QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499987 | #8732. Zečevi | arbuzick# | 0 | 0ms | 0kb | C++20 | 2.1kb | 2024-07-31 20:49:12 | 2024-07-31 20:49:12 |
answer
#include <bits/stdc++.h>
using namespace std;
constexpr long long inf = (long long)1e18 + 7;
void solve() {
int n, q;
cin >> n >> q;
array<string, 2> s;
cin >> s[0] >> s[1];
auto get_ans = [&]() -> long long {
int cnt = 0;
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < n; ++j) {
if (s[i][j] == 'P') {
cnt++;
}
}
}
long long ans_total = inf;
for (int cnt_upper = cnt; cnt_upper >= 0; --cnt_upper) {
int cnt_lower = cnt - cnt_upper;
// if (cnt_upper + 1 < cnt_lower) {
// continue;
// }
long long ans = 0;
int diff1 = 0, diff2 = 0;
for (int i = 0; i < n; ++i) {
if (s[0][i] == 'P') {
diff1++;
}
if (s[1][i] == 'P') {
diff2++;
}
if (i < cnt_upper) {
diff1--;
}
if (i < cnt_lower) {
diff2--;
}
if (diff1 * 1LL * diff2 < 0) {
ans++;
if (diff1 > 0) {
diff1--;
diff2++;
} else {
diff1++;
diff2--;
}
}
ans += abs(diff1) + abs(diff2);
}
ans_total = min(ans_total, ans);
}
return ans_total;
};
cout << get_ans() << '\n';
while (q--) {
int t, x, y;
cin >> t >> x >> y;
x--, y--;
if (t == 1) {
swap(s[x][y], s[x][y + 1]);
} else {
swap(s[x][y], s[x + 1][y]);
}
cout << get_ans() << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 0
Runtime Error
input:
1 100000 25117044 970963458 373893849 968275175 426927003 756404237 402749243 884153855 655982073 231540010 925839527 380078009 580079136 593952762 505135862 82095067 52931312 190936477 921699044 178656266 22689680 495676031 439196655 96470058 508403382 453576184 728333782 206229498 227588452 887461...
output:
result:
Subtask #2:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
100000 1 866301171 366511673 782130035 523593023 210159324 951803750 33819604 974027339 517904111 963671594 281974787 391051697 568097534 965085338 81004963 640086904 211218893 397278600 614725688 4366212 269152510 559992280 327491679 276555612 630131521 503842459 15556017 382637565 444080049 985512...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #26:
score: 0
Runtime Error
input:
1000 1000 98203901 1327928 90291962 1715530 73190581 1953419 30626944 1111081 19861765 1648083 378531325 1847131 32338803 1135925 213019894 1754207 104073495 1236818 153162191 1775836 283503659 1577207 370480039 1457117 11989599 1688477 8779089 1115475 25334382 1551917 102065341 1825040 154967698 15...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%