QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#732621#9565. Birthday GiftLzy_#WA 6ms3900kbC++142.3kb2024-11-10 15:21:062024-11-10 15:21:07

Judging History

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

  • [2024-11-10 15:21:07]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:3900kb
  • [2024-11-10 15:21:06]
  • 提交

answer

#include <bits/stdc++.h>

void solve() {
	std::string s;
	std::cin >> s;
	
	int l1 = -1, r1 = -1;
	int l2 = -1, r2 = -1;
	if (s[0] == '0') {
		l2 = r2 = 1;
	} else {
		if (s[0] == '1') {
			l1 = r1 = 1;
		} else {
			l1 = r1 = l2 = r2 = 1;
		}
	}
	for (int i = 1; i < s.size(); ++ i) {
		int tl1 = l1, tr1 = r1, tl2 = l2, tr2 = r2;
		if (s[i] == '0') {
			if (tl1 != -1) {
				l2 = tl1 + 1;
			} else {
				l2 = -1;
			}
			if (tr1 != -1) {
				r2 = tr1 + 1;
			} else {
				r2 = -1;
			}
			if (tl2 > 0) {
				l1 = tl2 - 1;
			} else {
				l1 = -1;
			}
			if (tr2 > 0) {
				r1 = tr2 - 1;
			} else {
				r1 = -1;
			}
			if (l1 == 0) {
				l2 = 0;
			}
			if (r1 == 0 && r2 == -1) {
				r2 = 0;
			}
		} else {
			if (s[i] == '1') {
				if (tl2 != -1) {
					l1 = tl2 + 1;
				} else {
					l1 = -1;
				}
				if (tr2 != -1) {
					r1 = tr2 + 1;
				} else {
					r1 = -1;
				}
				if (tl1 > 0) {
					l2 = tl1 - 1;
				} else {
					l2 = -1;
				}
				if (tr1 > 0) {
					r2 = tr1 - 1;
				} else {
					r2 = -1;
				}
				if (l2 == 0) {
					l1 = 0;
				}
				if (r2 == 0 && r1 == -1) {
					r1 = 0;
				}
			} else {
				if (tl1 > 0) {
					l2 = tl1 - 1;
				} else {
					if (tl1 == 0) {
						l2 = 1;
					} else {
						l2 = -1;
					}
				}
				if (tl2 > 0) {
					l1 = tl2 - 1;
				} else {
					if (tl2 == 0) {
						l1 = 1;
					} else {
						l1 = -1;
					}
				}
				if (tr1 != -1) {
					r2 = tr1 + 1;
				} else {
					r2 = -1;
				}
				if (tr2 != -1) {
					r1 = tr2 + 1;
				} else {
					r1 = -1;
				}
				if (l1 == 0 || l2 == 0) {
					l1 = l2 = 0;
				}
				if (r1 == 0 || r2 == 0) {
					if (r1 == -1) {
						r1 = 0;
					} 
					if (r2 == -1) {
						r2 = 0;
					}
				}
			}
		}
		//std::cout << l1 << " " << r1 << " " << l2 << " " << r2 << '\n';
	}
	
	int ans = 1 << 30;
	if (l1 != -1) {
		ans = std::min(ans, l1);
	}
	if (l2 != -1) {
		ans = std::min(ans, l2);
	}
	if (r1 != -1) {
		ans = std::min(ans, r1);
	}
	if (r2 != -1) {
		ans = std::min(ans, r2);
	}
	std::cout << ans << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0); std::cout.tie(0);

    int T;
    std::cin >> T;

    while (T --) {
    	solve();
    }

    return 0;
}

詳細信息

Test #1:

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

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: 5ms
memory: 3588kb

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

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: 0ms
memory: 3596kb

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: 1ms
memory: 3804kb

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

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: 1ms
memory: 3900kb

input:

2
0101010101010101010101010101010010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010...

output:

6648
174

result:

ok 2 number(s): "6648 174"

Test #8:

score: -100
Wrong Answer
time: 6ms
memory: 3772kb

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
4
0
6
0
4
0
0
4
4
4
4
2
2
4
2
2
6
4
0
2
4
0
2
2
2
2
2
6
2
0
0
4
4
4
6
6
4
0
2
4
4
2
0
4
6
8
0
2
4
0
4
4
4
2
0
4
2
2
6
6
6
2
0
4
6
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
6
6
2
0
4
2
0
4
2
6
6
4
6
6
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
6
6
4
0
0
4
4
2
0
2
2
4
2
...

result:

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