QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#499988 | #8731. Segregacija | arbuzick# | 0 | 636ms | 3612kb | C++20 | 2.1kb | 2024-07-31 20:49:34 | 2024-07-31 20:49:35 |
Judging History
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
Wrong Answer
Test #1:
score: 7
Accepted
time: 586ms
memory: 3552kb
input:
10 1000000 PPPPPPPPPP PPPPPPPPPP 2 1 7 1 1 3 2 1 4 2 1 10 2 1 3 1 2 3 2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3 3 4 4 4 4 4 4 4 4 4 4 3 3 3 4 4 4 3 3 3 3 3 4 4 4 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 3 3 3 3 3 3 3 3 3 4 4 4 ...
result:
wrong answer 22nd lines differ - expected: '4', found: '3'
Subtask #2:
score: 0
Time Limit Exceeded
Test #16:
score: 11
Accepted
time: 132ms
memory: 3596kb
input:
5 1000000 CCCCC CCCCC 1 2 4 2 1 1 1 1 2 2 1 1 2 1 1 1 2 4 2 1 3 2 1 3 1 2 4 2 1 4 2 1 3 2 1 4 1 1 1 1 2 2 2 1 5 1 2 1 2 1 4 1 2 3 1 2 1 2 1 2 2 1 5 2 1 4 2 1 4 2 1 3 2 1 2 1 1 2 2 1 5 2 1 3 1 1 2 1 1 2 2 1 2 2 1 4 1 1 4 2 1 2 2 1 3 2 1 4 1 2 3 1 1 1 1 1 4 2 1 4 1 1 1 1 1 3 1 1 3 2 1 5 1 2 2 2 1 5 2 ...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 1000001 lines
Test #17:
score: 0
Time Limit Exceeded
input:
200 1000000 PPPPPPPPPPPPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPPPPPPPPPPCPPCPPPPPCPPPPPPPPPPPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPCPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 845 845 845 845 845 845 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 846 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 847 ...
result:
Subtask #3:
score: 0
Wrong Answer
Test #37:
score: 0
Wrong Answer
time: 265ms
memory: 3608kb
input:
500 500 CPPPCCCCCCPCCCPPPCPCCPCCPPCPCPCCCPPPPPCCCPCPCPCCCPCPPCPPCCCPPPPPPCCCPPPCCCPPCPPCCCPPPCCPCCCCCPCPCCPCPPPCCCCPPCPCPCCCPPCPCPCCPPPPCPPPCCCCPCPPPCCPPPPCPCPCPPPPCCCCPCPPPPPPPCCPCCPCPCCPPPPCPCPCPPCPCCPPCPPCPPCCPCCPCPCCCCCCPCCCCCCCCPPPPCCCPCCPPCCPPCCCPPPPPCPCPPPCPPCPCCPPPPPCCCCCPCPPPCCCCPPCCPPCCPCC...
output:
3870 3871 3871 3871 3872 3871 3872 3872 3872 3871 3871 3871 3871 3872 3872 3871 3872 3872 3872 3871 3871 3871 3872 3871 3872 3872 3873 3874 3874 3875 3874 3873 3873 3872 3871 3870 3869 3869 3868 3868 3868 3869 3869 3869 3869 3869 3868 3867 3866 3866 3866 3865 3865 3866 3867 3866 3866 3865 3865 3864 ...
result:
wrong answer 34th lines differ - expected: '3874', found: '3872'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Time Limit Exceeded
Test #89:
score: 0
Time Limit Exceeded
input:
100000 100 PCPCCPPCCPPCPPPPCPPPPPCPPPCCCPCCPCCCPCPCPPPPPPPPPPPPCPPPCCPCCPCCCPPCPCCPPPCPCCCPCCCPPCPCPPPCPCPPCCPPCPPCPPCPPCPPPPCCCCCCPCCCCPCCCPPPCCPCPPCCCCPPPPPCPPPPPPCCPCCCCPPPCPPPCPPPCCPCCCCPCPCPCPPCPPCPCPCCCCCCCPCCCPCPCCPCCCCCPPPCPCPCCPCPCCPCPCCPPCCPCPCCPCCCPCCCPPCCCCPCCCCCPPCPCPCCCPPCCCPCPCCPCCCCP...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #115:
score: 0
Time Limit Exceeded
input:
1000000 1000000 PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP...
output:
result:
Subtask #7:
score: 0
Skipped
Dependency #1:
0%