QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#221092#6841. Occupy the CitiesrealIyxiang#AC ✓11ms16592kbC++141.7kb2023-10-21 08:52:582023-10-21 08:52:58

Judging History

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

  • [2023-10-21 08:52:58]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:16592kb
  • [2023-10-21 08:52:58]
  • 提交

answer

#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define lin read<ll>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using vec = vector < int >;
using veg = vector < pii >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

template < typename T > void chkmax(T &x, const T &y) { x = x > y ? x : y; }
template < typename T > void chkmin(T &x, const T &y) { x = x < y ? x : y; }

const int N = 1e6 + 10;

int n;
char s[N];
int a[N], tot, f[N][2];

void solve() {
	n = in, tot = 0; scanf("%s", s + 1);
	int cur = 0;
	rep(i, 1, n) {
		if(s[i] == '0') cur++;
		else a[++tot] = cur, cur = 0;
	} a[++tot] = cur;
	//rep(i, 1, tot) cerr << a[i] << " "; cerr << endl;
	f[0][0] = f[0][1] = 0;
	rep(i, 1, tot) {
		f[i][0] = f[i][1] = 1e9;
		rep(j, 0, 1) rep(k, 0, 1) {
			int ret = 0;
			if(j == 0 && k == 1) ret = (a[i] + 1) / 2 + 1;
			if(j == 1 || k == 0) ret = a[i] / 2  + 1;
			if(j == 1 && k == 0) ret = (a[i] + 1) / 2;
			if(i == 1) {
				if(k == 0) ret = a[i];
				else ret = a[i] + 1;
			}
			if(i == tot) {
				if(j == 1) ret = a[i];
				else ret = a[i] + 1;
			}
			if(a[i] == 0) ret = 0;
			chkmin(f[i][k], max(f[i - 1][j], ret));
		}
	}
	printf("%d\n", min(f[tot][0], f[tot][1]));
}

