QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#499802 | #8731. Segregacija | arbuzick# | 0 | 550ms | 3812kb | C++20 | 1.9kb | 2024-07-31 19:20:53 | 2024-07-31 19:20:54 |
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;
int cnt_pr = 0, cnt_pr_ans = 0;
long long ans = 0;
for (int i = 0; i < n; ++i) {
if (s[0][i] == 'P') {
cnt_pr++;
}
if (s[1][i] == 'P') {
cnt_pr++;
}
if (i < cnt_upper) {
cnt_pr_ans++;
}
if (i < cnt_lower) {
cnt_pr_ans++;
}
ans += abs(cnt_pr - cnt_pr_ans);
}
int cnt_up = 0;
for (int i = 0; i < n; ++i) {
if (s[0][i] == 'P') {
cnt_up++;
}
}
ans += abs(cnt_up - cnt_upper);
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;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 7
Accepted
time: 550ms
memory: 3600kb
input:
10 1000000 PPPPPPPPPP PPPPPPPPPP 2 1 7 1 1 3 2 1 4 2 1 10 2 1 3 1 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 4 4 4 4 5 5 5 5 5 5 5 5 5 6 5 5 5 6 6 6 5 5 5 5 5 6 6 6 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 5 5 5 5 5 5 5 5 5 6 6 6 ...
result:
wrong answer 22nd lines differ - expected: '4', found: '3'
Subtask #2:
score: 0
Time Limit Exceeded
Test #16:
score: 11
Accepted
time: 130ms
memory: 3532kb
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:
855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 854 854 854 854 854 854 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 855 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 856 ...
result:
Subtask #3:
score: 0
Wrong Answer
Test #37:
score: 0
Wrong Answer
time: 260ms
memory: 3812kb
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%