Skip to content

Commit 830fedf

Browse files
committedNov 23, 2021
Weekly Contest 266
1 parent b47cea1 commit 830fedf

4 files changed

+83
-0
lines changed
 

‎count-vowel-substrings-of-a-string.cc

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Count Vowel Substrings of a String
2+
#define FOR(i, a, b) for (long i = (a); i < (b); i++)
3+
#define REP(i, n) for (long i = 0; i < (n); i++)
4+
5+
class Solution {
6+
public:
7+
int countVowelSubstrings(string a) {
8+
int n = a.size(), ans = 0;
9+
REP(i, n) {
10+
int c = 0;
11+
FOR(j, i, n) {
12+
if (a[j]=='a') c|=1;
13+
else if (a[j]=='e') c|=2;
14+
else if (a[j]=='i') c|=4;
15+
else if (a[j]=='o') c|=8;
16+
else if (a[j]=='u') c|=16;
17+
else break;
18+
if (c==31) ans++;
19+
}
20+
}
21+
return ans;
22+
}
23+
};

‎maximum-path-quality-of-a-graph.cc

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Maximum Path Quality of a Graph
2+
using pii = pair<int, int>;
3+
4+
class Solution {
5+
vector<vector<pii>> es;
6+
vector<int> values, cnt;
7+
int ans = 0;
8+
public:
9+
void dfs(int tim, int u, int val) {
10+
if (!cnt[u]++)
11+
val += values[u];
12+
if (u == 0)
13+
ans = max(ans, val);
14+
for (auto [v, w]: es[u])
15+
if (tim >= w)
16+
dfs(tim-w, v, val);
17+
if (!--cnt[u])
18+
val -= values[u];
19+
}
20+
int maximalPathQuality(vector<int>& values, vector<vector<int>>& edges, int maxTime) {
21+
int n = values.size();
22+
this->values = move(values);
23+
es.resize(n);
24+
cnt.resize(n);
25+
for (auto &e: edges) {
26+
es[e[0]].emplace_back(e[1], e[2]);
27+
es[e[1]].emplace_back(e[0], e[2]);
28+
}
29+
dfs(maxTime, 0, 0);
30+
return ans;
31+
}
32+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Minimized Maximum of Products Distributed to Any Store
2+
#define ALL(x) (x).begin(), (x).end()
3+
4+
class Solution {
5+
public:
6+
int minimizedMaximum(int n, vector<int>& a) {
7+
long l = 1, h = *max_element(ALL(a));
8+
while (l < h) {
9+
long m = l+h >> 1, c = 0;
10+
for (long x: a)
11+
c += (x+m-1)/m;
12+
if (c > n) l = m+1;
13+
else h = m;
14+
}
15+
return l;
16+
}
17+
};

‎vowels-of-all-substrings.cc

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Vowels of All Substrings
2+
class Solution {
3+
public:
4+
long long countVowels(string a) {
5+
long n = a.size(), ans = 0;
6+
for (long i = 0; i < n; i++)
7+
if (strchr("aeiou", a[i]))
8+
ans += (i+1)*(n-i);
9+
return ans;
10+
}
11+
};

0 commit comments

Comments
 (0)
Please sign in to comment.