QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#777233 | #9783. Duloc Network | ucup-team3670# | WA | 29ms | 4840kb | C++20 | 2.0kb | 2024-11-23 23:56:40 | 2024-11-23 23:56:41 |
Judging History
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;
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 == 3500){
cout << "! " << 1 << 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];
}
mt19937 rnd(42);
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: 3592kb
input:
4 1 3 2 2 2 1
output:
? 1000 ? 0100 ? 0010 ? 0001 ? 0101 ? 0111 ! 1
result:
ok Correct answer with 6 queries.
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
2 0
output:
? 10 ! 0
result:
ok Correct answer with 1 queries.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3820kb
input:
4 1 3 2 2 2 1
output:
? 1000 ? 0100 ? 0010 ? 0001 ? 0101 ? 0111 ! 1
result:
ok Correct answer with 6 queries.
Test #4:
score: 0
Accepted
time: 1ms
memory: 3592kb
input:
2 0
output:
? 10 ! 0
result:
ok Correct answer with 1 queries.
Test #5:
score: 0
Accepted
time: 2ms
memory: 3816kb
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 5 2 5 3 2 2 5 3 4 2 4 2 2 2 4 3 4 4 4 3 4 4 5 6 5 5 6 5 3 3 4 4 4 4 5 4 6 4 2 5 3 3 4 4 4 6 5 4 7 2 4 6 6 3 5 6 3 4 4 7 2 3 5 3 3 4 5 3 4 5 7 8 4 7 5 4 2 2 5 2 2 3 2 3 5 2 4 4 2 4 3 4 5 3 7 5...
output:
? 10000000000000000000000000000000000000000000000000 ? 01000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000 ? 00010000000000000000000000000000000000000000000000 ? 00001000000000000000000000000000000000000000000000 ? 000001000000000000000000000000000...
result:
ok Correct answer with 196 queries.
Test #6:
score: 0
Accepted
time: 1ms
memory: 3668kb
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 13 15 25 19 22 17 18 17 20 21 13 13 23 19 31 30 24 27 18 18 17 25 17 39 24 22 22 22 27 33 27 39 37 24 34 34 26 35 32 36 33 32 36 35 26 36 22 35 14
output:
? 10000000000000000000000000000000000000000000000000 ? 01000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000 ? 00010000000000000000000000000000000000000000000000 ? 00001000000000000000000000000000000000000000000000 ? 000001000000000000000000000000000...
result:
ok Correct answer with 100 queries.
Test #7:
score: 0
Accepted
time: 2ms
memory: 3652kb
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 4 3 4 1 5 6 4 2 5 2 2 3 3 2 4 5 5 2 2 3 2 5 4 3 3 3 4 2 4 5 2 2 5 4 2 4 2 0 8 6 2 3 2 2 2 2 3 2 3 2 3 3 2 3 3 4 4 2 6 1 4 4 2 3 2 4 4 2 4 2 2 2 3 2 5 3 5 3 4 3 3 5 2 3 3 3 6 4 2 4 2 4 2 4 4 3 3 2 3...
output:
? 10000000000000000000000000000000000000000000000000 ? 01000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000 ? 00010000000000000000000000000000000000000000000000 ? 00001000000000000000000000000000000000000000000000 ? 000001000000000000000000000000000...
result:
ok Correct answer with 244 queries.
Test #8:
score: 0
Accepted
time: 1ms
memory: 3632kb
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 17 13 15 15 13 12 18 18 18 17 13 21 24 14 23 14 9 13 11 14 17 20 29 13 8 20 14 17 18 15 11 16 20 24 20 20 19 23 33 26 27 28 24 29 33 24 35 27 35 30 30 33 37 20 35 22 34 14
output:
? 10000000000000000000000000000000000000000000000000 ? 01000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000 ? 00010000000000000000000000000000000000000000000000 ? 00001000000000000000000000000000000000000000000000 ? 000001000000000000000000000000000...
result:
ok Correct answer with 108 queries.
Test #9:
score: 0
Accepted
time: 2ms
memory: 3640kb
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 3 2 3 2 3 2 3 2 2 2 3 2 2 3 2 4 3 4 2 2 4 2 2 2 2 2 2 3 3 6 2 3 3 4 2 2 4 2 2 2 4 2 5 2 2 3 2 3 2 2 2 4 1 6 8 3 3 4 3 3 3 3 3 3 3 3 3 5 3 3 2 4 3 3 3 2 2 4 2 3 3 2 2 2 1 2 4 2 3 2 2 4 2 2 2...
output:
? 10000000000000000000000000000000000000000000000000 ? 01000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000 ? 00010000000000000000000000000000000000000000000000 ? 00001000000000000000000000000000000000000000000000 ? 000001000000000000000000000000000...
result:
ok Correct answer with 250 queries.
Test #10:
score: 0
Accepted
time: 6ms
memory: 3980kb
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 2 4 2 2 3 2 3 2 2 3 3 2 2 4 3 4 2 2 2 2 4 3 2 5 2 3 3 3 5 7 4 2 2 3 5 3 2 2 3 4 5 6 8 6 4 ...
output:
? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok Correct answer with 960 queries.
Test #11:
score: 0
Accepted
time: 2ms
memory: 3652kb
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 12 23 21 18 26 19 17 17 14 20 12 21 19 15 18 16 ...
output:
? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok Correct answer with 228 queries.
Test #12:
score: 0
Accepted
time: 2ms
memory: 3900kb
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 2 1 5 5 5 8 7 6 4 4 5 4 5 3 3 5 4 6 3 3 5 4 7 7 7 7 6 4 7 4 4 5 6 5 8 4 6 6 9 6 8 5 5 8 9 7 5 6 ...
output:
? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok Correct answer with 537 queries.
Test #13:
score: 0
Accepted
time: 0ms
memory: 3936kb
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 2 2 3 4 4 6 3 3 4 3 7 4 6 3 3 3 3 3 3 3 3 3 5 4 3 4 3 6 3 5 4 6 4 4 5 3 5 3 3 3 6 3 3 6 4 6 3 ...
output:
? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok Correct answer with 720 queries.
Test #14:
score: 0
Accepted
time: 3ms
memory: 3888kb
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 5 5 6 7 6 7 5 6 5 5 5 5 8 7 6 4 4 4 5 5 4 5 4 4 4 3 3 4 5 5 3 3 5 3 3 3 3 3 3 4 2 2 2 2 2 3 2 5 ...
output:
? 1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 0100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 00100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok Correct answer with 1219 queries.
Test #15:
score: 0
Accepted
time: 0ms
memory: 3956kb
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 1427 queries.
Test #16:
score: 0
Accepted
time: 6ms
memory: 4008kb
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 1963 queries.
Test #17:
score: 0
Accepted
time: 6ms
memory: 3732kb
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 921 queries.
Test #18:
score: 0
Accepted
time: 3ms
memory: 3960kb
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 1688 queries.
Test #19:
score: 0
Accepted
time: 10ms
memory: 4316kb
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 2279 queries.
Test #20:
score: 0
Accepted
time: 6ms
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 2211 queries.
Test #21:
score: -100
Wrong Answer
time: 29ms
memory: 4840kb
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.