QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#777245#9783. Duloc Networkucup-team3670#WA 21ms4712kbC++202.0kb2024-11-23 23:58:342024-11-23 23:58:38

Judging History

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

  • [2024-11-23 23:58:38]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:4712kb
  • [2024-11-23 23:58:34]
  • 提交

answer

#include <bits/stdc++.h>

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define fore(i, l, r) for (int i = int(l); i < int(r); ++i)
#define sz(a) (int)((a).size())

using namespace std;

typedef long long li;

typedef string bs;

string operator |(const string &a, const string &b){
	string c(a.size(), '0');
	forn(i, a.size()) c[i] = max(a[i], b[i]);
	return c;
}

/*string operator !(const string &a){
	string c(a.size(), '0');
	forn(i, a.size()) c[i] = a[i] ^ '0' ^ '1';
	return c;
}*/

int n;
map<bs, int> memo;

int queries;
mt19937 rnd(49);

int ask(bs cur){
	int cnt = count(cur.begin(), cur.end(), '1');
	if (memo.count(cur))
		return memo[cur];
	if (cnt == 0 || cnt == n)
		return memo[cur] = 0;
	++queries;
	if (queries == 3499){
		cout << "! " << rnd() % 2 << endl;
		exit(0);
	}
	cout << "? ";
	forn(i, n) cout << cur[i];
	cout << endl;
	int x;
	cin >> x;
	return memo[cur] = x;
}

int ask2(bs a, bs b){
	return ask(a) + ask(b) != ask(a | b);
}

vector<bs> comp;
vector<int> rk, p;

int getp(int a){
	return a == p[a] ? a : p[a] = getp(p[a]);
}

void unite(int a, int b){
	a = getp(a), b = getp(b);
	if (a == b) return;
	if (rk[a] < rk[b]) swap(a, b);
	rk[a] += rk[b];
	p[b] = a;
	comp[a] = comp[a] | comp[b];
}

