Suddendly, all ideas of this contest are mine.
1324A - Yet Another Tetris Problem
Tutorial
Tutorial is loading...
Solution
for i in range(int(input())):
n = int(input())
cnto = sum(list(map(lambda x: int(x) % 2, input().split())))
print('YES' if cnto == 0 or cnto == n else 'NO')
1324B - Yet Another Palindrome Problem
Tutorial
Tutorial is loading...
Solution
for i in range(int(input())):
n = int(input())
s = list(map(int, input().split()))
ok = False
for i in range(n):
for j in range(i + 2, n):
if s[i] == s[j]: ok = True
print('YES' if ok else 'NO')
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
vector<int> pos;
pos.push_back(0);
for (int i = 0; i < int(s.size()); ++i) {
if (s[i] == 'R') pos.push_back(i + 1);
}
pos.push_back(s.size() + 1);
int ans = 0;
for (int i = 0; i < int(pos.size()) - 1; ++i) {
ans = max(ans, pos[i + 1] - pos[i]);
}
cout << ans << endl;
}
return 0;
}
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
vector<int> a(n), b(n);
for (auto &it : a) cin >> it;
for (auto &it : b) cin >> it;
vector<int> c(n);
for (int i = 0; i < n; ++i) {
c[i] = a[i] - b[i];
}
sort(c.begin(), c.end());
long long ans = 0;
for (int i = 0; i < n; ++i) {
if (c[i] <= 0) continue;
int pos = lower_bound(c.begin(), c.end(), -c[i] + 1) - c.begin();
ans += i - pos;
}
cout << ans << endl;
return 0;
}
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
bool in(int x, int l, int r) {
return l <= x && x <= r;
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n, h, l, r;
cin >> n >> h >> l >> r;
vector<int> a(n);
for (auto &it : a) cin >> it;
vector<vector<int>> dp(n + 1, vector<int>(n + 1, -1));
dp[0][0] = 0;
int sum = 0;
for (int i = 0; i < n; ++i) {
sum += a[i];
for (int j = 0; j <= n; ++j) {
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + in((sum - j) % h, l, r));
if (j < n) dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + in((sum - j - 1) % h, l, r));
}
}
cout << *max_element(dp[n].begin(), dp[n].end()) << endl;
return 0;
}
Tutorial
Tutorial is loading...
Solution
#include <bits/stdc++.h>
using namespace std;
vector<int> a;
vector<int> dp;
vector<int> ans;
vector<vector<int>> g;
void dfs(int v, int p = -1) {
dp[v] = a[v];
for (auto to : g[v]) {
if (to == p) continue;
dfs(to, v);
dp[v] += max(dp[to], 0);
}
}
void dfs2(int v, int p = -1) {
ans[v] = dp[v];
for (auto to : g[v]) {
if (to == p) continue;
dp[v] -= max(0, dp[to]);
dp[to] += max(0, dp[v]);
dfs2(to, v);
dp[to] -= max(0, dp[v]);
dp[v] += max(0, dp[to]);
}
}
int main() {
#ifdef _DEBUG
freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif
int n;
cin >> n;
a = dp = ans = vector<int>(n);
g = vector<vector<int>>(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
if (a[i] == 0) a[i] = -1;
}
for (int i = 0; i < n - 1; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
g[x].push_back(y);
g[y].push_back(x);
}
dfs(0);
dfs2(0);
for (auto it : ans) cout << it << " ";
cout << endl;
return 0;
}