Idea: Roms
Tutorial
Tutorial is loading...
Solution (awoo)
for _ in range(int(input())):
n = int(input())
a = input()
b = input()
c = input()
print("YES" if any([a[i] != c[i] and b[i] != c[i] for i in range(n)]) else "NO")
Idea: Roms
Tutorial
Tutorial is loading...
Solution (Roms)
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
cin >> t;
for (int tc = 0; tc < t; ++tc) {
int n;
cin >> n;
map<int, int> numOfLens;
for (int i = 0; i < n; ++i){
int x;
cin >> x;
++numOfLens[x];
}
long long res = 0;
int sum = 0;
for (auto it : numOfLens) {
long long cnt = it.second;
if(cnt >= 3)
res += cnt * (cnt - 1) * (cnt - 2) / 6;
if(cnt >= 2)
res += cnt * (cnt - 1) / 2 * sum;
sum += cnt;
}
cout << res << endl;
}
return 0;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Roms)
#include <bits/stdc++.h>
using namespace std;
const int N = 200'000;
const int INF = 1'000'000'009;
int t;
char type(const vector <int>& a, int id) {
int distL = (id == 0? INF : a[id] - a[id - 1]);
int distR = (id + 1 == a.size()? INF : a[id + 1] - a[id]);
if(distL < distR) return 'L';
if(distL > distR) return 'R';
assert(false);
}
int main() {
ios::sync_with_stdio(false);
cin >> t;
for (int tc = 0; tc < t; ++tc) {
int n;
cin >> n;
vector <int> a(n);
for (int i = 0; i < n; ++i)
cin >> a[i];
vector <int> l(n), r(n);
for (int i = 1; i < n; ++i)
r[i] = r[i - 1] + (type(a, i - 1) == 'R'? 1 : a[i] - a[i - 1]);
for (int i = n - 2; i >= 0; --i)
l[i] = l[i + 1] + (type(a, i + 1) == 'L'? 1 : a[i + 1] - a[i]);
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
--x, --y;
if (x < y)
cout << r[y] - r[x] << endl;
else
cout << l[y] - l[x] << endl;
}
}
return 0;
}
Idea: BledDest
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n + 2), d(n + 2, INT_MAX);
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 1; i <= n; ++i) cin >> d[i];
set<int> lft, cur;
for (int i = 0; i < n + 2; ++i) {
lft.insert(i);
cur.insert(i);
}
for (int z = 0; z < n; ++z) {
set<int> del, ncur;
for (int i : cur) {
auto it = lft.find(i);
if (it == lft.end()) continue;
int prv = *prev(it);
int nxt = *next(it);
if (a[prv] + a[nxt] > d[i]) {
del.insert(i);
ncur.insert(prv);
ncur.insert(nxt);
}
}
cout << del.size() << ' ';
for (auto it : del) lft.erase(it);
cur = ncur;
}
cout << '\n';
}
}
1922E - Increasing Subsequences
Idea: Roms
Tutorial
Tutorial is loading...
Solution (Neon)
#include <bits/stdc++.h>
using namespace std;
vector<int> f(long long x) {
vector<int> res;
if (x == 2) {
res.push_back(0);
} else if (x & 1) {
res = f(x - 1);
res.push_back(*min_element(res.begin(), res.end()) - 1);
} else {
res = f(x / 2);
res.push_back(*max_element(res.begin(), res.end()) + 1);
}
return res;
}
int main() {
int t;
cin >> t;
while (t--) {
long long x;
cin >> x;
auto ans = f(x);
cout << ans.size() << '\n';
for (int i : ans) cout << i << ' ';
cout << '\n';
}
}
Idea: Roms
Tutorial
Tutorial is loading...
Solution (awoo)
#include <bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); ++i)
const int N = 103;
int dp[N][N][N], dp2[N][N][N];
int main(){
int t;
cin >> t;
while (t--){
int n, x;
cin >> n >> x;
vector<int> a(n);
forn(i, n){
cin >> a[i];
--a[i];
}
forn(r, n) forn(l, r + 1) forn(i, x){
dp[l][r + 1][i] = dp2[l][r + 1][i] = 1e9;
}
forn(i, n) forn(j, x){
dp[i][i + 1][j] = a[i] != j;
dp2[i][i + 1][j] = a[i] == j;
}
for (int len = 2; len <= n; ++len){
forn(l, n - len + 1){
int r = l + len;
for (int m = l + 1; m < r; ++m){
forn(i, x)
dp2[l][r][i] = min(dp2[l][r][i], dp2[l][m][i] + dp2[m][r][i]);
forn(i, x)
dp[l][r][i] = min(dp[l][r][i], dp[l][m][i] + dp[m][r][i]);
}
forn(i, x){
dp[l][r][i] = min(dp[l][r][i], dp2[l][r][i] + 1);
}
forn(i, x) forn(j, x) if (i != j){
dp2[l][r][i] = min(dp2[l][r][i], dp[l][r][j]);
}
}
}
cout << *min_element(dp[0][n], dp[0][n] + x) << '\n';
}
}