int main(){
	//cin.tie(0);
	//ios::sync_with_stdio(false);
	cin >> n;
	comp.assign(n, string(n, '0'));
	forn(i, n) comp[i][i] = '1';
	forn(i, n) if (ask(comp[i]) == 0){
		cout << "! " << 0 << endl;
		return 0;
	}
	rk.assign(n, 1);
	p.resize(n);
	iota(p.begin(), p.end(), 0);
	vector<int> ord(n);
	iota(ord.begin(), ord.end(), 0);
	while (sz(ord) > 1){
		shuffle(ord.begin(), ord.end(), rnd);
		bool ok = false;
		fore(i, 1, sz(ord)) if (ask2(comp[getp(ord[0])], comp[getp(ord[i])])){
			unite(ord[0], ord[i]);
			ok = true;
			break;
		}
		if (!ok){
			cout << "! " << 0 << endl;
			return 0;
		}
		vector<int> nord;
		forn(i, sz(ord)) if (ord[i] == getp(ord[i]))
			nord.push_back(ord[i]);
		ord = nord;
	}
	cout << "! " << 1 << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
1
3
2
2
2
2

output:

? 1000
? 0100
? 0010
? 0001
? 0101
? 1010
! 1

result:

ok Correct answer with 6 queries.

Test #2:

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

input:

2
0

output:

? 10
! 0

result:

ok Correct answer with 1 queries.

Test #3:

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

input:

4
1
3
2
2
2
2

output:

? 1000
? 0100
? 0010
? 0001
? 0101
? 1010
! 1

result:

ok Correct answer with 6 queries.

Test #4:

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

input:

2
0

output:

? 10
! 0

result:

ok Correct answer with 1 queries.

Test #5:

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

input:

50
3
1
1
1
1
4
3
1
1
2
3
3
2
1
2
4
3
1
1
1
2
4
1
3
1
4
3
2
2
2
4
2
2
1
1
2
1
2
4
1
1
3
3
3
6
2
1
3
2
3
2
4
3
2
4
5
4
3
4
3
3
5
3
6
3
5
3
3
3
2
3
2
4
4
5
5
4
5
4
6
4
4
6
3
2
2
4
3
4
3
3
7
3
3
5
4
2
4
5
3
4
2
2
2
2
1
3
4
3
3
3
4
2
3
3
3
2
5
5
2
2
3
4
4
2
3
2
6
5
6
5
5
7
5
8
5
5
3
6
7
6
6
4
3
4
5
2
5
3...

output:

? 10000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000
? 00010000000000000000000000000000000000000000000000
? 00001000000000000000000000000000000000000000000000
? 000001000000000000000000000000000...

result:

ok Correct answer with 281 queries.

Test #6:

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

input:

50
10
13
8
6
13
8
10
8
8
8
9
13
15
11
9
10
14
6
16
10
15
10
7
8
10
10
10
13
10
15
9
10
11
5
16
10
14
11
10
9
9
15
11
10
7
11
12
10
9
10
17
15
20
16
21
16
26
20
23
22
19
15
21
28
16
29
21
25
16
14
29
24
27
22
33
21
32
26
14
20
32
31
34
34
18
34
24
32
22
30
25
34
32
29
36
26
24
31
20
7

output:

? 10000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000
? 00010000000000000000000000000000000000000000000000
? 00001000000000000000000000000000000000000000000000
? 000001000000000000000000000000000...

result:

ok Correct answer with 100 queries.

Test #7:

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

input:

50
1
3
1
4
3
1
1
1
1
3
1
1
1
1
3
5
1
1
1
1
3
2
5
1
2
1
4
1
2
3
4
3
3
2
3
1
1
1
1
3
2
2
1
3
4
2
4
2
3
2
6
6
7
3
2
4
2
5
2
4
4
6
4
3
3
4
3
4
6
6
6
6
7
6
6
5
8
2
4
2
3
5
2
2
4
9
2
5
2
2
4
3
2
3
2
3
3
5
4
3
6
4
3
6
2
3
5
4
4
2
2
1
7
6
4
4
5
6
3
3
3
3
8
3
3
3
3
3
7
13
4
7
4
5
4
4
7
4
4
15
4
4
8
14
4
4
4
...

output:

? 10000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000
? 00010000000000000000000000000000000000000000000000
? 00001000000000000000000000000000000000000000000000
? 000001000000000000000000000000000...

result:

ok Correct answer with 271 queries.

Test #8:

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

input:

50
2
14
8
8
7
12
12
8
8
9
9
10
8
8
4
8
9
9
9
11
13
11
8
7
9
12
7
5
6
4
7
8
10
5
5
10
8
4
10
9
11
7
10
8
6
8
10
7
5
9
19
15
11
12
17
14
14
14
19
19
18
18
21
13
9
18
15
27
9
32
18
21
14
23
23
25
24
34
17
30
22
13
13
14
10
12
18
14
28
21
34
34
14
34
19
23
8
11
21
4
28
28
23
35
33
30
34
28
26
23
21
8

output:

? 10000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000
? 00010000000000000000000000000000000000000000000000
? 00001000000000000000000000000000000000000000000000
? 000001000000000000000000000000000...

result:

ok Correct answer with 112 queries.

Test #9:

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

input:

50
3
1
1
1
2
1
1
1
1
5
1
2
1
1
1
1
3
1
1
2
1
1
1
2
2
1
1
1
1
3
1
2
1
1
2
3
1
2
3
2
1
3
1
2
3
1
2
2
1
1
3
2
4
2
2
3
2
2
1
2
2
2
2
2
4
3
3
2
2
3
4
2
4
2
6
2
4
3
3
3
2
3
4
4
3
5
4
2
3
3
2
2
2
3
2
5
3
4
4
2
2
2
2
2
3
1
2
3
3
4
3
2
4
2
2
2
2
2
4
3
3
2
2
3
3
3
3
4
2
2
3
2
2
5
2
2
3
2
4
2
4
2
2
2
2
5
2
4
3...

output:

? 10000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000
? 00010000000000000000000000000000000000000000000000
? 00001000000000000000000000000000000000000000000000
? 000001000000000000000000000000000...

result:

ok Correct answer with 294 queries.

Test #10:

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

input:

100
1
2
1
1
1
1
1
1
3
3
1
1
2
3
4
1
2
2
2
1
2
2
1
2
2
1
1
1
3
2
1
2
2
1
4
1
1
1
3
2
4
1
3
2
3
3
3
1
1
1
1
2
1
2
2
4
3
1
2
1
1
1
1
3
3
3
2
1
1
2
1
2
2
3
2
1
5
3
5
1
1
1
1
1
1
1
1
3
4
1
2
1
2
1
1
2
1
3
2
1
2
4
3
3
2
2
2
4
2
2
2
2
2
3
4
5
3
2
2
2
3
4
3
6
3
3
2
3
4
3
2
3
3
2
4
2
2
3
3
5
2
2
4
4
3
3
4
4
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 571 queries.

Test #11:

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

input:

100
11
13
9
11
8
7
15
12
8
8
7
6
9
12
11
9
10
9
11
16
10
8
9
8
10
6
8
9
13
10
9
7
5
11
14
6
11
16
7
7
8
8
11
8
13
15
11
12
11
11
11
9
10
12
10
6
11
10
5
13
9
9
6
6
6
12
7
12
10
10
9
11
7
11
5
6
9
6
5
9
5
16
11
13
13
10
5
5
8
8
12
11
5
8
8
10
8
10
8
10
26
22
19
20
17
19
19
18
17
21
20
42
18
15
28
18
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 223 queries.

Test #12:

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

input:

100
5
3
3
4
2
2
2
8
4
5
4
4
2
2
3
4
6
5
1
4
3
3
2
5
5
2
2
4
3
4
4
4
4
1
3
5
3
4
4
3
3
4
1
3
3
2
5
5
5
1
3
4
3
4
2
2
4
2
1
3
3
7
3
5
5
6
6
1
3
2
3
3
3
2
1
6
3
5
5
3
4
4
2
2
1
5
7
3
3
1
6
2
2
5
2
5
3
3
6
4
7
8
7
5
7
9
7
5
6
10
5
7
7
10
6
11
6
5
5
3
6
5
6
5
8
6
3
6
5
4
6
4
7
6
7
9
8
3
9
6
8
8
9
6
9
10
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 556 queries.

Test #13:

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

input:

100
1
1
1
3
1
1
3
1
4
1
2
3
4
1
1
2
4
1
3
2
1
3
2
4
1
3
1
1
2
1
1
1
3
1
1
4
1
1
1
1
4
1
2
1
3
3
1
1
3
4
1
2
2
3
3
1
1
1
1
4
1
1
1
1
1
2
2
2
2
1
2
2
2
2
2
1
1
2
5
1
2
2
1
1
2
2
2
4
1
1
1
5
4
1
3
1
1
1
2
1
3
3
2
2
2
2
3
2
3
2
2
3
2
5
2
2
4
2
2
3
3
4
2
2
4
5
2
3
4
5
3
2
2
3
2
2
3
2
2
4
2
2
3
3
2
5
3
2
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 1111 queries.

Test #14:

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

input:

100
1
1
2
3
1
3
2
1
1
1
1
1
1
4
1
1
1
2
1
1
2
3
1
1
1
2
1
2
2
2
1
2
1
1
1
4
3
1
1
1
1
2
2
3
2
1
1
1
1
1
1
1
1
5
3
1
1
2
1
1
2
1
2
2
1
2
3
1
1
1
1
1
3
1
1
1
1
1
3
1
1
1
2
2
1
3
3
2
1
4
3
1
2
3
1
1
2
1
2
1
2
2
3
2
2
2
2
5
2
2
3
4
3
2
3
2
4
2
2
2
4
3
2
2
2
2
3
6
3
4
2
2
2
3
3
2
4
3
2
2
3
2
3
2
1
4
2
2
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 1356 queries.

Test #15:

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

input:

150
4
2
3
2
2
3
2
4
3
3
4
2
2
4
6
1
3
2
3
5
3
4
4
3
6
3
1
2
4
5
5
3
2
3
3
2
3
1
2
4
2
4
4
1
2
3
2
3
1
1
4
4
3
2
2
1
3
3
1
2
1
6
1
3
2
4
1
4
2
1
4
3
4
1
3
4
2
4
2
5
3
4
2
6
6
2
2
2
3
2
4
4
4
2
2
1
2
1
3
2
3
7
2
1
3
2
5
4
1
2
3
2
3
2
3
5
3
4
5
2
3
1
3
1
2
3
1
3
1
2
3
3
2
3
7
1
2
1
4
2
2
2
3
4
4
3
6
3
...

output:

? 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 1633 queries.

Test #16:

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

input:

150
4
2
2
1
2
1
1
8
1
2
1
3
4
2
1
4
3
2
1
4
3
1
1
4
5
3
2
3
3
2
4
1
3
4
4
5
4
2
6
4
2
2
2
2
3
6
2
3
3
4
3
3
2
3
2
4
2
1
1
1
1
2
2
4
2
3
3
3
7
1
4
3
3
3
4
2
2
1
2
2
2
1
2
4
2
1
2
2
4
2
2
4
2
6
2
4
4
2
1
2
4
2
5
1
4
3
3
1
2
4
4
2
2
3
4
1
4
2
2
3
3
3
2
3
2
6
3
3
2
3
1
1
3
5
2
3
2
2
2
3
1
3
3
4
3
3
2
3
...

output:

? 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 1528 queries.

Test #17:

score: 0
Accepted
time: 20ms
memory: 4108kb

input:

150
3
1
4
1
4
2
3
1
1
3
1
1
4
5
7
1
2
1
2
3
4
2
3
5
1
5
1
2
2
5
3
6
2
2
1
3
5
1
3
2
2
3
1
2
1
3
2
2
1
3
2
2
2
5
1
2
2
5
5
2
3
4
1
3
1
2
1
2
2
1
1
5
3
1
3
1
2
3
1
2
2
2
1
4
1
2
2
5
3
2
1
4
2
2
5
1
3
3
1
4
3
2
4
1
5
3
4
2
2
3
1
2
4
3
3
2
1
2
3
1
1
2
1
3
4
3
1
2
4
4
3
1
7
4
1
1
1
1
4
3
2
3
2
2
1
3
3
1
...

output:

? 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 1952 queries.

Test #18:

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

input:

150
4
4
5
4
2
2
5
3
1
4
2
2
3
1
1
2
2
3
3
3
8
2
1
3
2
2
3
1
1
3
2
3
2
3
3
7
1
2
1
5
4
1
4
4
3
2
3
2
5
7
3
2
1
2
1
3
5
3
3
6
3
3
5
3
5
5
1
4
2
5
2
3
2
2
1
3
2
2
2
2
1
3
2
1
2
5
4
3
6
3
2
3
1
2
3
3
1
4
2
2
2
3
4
3
1
5
2
1
5
2
4
6
3
3
2
3
3
2
3
1
5
1
3
2
3
8
2
5
1
4
5
4
1
1
3
1
1
1
5
3
1
3
4
2
3
2
2
4
...

output:

? 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 1335 queries.

Test #19:

score: 0
Accepted
time: 13ms
memory: 4580kb

input:

150
2
1
1
3
2
2
2
1
1
1
1
1
2
2
2
1
1
3
3
2
2
1
2
1
2
5
4
2
1
2
2
2
2
1
2
1
2
1
2
3
3
2
3
2
1
1
2
2
3
1
2
1
1
3
3
2
4
2
1
1
2
5
2
2
2
2
1
1
3
2
1
3
1
5
3
1
3
1
4
1
2
1
3
1
1
1
3
1
1
2
1
5
3
1
1
1
2
1
2
1
2
1
1
2
2
3
1
2
1
2
2
2
2
2
3
1
5
2
1
2
3
2
1
2
4
1
1
2
3
3
3
1
2
1
3
2
2
1
1
2
2
3
1
1
1
1
4
1
...

output:

? 100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 3047 queries.

Test #20:

score: 0
Accepted
time: 14ms
memory: 4476kb

input:

200
1
3
1
3
3
1
1
1
1
1
2
1
3
2
2
1
1
3
1
2
1
1
1
1
2
2
1
1
1
2
1
4
1
1
1
1
2
1
1
2
3
1
1
1
4
1
1
1
1
3
1
1
1
1
2
1
1
1
1
2
1
2
1
2
1
1
1
1
1
4
1
1
1
1
1
1
1
1
1
2
1
1
2
1
2
2
2
4
1
2
1
1
5
2
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
3
1
2
1
1
3
1
1
1
2
1
5
1
1
1
1
4
1
4
1
1
3
1
3
1
3
1
1
4
1
2
1
3
1
2
2
2
...

output:

? 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 2725 queries.

Test #21:

score: -100
Wrong Answer
time: 21ms
memory: 4712kb

input:

200
3
2
2
2
2
2
1
1
1
4
2
1
2
2
2
2
1
1
2
1
1
3
1
1
2
2
2
3
1
2
1
1
2
1
2
2
2
3
3
3
2
2
1
1
4
1
1
2
2
2
2
1
2
2
1
3
2
3
2
1
1
1
1
1
2
2
1
1
2
1
1
4
2
1
1
1
1
2
3
2
1
2
3
4
1
1
2
5
5
2
1
3
2
3
1
3
1
2
1
2
1
1
3
2
2
3
3
4
1
1
2
1
3
2
1
1
1
1
1
4
2
1
1
1
1
2
2
2
3
2
2
2
1
1
1
2
3
3
2
2
2
3
1
4
1
3
2
1
...

output:

? 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

wrong answer Wrong answer.