Educational Codeforces Round 103 (Rated for Div. 2)
Educational Codeforces Round 103 (Rated for Div. 2)
A - K-divisible Sum
int main() {
IOS;
for (cin >> _; _; --_) {
ll n, k; cin >> n >> k; k = ((n - 1) / k + 1) * k;
cout << (k - 1) / n + 1 << '\n';
}
return 0;
}
B - Inflation
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n >> k; VL a(n + 1), b(n + 1);
rep (i, 1, n) cin >> a[i], b[i] = a[i] + b[i - 1];
ll ans = 0, cur = 0;
per (i, n, 2) {
if (a[i] * 100 <= k * b[i - 1]) continue;
ll res = (a[i] * 100 - k * b[i - 1] - 1) / k + 1;
umax(ans, res);
}
cout << ans << '\n';
}
return 0;
}
C - Longest Simple Cycle
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n; VL c(n + 1), a(n + 1), b(n + 1);
rep (i, 1, n) cin >> c[i], --c[i];
rep (i, 1, n) cin >> a[i];
rep (i, 1, n) cin >> b[i];
ll ans = 0, cur = abs(a[2] - b[2]) << 1;
for (int i = 2; i <= n; ++i) {
if (a[i] == b[i]) umax(ans, cur = 2 + c[i]);
else umax(ans, cur = max(2 - abs(a[i] - b[i]) + c[i] + cur, 2 + abs(a[i] - b[i]) + c[i]));
}
cout << ans << '\n';
}
return 0;
}
D - Journey
char s[N];
int f[N], ans[N];
int find(int x) { return x == f[x] ? x : f[x] = find(f[x]); }
void unit(int x, int y) {
x = find(x), y = find(y);
if (x == y) return; f[y] = x;
}
int main() {
IOS;
for (cin >> _; _; --_) {
cin >> n; cin >> s + 1;
rep (i, 0, n) f[i] = i, ans[i] = 0;
for (int i = 0, j = 0; i <= n;) {
++ans[j];
if (s[i] == 'L') ++ans[j];
if (i < n && s[i + 1] == 'L') { j = ++i; continue; }
if (i == n) break;
if (i + 1 < n && s[i + 2] == 'R') { ++ans[j]; j = ++i; }
else if (i + 1 < n) unit(j, i + 2), ans[i + 1] = 1, i += 2;
else ++ans[j], ans[i + 1] = 1, i += 2;
}
rep (i, 0, n) cout << ans[find(i)] << ' '; cout << '\n';
}
return 0;
}
E -Pattern Matching
找到能匹配的, 拓扑就行, 没调出来