QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#792760#9565. Birthday GiftkircoWA 9ms3884kbC++23903b2024-11-29 13:53:132024-11-29 13:53:14

Judging History

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

  • [2024-11-29 13:53:14]
  • 评测
  • 测评结果:WA
  • 用时:9ms
  • 内存:3884kb
  • [2024-11-29 13:53:13]
  • 提交

answer

#include<bits/stdc++.h>
#define iosy ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
#define int long long
using namespace std;
const int N = 2e5+10;

void solve(){
	string s;cin>>s;
	int n=s.size();
	deque<char> q;
	int ans=n;
	for(int i=0;i<n;i++){
		if(q.empty()){
			q.push_back(s[i]);
		}else{
			char c=q.back();q.pop_back();
			if(c!='2'&&s[i]!='2'&&c!=s[i]){
				q.push_back(c);
				q.push_back(s[i]);
			}
		}
	}
	ans=min(ans,(int)q.size());

	reverse(s.begin(),s.end());
	while(!q.empty())q.pop_back();
	
	for(int i=0;i<n;i++){
		if(q.empty()){
			q.push_back(s[i]);
		}else{
			char c=q.back();q.pop_back();
			if(c!='2'&&s[i]!='2'&&c!=s[i]){
				q.push_back(c);
				q.push_back(s[i]);
			}
		}
	}
	ans=min(ans,(int)q.size());
	cout<<ans<<"\n";
}

signed main(){ 
	iosy;int _=1;
	cin>>_;
	while(_--){solve();}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3852kb

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: 9ms
memory: 3824kb

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: 3ms
memory: 3644kb

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: 3ms
memory: 3884kb

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: 3ms
memory: 3880kb

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: 4ms
memory: 3532kb

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: 2ms
memory: 3760kb

input:

2
0101010101010101010101010101010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

6648
174

result:

ok 2 number(s): "6648 174"

Test #8:

score: -100
Wrong Answer
time: 9ms
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
2
0
6
0
2
0
0
4
4
4
4
2
2
4
2
2
6
4
0
2
2
0
0
0
2
2
2
4
2
0
0
4
2
4
6
6
4
0
2
4
2
2
0
4
6
6
0
2
4
0
4
4
4
2
0
4
2
2
6
4
6
0
0
4
4
0
6
4
0
0
2
0
6
6
4
2
6
0
0
2
6
2
2
4
2
6
2
0
6
6
2
0
6
2
0
6
4
6
2
0
4
2
0
4
0
6
4
2
6
4
6
2
0
2
4
0
0
0
0
0
2
0
0
0
2
2
4
4
0
4
0
4
4
0
2
4
4
4
0
0
4
2
2
0
2
2
4
2
...

result:

wrong answer 29th numbers differ - expected: '0', found: '2'