QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#739025#9565. Birthday GiftcarboxylBaseWA 34ms3824kbC++232.9kb2024-11-12 20:36:392024-11-12 20:36:40

Judging History

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

  • [2024-11-12 20:36:40]
  • 评测
  • 测评结果:WA
  • 用时:34ms
  • 内存:3824kb
  • [2024-11-12 20:36:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int long long

string s;

void solve(){
    cin >> s;
    string t;
    for (int i = 0;i<s.length();i++){
        // cout << i <<endl;
        if (!t.length()){
            t.push_back(s[i]);
        }else{
            if (t[t.length()-1] == '2'){
                if (s[i] == '1'){
                    if (t.length() >= 2){
                        if (t[t.length()-2] == '1'){
                            t.pop_back();
                        }else{
                            t.push_back(s[i]);
                        }
                    }else{
                        t.push_back(s[i]);
                    }
                }else if (s[i] == '0'){
                    if (t.length() >= 2){
                        if (t[t.length()-2] == '0'){
                            t.pop_back();
                        }else{
                            t.push_back(s[i]);
                        }
                    }else{
                        t.push_back(s[i]);
                    }
                }else{
                    t.push_back(s[i]);
                }
            }else if (t[t.length()-1] == '1'){
                if (s[i] == '1'){
                    t.pop_back();
                }else{
                    t.push_back(s[i]);
                }
            }else{
                if (s[i] == '0'){
                    t.pop_back();
                }else{
                    t.push_back(s[i]);
                }
            }
        }
    }
    // cout << t << endl;
    if (t.length() == 0){
        cout << 0 <<endl;
        return;
    }
    int sum2 = 0;
    int cnt = 0;
    for (int i = 1;i<t.length()-1;i++){
        if (t[i] == '2'){
            cnt++;
        }else{
            if (cnt % 2 == 0){
            }else{
                sum2++;
            }
            cnt = 0;
        }
    }
    int ans = 0;
    s = "";
    for (int i = 0;i<t.length();i++){
        if (t[i] == '2'){
            if (s.length()>0){
                s.pop_back();
            }else{
                i++;
            }
        }else{
            if (s.length() == 0){
                s.push_back(t[i]);
            }else {
                if (s[s.length()-1] == t[i]){
                    s.pop_back();
                }else{
                    s.push_back(t[i]);
                }
            }
        }
    }
    // cout << s << endl;
    ans = s.length();
    sum2 *= 2;
    if (ans > sum2){
        ans -= sum2;
    }else{
        if (ans % 2 == sum2 % 2){
            ans = 0;
        }else{
            ans = 1;
        }
    }
    cout << ans << endl;
    return;
}

signed main(){
    // freopen("input.txt","r",stdin);
    // ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int _ = 1;
    cin >> _;
    while (_--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3728kb

input:

5
0110101
01020102
0000021111
1012121010
0100202010

output:

3
4
0
6
0

result:

ok 5 number(s): "3 4 0 6 0"

Test #2:

score: 0
Accepted
time: 15ms
memory: 3732kb

input:

50000
1010110101
1010101010
0101010101
0101010010
0101010010
1010101010
0101001010
1010010010
0100101010
1010101001
1010100101
0101010100
0100101011
0101101010
1011010110
1011010101
1010010101
1010010010
0101010101
0010101010
0101011010
0100101010
1010101010
1010010101
1010101101
1101010101
10100101...

output:

0
10
10
4
4
10
0
4
4
6
2
8
2
2
0
4
2
4
10
8
2
4
10
2
4
8
2
8
8
4
8
4
4
6
4
4
4
6
10
10
2
2
0
10
8
10
0
10
10
10
4
10
8
10
0
8
4
0
8
2
8
0
6
2
8
10
4
10
10
2
10
2
10
8
6
4
2
8
8
0
8
10
8
10
8
10
2
6
10
4
10
8
10
4
10
6
10
10
10
6
6
6
4
10
10
10
2
2
8
10
6
10
10
8
4
10
6
10
2
2
8
2
10
4
6
0
10
4
6
2
1...

result:

ok 50000 numbers

Test #3:

score: 0
Accepted
time: 5ms
memory: 3824kb

input:

5000
1010101010101010101110101010101010100101010101010101010110101010101010101010101010101010101010101010
0101010101010101010101010101101010101010101010101010101010101010101010101010100101010101010110101010
010101010101010101010101010101010101010101010101010101010101010101010100101010101010101010101...

output:

58
16
44
26
2
30
62
14
16
68
44
78
58
54
52
4
22
60
12
60
12
82
64
68
44
4
34
12
82
16
64
12
14
46
48
12
94
12
82
50
30
40
8
88
62
20
2
46
86
36
16
20
18
74
66
36
80
98
26
0
30
72
40
70
28
80
52
18
94
62
32
26
18
92
44
80
48
4
28
32
34
50
80
54
80
32
62
62
76
70
78
16
16
2
2
58
46
18
56
26
36
56
76
...

result:

ok 5000 numbers

Test #4:

score: 0
Accepted
time: 8ms
memory: 3792kb

input:

500
01010101010101010101010101010101010101010101010101010101010101010101001010101010101010101010110101010101010101010101010101010101010101010100101101010101010010101010101010101010101010101010101010101010101010101010101010101101010101010101010101010101010101010101010101010101001010101010101001010100...

output:

28
12
76
174
24
124
142
142
142
194
216
70
12
176
18
310
16
188
38
42
164
110
162
4
12
24
2
96
206
4
238
64
64
28
50
54
278
182
122
86
4
76
44
146
118
122
276
268
148
32
78
90
202
40
20
240
128
116
228
282
36
178
160
88
2
20
114
70
248
68
54
18
18
210
46
126
26
52
0
298
6
16
160
32
92
56
106
126
246...

result:

ok 500 numbers

Test #5:

score: 0
Accepted
time: 8ms
memory: 3620kb

input:

50
101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101...

output:

836
3994
352
3984
1826
568
2088
4076
1750
1258
532
3036
1718
1106
1002
478
1838
2030
422
4210
828
2088
2930
4044
1406
2388
3586
2018
1976
1026
5092
4154
3478
1018
1998
4014
718
2852
6070
2518
6380
4826
170
1876
1096
3914
1692
574
4612
802

result:

ok 50 numbers

Test #6:

score: 0
Accepted
time: 8ms
memory: 3624kb

input:

50
010101010101101110100100101010101100010100110100101001011010101000100101001010100101101010001011010110010101010101010101011011000010001001010101010110101010111010011010101010100101001010101010101100101010101010100101010101010100011101110101010011010101011010110100110101010010010101101101011001010...

output:

152
84
110
60
218
124
190
198
76
98
202
234
126
160
236
134
44
324
176
136
178
156
46
220
8
106
18
136
346
74
30
104
310
264
160
224
198
218
314
166
166
54
82
246
242
62
164
26
336
124

result:

ok 50 numbers

Test #7:

score: 0
Accepted
time: 6ms
memory: 3716kb

input:

2
0101010101010101010101010101010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

6648
174

result:

ok 2 number(s): "6648 174"

Test #8:

score: -100
Wrong Answer
time: 34ms
memory: 3528kb

input:

50000
0100202010
0101221101
0120120101
1210102101
1210101020
1020210101
0200101020
1010210120
0121012010
0212101010
0201010120
1101010221
0012101020
1110101221
1010121201
1202010101
0210012101
0210010102
2101210101
0101002201
0102101210
1020101201
1201002101
0101022010
0201101012
1210010210
20120101...

output:

0
4
0
0
6
2
4
0
0
4
4
4
4
2
0
4
2
2
6
4
0
0
2
0
2
0
4
2
0
4
2
0
2
4
0
0
6
6
4
0
2
4
4
2
0
4
6
6
0
2
4
0
4
4
4
0
0
4
4
0
6
4
6
0
0
4
4
4
6
2
0
0
2
0
6
6
4
0
6
0
0
0
6
2
0
4
2
6
2
0
6
6
2
0
6
0
0
6
4
6
2
2
0
2
0
4
0
6
4
2
6
4
6
4
0
4
4
0
4
2
0
0
0
0
0
0
2
2
4
4
0
4
0
4
4
0
2
4
4
4
0
2
4
2
4
2
0
4
4
2
...

result:

wrong answer 3rd numbers differ - expected: '2', found: '0'