QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499798#8730. Particijaarbuzick#0 0ms3616kbC++201.9kb2024-07-31 19:19:292024-07-31 19:19:35

Judging History

你现在查看的是最新测评结果

  • [2024-07-31 19:19:35]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:3616kb
  • [2024-07-31 19:19:29]
  • 提交

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 >= cnt - cnt_upper; --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;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3488kb

input:

751 0
5
5 5 5 5 5
1 2 3 4 5
6
1 2 2 6 4 5
3 6 3 4 3 3
8
5 8 6 5 4 3 6 6
3 4 4 3 2 6 6 2
5
1 1 1 1 1
5 5 4 3 3
8
5 7 3 7 8 2 7 5
4 2 6 3 6 2 5 6
8
5 8 7 3 4 6 5 2
3 3 3 3 3 3 1 3
6
2 1 3 1 3 6
5 5 3 6 3 5
8
8 6 2 4 7 7 4 1
7 7 3 3 7 7 3 3
5
2 1 4 4 2
1 2 1 4 1
6
2 2 2 2 2 2
5 3 2 1 4 6
7
4 1 7 4 2 3 ...

output:

9

result:

wrong answer 1st numbers differ - expected: '1', found: '9'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #14:

score: 0
Wrong Answer
time: 0ms
memory: 3616kb

input:

719 1
8
1 1 2 1 5 1 5 1
2 5 6 1 4 4 8 7
5
5 5 5 5 5
1 4 1 2 5
8
5 2 4 7 8 6 1 3
4 4 4 4 4 4 4 4
7
4 5 5 4 4 5 5
1 7 5 3 6 2 4
5
1 4 4 5 2
1 4 2 1 3
2
1 2
2 1
8
6 8 6 2 8 4 5 6
3 4 7 4 8 8 8 4
8
2 7 2 7 2 2 2 2
3 4 1 3 8 5 7 4
8
3 3 2 8 5 6 4 4
4 7 7 4 7 7 8 7
5
2 4 4 4 4
5 2 3 1 4
6
1 1 1 1 1 1
6 5 ...

output:

5030
5030

result:

wrong answer 1st numbers differ - expected: '2', found: '5030'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Runtime Error

Test #40:

score: 0
Runtime Error

input:

704 2
6
5 3 1 4 4 4
4 5 6 4 5 2
7
1 4 1 4 1 1 1
7 1 4 1 6 7 5
7
5 6 6 5 5 6 6
3 4 6 1 7 3 5
8
8 2 7 4 6 1 3 4
6 6 6 6 6 6 6 6
8
1 3 1 2 8 7 4 1
8 8 8 8 5 1 8 8
8
1 6 2 6 7 3 5 8
7 7 5 8 5 7 5 5
6
6 4 5 3 6 1
3 3 3 3 4 3
7
3 3 7 3 3 3 3
1 4 5 3 6 5 7
5
3 1 5 5 1
5 4 3 5 3
6
4 1 4 2 2 2
6 2 2 1 5 2
6
...

output:


result:


Subtask #6:

score: 0
Skipped

Dependency #5:

0%