QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#499985#8731. Segregacijaarbuzick#0 416ms3616kbC++202.1kb2024-07-31 20:45:542024-07-31 20:45:55

Judging History

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

  • [2024-07-31 20:45:55]
  • 评测
  • 测评结果:0
  • 用时:416ms
  • 内存:3616kb
  • [2024-07-31 20:45:54]
  • 提交

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: 369ms
memory: 3484kb

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: 416ms
memory: 3548kb

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

result:

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

Subtask #2:

score: 0
Time Limit Exceeded

Test #16:

score: 11
Accepted
time: 132ms
memory: 3616kb

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:

854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
853
853
853
853
853
853
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
854
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
855
...

result:


Subtask #3:

score: 0
Wrong Answer

Test #37:

score: 17
Accepted
time: 133ms
memory: 3616kb

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: 255ms
memory: 3604kb

input:

500 500
PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPPPPPPPPCPPPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPCPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCPPCPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPCCPPPPPPCPPPPPPPPPPPPPPCPPPPPPPPPPPPPPPPPPPPPPPPPCPPPCPPPPPPPPCPPPPPPPPCPPPPCPPPPPPPP...

output:

11721
11721
11722
11722
11723
11723
11723
11723
11723
11724
11724
11724
11724
11724
11724
11723
11723
11723
11723
11723
11723
11723
11722
11723
11723
11723
11723
11723
11723
11723
11723
11723
11723
11724
11724
11723
11723
11723
11723
11723
11723
11723
11723
11723
11722
11722
11722
11722
11722
11722
...

result:

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

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%