QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#777238#9783. Duloc Networkucup-team3670#WA 18ms4924kbC++202.0kb2024-11-23 23:58:002024-11-23 23:58:02

Judging History

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

  • [2024-11-23 23:58:02]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:4924kb
  • [2024-11-23 23:58:00]
  • 提交

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(44);

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;
}

详细

Test #1:

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

input:

4
1
3
2
2
2
1

output:

? 1000
? 0100
? 0010
? 0001
? 1001
? 1011
! 1

result:

ok Correct answer with 6 queries.

Test #2:

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

input:

2
0

output:

? 10
! 0

result:

ok Correct answer with 1 queries.

Test #3:

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

input:

4
1
3
2
2
2
1

output:

? 1000
? 0100
? 0010
? 0001
? 1001
? 1011
! 1

result:

ok Correct answer with 6 queries.

Test #4:

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

input:

2
0

output:

? 10
! 0

result:

ok Correct answer with 1 queries.

Test #5:

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

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
4
5
3
2
6
3
5
6
5
6
5
3
4
4
3
5
5
3
3
5
3
3
3
5
2
3
4
4
8
4
3
5
3
5
3
3
3
3
3
6
3
5
3
3
4
3
9
4
4
2
3
5
2
3
4
2
4
5
4
4
2
4
3
5
2
2
2
3
4
4
0
5
6
4
6
5
3
7
6
4
3
4
2
9
2
1
4
5
4
6
6
5
4
3
4
2
1
5
2...

output:

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

result:

ok Correct answer with 211 queries.

Test #6:

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

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
15
19
21
17
22
12
18
17
17
21
21
15
19
22
16
32
37
27
23
24
13
38
24
38
37
28
14
27
26
30
23
26
16
32
32
21
35
17
30
32
32
34
38
30
27
18
36
9

output:

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

result:

ok Correct answer with 98 queries.

Test #7:

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

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
2
4
2
3
4
6
5
5
4
4
3
5
4
5
2
3
3
3
6
3
5
3
3
6
8
10
8
6
6
6
5
5
6
5
5
3
2
9
6
7
4
4
2
7
4
4
6
8
5
7
4
5
4
4
4
4
5
3
2
2
4
2
2
2
2
4
3
3
4
1
2
5
3
1
11
13
6
6
5
3
6
5
7
3
4
6
5
5
3
3
7
3
3
6
3
4
3
...

output:

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

result:

ok Correct answer with 271 queries.

Test #8:

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

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
21
15
17
11
12
15
22
13
15
15
21
17
18
15
13
14
18
11
10
18
27
21
20
13
15
30
22
36
36
31
15
14
25
18
24
20
25
17
29
23
19
25
34
16
36
20
26
33
12
23
29
31
27
21
34
10

output:

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

result:

ok Correct answer with 106 queries.

Test #9:

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

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
2
2
4
1
3
3
3
5
4
3
3
3
5
3
3
5
3
3
4
4
3
1
3
2
2
3
2
2
3
2
2
3
2
3
2
2
3
4
4
2
2
2
4
2
1
2
2
4
4
4
6
2
2
4
4
2
2
3
3
2
3
3
4
4
2
2
0
4
4
2
4
3
2
2
2
2
2
2
2
2
4
2
4
2
4
2
3
6
1
2
4
2
3
2
6
2
4
3
2...

output:

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

result:

ok Correct answer with 446 queries.

Test #10:

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

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
3
5
3
3
2
4
3
4
5
4
4
5
2
5
5
4
6
3
3
4
3
4
4
6
3
5
3
4
4
4
4
5
4
6
2
3
2
4
6
3
3
3
4
3
3
3
3
4
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 1162 queries.

Test #11:

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

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
20
22
15
21
19
20
19
14
20
20
20
11
23
23
31
31
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 231 queries.

Test #12:

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

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
5
3
5
8
5
5
8
9
8
8
11
6
7
8
8
5
8
7
7
7
6
2
6
3
6
5
6
8
5
9
8
5
4
5
5
9
7
3
5
4
6
4
7
4
3
4
4...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 651 queries.

Test #13:

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

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
2
2
3
2
2
2
2
3
4
2
3
2
3
2
2
2
4
2
3
3
4
4
2
2
2
3
4
5
5
2
2
2
5
2
2
2
5
4
3
3
3
6
6
4
5
4
3
4
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 542 queries.

Test #14:

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

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
4
3
3
3
3
3
3
3
5
3
3
5
2
2
3
2
4
2
2
4
1
2
2
2
3
4
3
2
2
3
2
2
2
2
2
2
2
2
2
3
2
2
3
3
4
5
2
2
...

output:

? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

ok Correct answer with 556 queries.

Test #15:

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

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 1512 queries.

Test #16:

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

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 1679 queries.

Test #17:

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

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 1719 queries.

Test #18:

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

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 1487 queries.

Test #19:

score: 0
Accepted
time: 12ms
memory: 4296kb

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 2162 queries.

Test #20:

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

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 2977 queries.

Test #21:

score: 0
Accepted
time: 18ms
memory: 4692kb

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:

ok Correct answer with 3498 queries.

Test #22:

score: -100
Wrong Answer
time: 18ms
memory: 4924kb

input:

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

output:

? 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
? 01000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

result:

wrong answer Wrong answer.