QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499799#8731. Segregacijaarbuzick#0 348ms3788kbC++201.9kb2024-07-31 19:19:412024-07-31 19:19:42

Judging History

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

  • [2024-07-31 19:19:42]
  • 评测
  • 测评结果:0
  • 用时:348ms
  • 内存:3788kb
  • [2024-07-31 19:19:41]
  • 提交

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: 7
Accepted
time: 348ms
memory: 3536kb

input:

10 1000000
PPPPPPPPPP
PPPPPPPPPP
2 1 7
1 1 3
2 1 4
2 1 10
2 1 3
1 2 3
2 1 10
2 1 5
2 1 4
2 1 2
2 1 9
2 1 2
1 1 6
2 1 9
2 1 2
2 1 7
2 1 5
1 1 8
1 2 8
2 1 9
2 1 10
1 1 7
2 1 7
2 1 9
2 1 8
1 1 1
2 1 5
2 1 2
2 1 4
2 1 10
1 2 5
1 2 1
2 1 2
1 2 6
2 1 7
1 2 2
2 1 1
1 1 5
1 2 4
2 1 10
1 1 6
2 1 1
1 1 8
1 1 ...

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 #2:

score: 0
Wrong Answer
time: 337ms
memory: 3788kb

input:

10 1000000
PPPPPPPPPP
PPPPPPCPCC
1 1 1
1 2 5
1 1 6
2 1 7
2 1 4
2 1 6
1 2 8
1 1 4
1 2 4
1 2 6
2 1 7
1 2 1
1 2 1
2 1 3
2 1 5
1 1 1
2 1 7
2 1 2
1 2 5
1 2 2
2 1 8
2 1 3
2 1 10
1 2 3
2 1 3
2 1 2
1 1 7
1 1 1
2 1 7
1 2 8
1 2 4
2 1 5
1 2 5
2 1 10
1 1 7
2 1 5
2 1 7
1 1 1
1 1 1
2 1 4
1 1 3
1 1 9
2 1 7
2 1 1
2...

output:

1
1
1
1
2
2
2
3
3
3
3
2
2
2
2
2
2
3
3
3
3
4
4
5
5
5
5
5
5
4
4
4
4
4
3
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
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
7
7
7
7
7
7
7
7
7
7
7
7
6
7
7
6
6
6
6
6
6
6
5
5
5
5
5
5
5
5
5
5
5
6
6
7
7
8
8
8
8
8
8
8
8
8
7
6
6
...

result:

wrong answer 56th lines differ - expected: '5', found: '4'

Subtask #2:

score: 0
Time Limit Exceeded

Test #16:

score: 11
Accepted
time: 127ms
memory: 3540kb

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:

863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
862
862
862
862
862
862
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
863
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
864
...

result:


Subtask #3:

score: 0
Wrong Answer

Test #37:

score: 17
Accepted
time: 131ms
memory: 3620kb

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
3874
3875
3874
3873
3873
3874
3874
3874
3873
3873
3873
3873
3873
3872
3871
3870
3870
3870
3871
3871
3872
3873
3872
3872
3871
3871
3872
...

result:

ok 501 lines

Test #38:

score: 0
Wrong Answer
time: 250ms
memory: 3600kb

input:

500 500
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPPPPPPPPCPPPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPCPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPCPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCPPPPPPCPPPPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPCPPPCPPPPPPPPCPPPPPPPPCPPPPCPPPPPPPP...

output:

11763
11763
11764
11764
11765
11765
11765
11765
11765
11766
11766
11766
11766
11766
11766
11765
11765
11765
11765
11765
11765
11765
11764
11765
11765
11765
11765
11765
11765
11765
11765
11765
11765
11766
11766
11765
11765
11765
11765
11765
11765
11765
11765
11765
11764
11764
11764
11764
11764
11764
...

result:

wrong answer 1st lines differ - expected: '13126', found: '11763'

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%