int main() {
#ifdef YJR_2333_TEST
	freopen("1.in", "r", stdin);
#endif
	int T = in;
	while(T--) {
		solve();
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
3
010
4
0100
7
0001000
5
11111
6
010101

output:

2
2
4
0
1

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 8044kb

input:

2036
1
1
2
01
2
10
2
11
3
001
3
010
3
011
3
100
3
101
3
110
3
111
4
0001
4
0010
4
0011
4
0100
4
0101
4
0110
4
0111
4
1000
4
1001
4
1010
4
1011
4
1100
4
1101
4
1110
4
1111
5
00001
5
00010
5
00011
5
00100
5
00101
5
00110
5
00111
5
01000
5
01001
5
01010
5
01011
5
01100
5
01101
5
01110
5
01111
5
10000
5...

output:

0
1
1
0
2
2
1
2
1
1
0
3
2
2
2
1
1
1
3
1
1
1
2
1
1
0
4
3
3
3
2
2
2
3
2
2
1
2
1
1
1
4
2
2
1
2
1
1
1
3
1
1
1
2
1
1
0
5
4
4
3
3
3
3
3
2
2
2
2
2
2
2
4
2
2
2
2
1
1
1
3
1
1
1
2
1
1
1
5
2
2
2
2
1
1
1
3
1
1
1
2
1
1
1
4
2
2
1
2
1
1
1
3
1
1
1
2
1
1
0
6
5
5
4
4
4
4
4
3
3
3
3
3
3
3
4
2
2
2
2
2
2
2
3
2
2
2
2
2
2
...

result:

ok 2036 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 7924kb

input:

1000
100
1011100101100000101100001011101111011001011101100011010110100101110011010111011101100111100010010101
100
0001001110011011010011111011001110001011010001111110111001100000001111000110101001000101000011000110
100
011011010100100100011000110111011111100100101100010000011101011110001000010011011...

output:

3
4
3
4
4
3
4
5
4
3
3
3
3
2
5
3
3
3
3
3
2
4
3
3
3
3
4
3
2
3
6
5
3
3
3
5
2
3
2
3
2
3
5
4
3
3
3
5
3
3
3
2
3
5
3
2
2
3
4
3
3
4
4
3
5
3
5
4
4
2
5
3
3
4
3
3
3
3
3
3
4
3
4
3
3
6
4
4
9
3
3
2
5
2
4
4
2
4
3
3
4
3
2
5
3
5
3
4
3
2
3
2
3
3
4
3
3
4
3
2
3
3
4
3
3
4
4
3
3
4
3
4
3
3
4
5
3
3
3
4
6
4
3
4
3
3
3
4
4
4
...

result:

ok 1000 lines

Test #4:

score: 0
Accepted
time: 2ms
memory: 8048kb

input:

100
1000
101001000101110101101100110011101110001111000111000101100011110111111000000110110110000101100110010000010100011110011101111000110101010001101010101101111101111101010001101100011110000000000010011000000010010101001001100001010011011101110111100010000110001110011010000110000001101011000100010...

output:

6
5
4
5
4
5
4
5
5
5
4
5
6
5
4
4
5
5
4
5
5
6
5
5
4
5
5
7
4
7
5
5
8
6
4
4
5
3
5
5
4
4
5
7
6
5
7
6
4
7
5
5
5
4
4
5
4
4
5
4
6
4
5
4
5
4
6
6
6
4
10
5
5
5
4
4
6
5
5
7
6
4
5
5
6
6
6
7
4
4
4
5
6
5
6
4
5
6
5
3

result:

ok 100 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 8440kb

input:

1
100000
000101101111111110101100100000101111001010100001111011111000110000110111101101010110010111000000101010001011110001100110110001010000010010000010100100000000001101110110101101001010110111001010100110100111111101000110100111011111101011101100110001011000000000011111011100111110100100100010101...

output:

8

result:

ok single line: '8'

Test #6:

score: 0
Accepted
time: 0ms
memory: 10436kb

input:

1
100000
011010011100000110100111110110111110011001001000000111111100011100110010001110000111111010100110000111000100000001010010100110111001010010100111000000000111110101011101000001010100111100001110010101111100011000001011000111010111110010001111000011101100011110111100010101100010111101010001110...

output:

8

result:

ok single line: '8'

Test #7:

score: 0
Accepted
time: 1ms
memory: 8044kb

input:

1000
100
0000000000100010000000001100000000000010010101000010000000000000000000000010010000000000110000000010
100
0000000000000000000000000000000100000000000000000000001100000110000000000000010000010000100101000000
100
000010000000000000000000000000000000000000000000000000000010000000000000000000000...

output:

12
31
27
16
14
27
14
42
13
10
23
16
12
11
28
24
20
15
17
10
23
23
7
22
15
21
12
22
16
12
10
8
19
19
27
13
15
10
10
17
20
23
10
6
28
12
36
12
22
20
14
12
14
11
32
12
9
14
20
12
11
27
12
8
13
11
11
13
13
18
7
12
16
15
21
13
13
27
19
8
20
13
12
15
32
29
17
11
27
17
19
12
23
10
10
23
13
9
9
20
10
15
30
...

result:

ok 1000 lines

Test #8:

score: 0
Accepted
time: 1ms
memory: 5952kb

input:

1000
100
1000000010000100000000000000000001100000011000000100100000000000110000000100100000000000001000000100
100
0000000000000010011000000010000010000000000000000000000000000000100100000100000000000010000000000000
100
000000010010000000000000001000000000000000000000010000001001000001000001000000010...

output:

10
16
20
17
15
15
19
16
12
21
32
11
43
23
17
14
16
20
9
8
14
40
13
9
13
13
41
13
10
13
18
29
15
22
11
7
17
10
31
13
11
27
15
13
32
19
14
12
19
10
27
16
14
22
23
12
18
14
18
12
13
18
48
18
9
11
13
19
11
40
19
17
10
11
15
11
10
24
9
19
10
22
18
24
14
20
11
10
21
16
11
21
16
13
16
45
26
12
14
10
11
14
...

result:

ok 1000 lines

Test #9:

score: 0
Accepted
time: 1ms
memory: 8048kb

input:

1000
100
0000000000100000001000000000000000010000000000010000000010100000000000000000000000101000000000000001
100
0000000000010000000000000001001000100000001000000000000010100001000000000000000000100000000000000000
100
000100000000000000000000010000100000000000000100000000000000000010000000100000000...

output:

12
17
11
8
15
16
22
26
22
13
17
14
15
21
10
7
10
51
14
13
22
10
40
21
34
16
16
18
12
17
14
34
22
21
11
16
15
15
14
9
11
14
8
20
25
11
19
20
14
18
42
9
14
30
9
33
18
9
12
9
20
19
17
18
17
19
13
14
32
16
14
27
18
14
17
12
9
58
34
8
30
14
16
19
16
21
13
23
28
15
33
10
11
41
19
27
24
15
11
17
18
21
14
1...

result:

ok 1000 lines

Test #10:

score: 0
Accepted
time: 3ms
memory: 8648kb

input:

1
1000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

435

result:

ok single line: '435'

Test #11:

score: 0
Accepted
time: 3ms
memory: 8220kb

input:

1
1000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

3424

result:

ok single line: '3424'

Test #12:

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

input:

1
1000000
10100100000000000000000001000000000001001000000010110000000000001000001010001100000101010010000010000001111000000110001101000000110100000010000000010000000000000000010001010000001000100100110001000100011100000011001000001000010100001000000000000010010100000001010000000000001000010000100101...

output:

28

result:

ok single line: '28'

Test #13:

score: 0
Accepted
time: 3ms
memory: 11944kb

input:

1
1000000
10001100000011000000100110010100101010100000001100000100000000001000110000000000000011000100000101000010011100000100100011100000110011110100000100001010000101001000001110000000100100111001000000001001011010001001111011000100001100000000000100001101000100000001000000001000010001100001000000...

output:

25008

result:

ok single line: '25008'

Test #14:

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

input:

1
1000000
10101101010100110100001011000000011100100010001010000000010010000100101010000001000000100011000000000000010000000001000111001101100001000011000001010110010000001000100100000000101001000010010000000010000000010110000100010000101001010000001010000000111000010011000100000000010110010100000010...

output:

50002

result:

ok single line: '50002'

Test #15:

score: 0
Accepted
time: 7ms
memory: 9984kb

input:

1
1000000
11000000011101000010000111101010011000001110000001010011000100111010010000000001000000000011111001001000111000100001000000000100110010010000001000000100100000010010000011000000100001000100001101000000110001000000110000011010110100011110001000010000101001000000100010010110110000000000000111...

output:

19

result:

ok single line: '19'

Test #16:

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

input:

1
1000000
10011000000001100001010001111011101001101110101010000001100001000100010010010001000011100101001100011110101110000000101001001000011101011000000100011100000000001001001000100000110000001000000000011000101000010010000101000110000011100100011100001011101110011001011100000100001000010000101000...

output:

50002

result:

ok single line: '50002'

Test #17:

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

input:

1
1000000
10011000000000001101000010001000000010101000001010110011000000010010001100001100010000110000000000000101000100100010011000001010001000011001010001001000001100000000000110000001010110000000100010010000000000000000100101100010000101001000010110000101010110100000001011000110000001000010000110...

output:

21

result:

ok single line: '21'

Test #18:

score: 0
Accepted
time: 2ms
memory: 12544kb

input:

1
1000000
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

150000

result:

ok single line: '150000'

Test #19:

score: 0
Accepted
time: 4ms
memory: 12416kb

input:

1
1000000
11010010111111011011011111000111011110010111101010011110101010111001100110111101001111101011101111010011110101001011110110111111110100010111010101100011011001111111111001100110110101011111001110110011011110011110110101011000010011011010111100111011101111011111110111110110111001111000110011...

output:

100000

result:

ok single line: '100000'

Test #20:

score: 0
Accepted
time: 9ms
memory: 14444kb

input:

1
1000000
11011001111110011111111100010101111111010100010010101111010000011110010101011001011010101001101100001001100011011000100100001101100100110100001000000100100111100110010111100010100110100011001101001111011010001000001010001111100001110011000010000110010100011000001110011101111010000111100001...

output:

50003

result:

ok single line: '50003'

Test #21:

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

input:

1
1000000
10100110111101111110101011000111101110011111011110101001010110101011011101011100011111011111111011010111001101111100001011111011100010110100011001110011100000011011101111011110110011001000010011111111110101001110110111111101010010100110110111001101010100101111011011010111110110011101111010...

output:

50002

result:

ok single line: '50002'

Test #22:

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

input:

1
1000000
11111111110100101111101000101101100010010111101101001001100011111001111010101100001000011010000010011101111100100110011101101011010110110001110111111011001111110010110010101111100110010000001010010110010111110101001001001111011101111110111011100011110101010111111110110110111101111111011111...

output:

40000

result:

ok single line: '40000'

Test #23:

score: 0
Accepted
time: 10ms
memory: 14284kb

input:

1
1000000
11110001001000011010011010100100011101100001111111111011111001011110110010010010010010111010101001001101100111000110001111011111101111101010111111110111101101111000110110011101111000001011100111100100000010001101010011001000110111011110010101000110011010101101010101000010010110101111011100...

output:

30001

result:

ok single line: '30001'

Test #24:

score: 0
Accepted
time: 11ms
memory: 14544kb

input:

1
1000000
11110001011010110101101101101001101100110001101000011100010010101010110000000111111010011101001110100001100011010111101000110110011000100100000001101110010011000111011110100100011011011101110001011010001011100000110110100000011010001111011111111000010000011000100101101000110000000001100101...

output:

20000

result:

ok single line: '20000'

Test #25:

score: 0
Accepted
time: 7ms
memory: 16592kb

input:

1
1000000
11110110100100101100010010101101010011010011000110111100000101011101000000110010101110100100101110111101001100010111010000110010100010101111001100111111100101100110111001100101000010011011011100111000011001001110110010110001001011110100010100111100101001101001010110011001011101011110111111...

output:

10000

result:

ok single line: '10000'

Test #26:

score: 0
Accepted
time: 7ms
memory: 13588kb

input:

1
1000000
10110110111011101100011011010100100110011110101101000100010110011111001110111100010111100101001101101111100101010100110011101000101101000010100100110101110001010100011011111001001011011110111010000000101100100010010100110010001101010110010011111101101111011011111000101100010100111001110111...

output:

5002

result:

ok single line: '5002'

Test #27:

score: 0
Accepted
time: 11ms
memory: 16584kb

input:

1
1000000
11011000001110011101010011011111101111000101001101000111000111000000110000000001000010001101110000110110101010011110110100011001101000010010101011000101000101111111011010100011010100000011101101010011110010100000111111010010011101010011100101001001011011011001111001111000110001101111001000...

output:

10

result:

ok single line: '10'

Test #28:

score: 0
Accepted
time: 0ms
memory: 8136kb

input:

1
100000
111110101000100010100110001101001111100000100010101001000000110111110010011111110011001100010100101001000000110010110110001001110001100000000110000000001110100000010001111010000001100011110111111100100010100111100101001100110011110100011011100111111000101110101101000011101011101111110001010...

output:

50000

result:

ok single line: '50000'

Test #29:

score: 0
Accepted
time: 3ms
memory: 12416kb

input:

1
1000000
10100000111001011000001111001101011111100001011101011001110001000001111011001101000110111010000111100011111100001100111101101001101101111010111110011100001111100100101100101000000110000110001101011000011100000111001001111100100000011011000101100001000000111001101010000010111000110100101100...

output:

500001

result:

ok single line: '500001'

Test #30:

score: 0
Accepted
time: 3ms
memory: 10092kb

input:

1
1000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

500002

result:

ok single line: '500002'

Test #31:

score: 0
Accepted
time: 2ms
memory: 8048kb

input:

1
500000
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

146513

result:

ok single line: '146513'

Test #32:

score: 0
Accepted
time: 7ms
memory: 9920kb

input:

1
1000000
11111010101001011110111001010011100110100111111101110101110110111010010001111111001101111100010011111111011011001101011001101001101111010010111111110110111011101011010001001011000010110110101011110111111011101111001010100011011110111110111110100111101010110010111101111100111111011111110110...

output:

500000

result:

ok single line: '500000'

Test #33:

score: 0
Accepted
time: 3ms
memory: 14464kb

input:

1
1000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

500000

result:

ok single line: '500000'