QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#777214 | #9783. Duloc Network | ucup-team3670# | TL | 17ms | 4524kb | C++20 | 1.9kb | 2024-11-23 23:46:50 | 2024-11-23 23:46:50 |
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;
cout << "? ";
forn(i, n) cout << cur[i];
if (queries < 3500){
cout << endl;
}
else{
while (true);
}
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';
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: 3596kb
input:
4 3 2 2 2 1 1
output:
? 0100 ? 0001 ? 0101 ? 0010 ? 0111 ? 1000 ! 1
result:
ok Correct answer with 6 queries.
Test #2:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
2 0 0
output:
? 01 ? 10 ! 0
result:
ok Correct answer with 2 queries.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3620kb
input:
4 3 2 2 2 1 1
output:
? 0100 ? 0001 ? 0101 ? 0010 ? 0111 ? 1000 ! 1
result:
ok Correct answer with 6 queries.
Test #4:
score: 0
Accepted
time: 1ms
memory: 3596kb
input:
2 0 0
output:
? 01 ? 10 ! 0
result:
ok Correct answer with 2 queries.
Test #5:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
50 1 1 2 3 4 2 3 4 5 1 2 4 5 2 3 1 2 1 2 4 5 2 3 3 4 1 2 3 4 1 2 1 2 1 2 3 4 2 3 3 4 3 4 3 4 2 3 3 4 4 4 3 2 5 6 5 2 3 5 6 5 3 2 3 3 1 4 4 4 1 4 2 5 4 6 4 2 5 3 2 3 4 2 2 4 4 6 5 4 7 1 2 4 6 6 1 3 5 4 6 3 4 2 4 7 1 2 3 5 1 3 3 4 5 3 4 3 5 7 8 4 7 5 4 1 2 2 5 2 2 3 2 3 5 2 4 4 2 4 3 4 4 5 3 6 7 5 4 4...
output:
? 00000000000000000000000000000000000000001000000000 ? 00000000000000000000000010000000000000000000000000 ? 00000000000000000000000010000000000000001000000000 ? 00000000000000000000000000000000000000000010000000 ? 00000000000000000000000000000000000000001010000000 ? 000000000000000000000000000001000...
result:
ok Correct answer with 196 queries.
Test #6:
score: 0
Accepted
time: 0ms
memory: 3640kb
input:
50 9 10 17 8 10 13 9 10 15 15 13 25 8 19 10 15 22 11 7 17 6 14 18 10 10 17 10 20 9 16 21 5 8 13 9 13 9 23 10 19 13 31 30 11 16 24 15 27 11 10 18 10 10 18 11 10 17 12 13 25 6 17 15 39 11 24 10 22 8 22 9 22 7 27 10 33 8 27 39 37 13 24 34 34 8 26 35 32 10 36 33 32 14 36 35 26 36 22 35 14
output:
? 00000000000000000000000000000000000000001000000000 ? 00000000000000000000000010000000000000000000000000 ? 00000000000000000000000010000000000000001000000000 ? 00000000000000000000000100000000000000000000000000 ? 00000000000000000000000000001000000000000000000000 ? 000000000000000000000001000010000...
result:
ok Correct answer with 100 queries.
Test #7:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
50 2 2 4 1 3 3 4 1 2 1 3 2 5 3 6 1 4 1 2 2 3 5 1 2 1 2 3 2 3 2 1 3 4 4 5 5 1 2 1 2 3 1 2 4 5 3 4 2 3 3 2 3 3 4 1 2 3 4 4 5 1 2 2 4 5 3 4 1 2 3 4 1 2 0 5 8 6 1 2 4 3 1 2 1 2 1 2 1 2 3 2 3 1 2 3 3 2 3 3 4 4 2 6 1 4 4 1 2 3 2 4 3 4 2 3 4 2 2 2 3 2 5 3 5 5 3 4 3 3 5 2 2 3 3 3 6 4 2 4 2 4 2 4 4 3 3 2 3 5...
output:
? 00000000000000000000000000000000000000001000000000 ? 00000000000000000000000010000000000000000000000000 ? 00000000000000000000000010000000000000001000000000 ? 00000000000000000000000000000000000000000010000000 ? 00000000000000000000000000000000000000001010000000 ? 000000000000000000000000000001000...
result:
ok Correct answer with 244 queries.
Test #8:
score: 0
Accepted
time: 1ms
memory: 3848kb
input:
50 11 9 17 7 6 13 8 15 8 15 8 13 4 9 12 7 14 18 8 18 10 13 18 10 8 17 9 13 12 11 21 8 24 9 5 14 23 5 9 14 5 9 9 13 2 11 5 14 10 17 10 20 29 4 9 13 8 20 8 7 14 11 12 17 10 18 15 11 9 16 4 20 10 24 8 20 12 20 7 19 6 23 8 33 8 26 27 28 7 24 29 33 8 24 35 27 7 35 30 30 8 33 37 20 35 22 34 14
output:
? 00000000000000000000000000000000000000001000000000 ? 00000000000000000000000010000000000000000000000000 ? 00000000000000000000000010000000000000001000000000 ? 00000000000000000000000100000000000000000000000000 ? 00000000000000000000000000001000000000000000000000 ? 000000000000000000000001000010000...
result:
ok Correct answer with 108 queries.
Test #9:
score: 0
Accepted
time: 2ms
memory: 3652kb
input:
50 1 2 3 1 2 3 4 1 2 2 3 1 2 2 3 1 2 2 3 1 2 2 3 1 2 1 2 1 2 2 3 1 2 1 2 2 3 1 2 3 4 2 3 3 4 1 2 1 2 3 4 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 5 6 3 2 2 1 3 3 4 1 1 2 2 4 2 1 2 2 4 2 5 2 1 2 3 2 3 2 1 2 2 3 4 1 6 8 3 3 4 3 3 3 3 3 3 3 3 3 3 5 1 3 3 2 4 3 3 3 1 2 2 4 2 3 3 2 2 2 1 2 4 2 3 1 2 2 4 2 2 2 0 4...
output:
? 00000000000000000000000000000000000000001000000000 ? 00000000000000000000000010000000000000000000000000 ? 00000000000000000000000010000000000000001000000000 ? 00000000000000000000000000000000000000000010000000 ? 00000000000000000000000000000000000000001010000000 ? 000000000000000000000000000001000...
result:
ok Correct answer with 250 queries.
Test #10:
score: 0
Accepted
time: 4ms
memory: 3744kb
input:
100 1 2 3 4 5 2 3 1 2 3 4 1 2 1 2 2 3 1 2 2 3 1 2 1 2 2 3 2 3 1 2 1 2 3 4 2 3 3 4 1 2 1 2 1 2 3 2 1 3 4 2 3 2 4 5 2 3 1 3 1 3 3 5 5 7 2 4 2 2 1 2 2 3 4 5 2 3 1 2 1 2 3 4 2 5 3 6 8 6 1 4 1 4 5 1 4 1 4 3 6 5 4 2 5 2 5 2 5 3 6 1 4 1 4 7 1 4 5 1 4 1 4 7 3 6 1 4 1 4 1 4 4 1 4 1 4 6 4 1 4 1 4 2 5 3 6 2 5 ...
output:
? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000 ? 00000000000000000000000000000000000000000000000000000000000000000000000000100000000000000100...
result:
ok Correct answer with 960 queries.
Test #11:
score: 0
Accepted
time: 2ms
memory: 3812kb
input:
100 8 5 12 11 12 23 10 21 8 18 16 11 26 11 8 19 7 17 5 17 9 14 15 20 7 12 21 11 11 19 10 6 15 8 11 18 6 11 16 11 8 19 29 9 5 14 32 7 16 22 10 11 21 7 15 6 12 16 13 20 6 19 17 9 18 10 28 12 26 15 8 20 13 9 22 21 13 27 9 30 10 5 15 34 9 25 5 13 6 8 14 6 10 10 10 20 18 10 19 8 26 12 12 23 10 20 10 19 9...
output:
? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000 ? 00000000000000000000000000000000000000000000000000000000000000000000000000100000000000000100...
result:
ok Correct answer with 228 queries.
Test #12:
score: 0
Accepted
time: 4ms
memory: 3724kb
input:
100 1 1 2 2 1 4 2 5 4 1 5 1 5 4 8 5 7 1 5 6 3 4 3 4 4 5 3 4 4 5 2 3 2 3 5 5 4 6 2 3 1 2 3 4 5 5 4 3 7 4 7 4 7 4 7 3 6 4 7 4 1 4 5 3 6 2 5 5 8 4 3 6 3 6 6 9 3 6 5 8 2 5 2 5 5 8 9 2 7 3 5 6 2 4 4 6 4 5 7 5 7 7 9 3 5 7 8 4 6 7 6 8 4 4 3 5 3 5 8 6 7 4 6 3 4 5 9 8 3 9 6 7 3 4 6 3 4 5 9 6 7 6 2 3 3 5 6 2 ...
output:
? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000 ? 00000000000000000000000000000000000000000000000000000000000000000000000000100000000000000100...
result:
ok Correct answer with 537 queries.
Test #13:
score: 0
Accepted
time: 3ms
memory: 3680kb
input:
100 1 2 3 1 2 1 2 2 3 4 4 3 1 4 3 6 2 3 2 1 3 2 4 1 3 5 7 2 4 4 6 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 1 3 3 5 2 4 1 3 4 1 3 4 6 1 3 3 5 2 4 4 6 2 4 2 4 3 5 1 3 3 5 1 3 1 3 1 3 4 6 1 3 1 3 4 6 2 4 4 6 2 3 2 1 2 1 2 3 4 1 2 3 2 1 2 2 1 2 2 2 1 2 1 2 1 2 3 4 1 2 2 2 2 3 1 2 1 2 1 2 2 2 1 2 3 2 3 3 4 1 2 1 ...
output:
? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000 ? 00000000000000000000000000000000000000000000000000000000000000000000000000100000000000000100...
result:
ok Correct answer with 720 queries.
Test #14:
score: 0
Accepted
time: 5ms
memory: 3724kb
input:
100 4 1 5 1 5 2 6 3 7 2 6 3 7 1 5 2 6 1 5 1 5 1 5 1 5 5 8 3 4 7 3 6 4 1 4 4 5 2 5 1 4 2 5 4 1 4 3 4 1 3 1 3 4 3 5 3 5 1 3 1 3 5 1 3 1 3 1 3 1 3 1 3 3 2 4 2 2 1 2 1 2 1 2 1 2 2 3 2 5 3 4 3 1 2 4 5 2 1 2 2 3 2 3 2 5 1 2 2 2 1 2 1 2 2 3 1 2 2 2 2 3 2 3 2 3 2 3 2 3 2 3 1 2 2 1 2 2 2 3 1 2 3 4 1 2 3 4 2 ...
output:
? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000 ? 00000000000000000000000000000000000000000000000000000000000000000000000000100000000000000100...
result:
ok Correct answer with 1219 queries.
Test #15:
score: 0
Accepted
time: 4ms
memory: 3964kb
input:
150 2 3 5 6 8 5 7 2 4 3 5 2 4 1 3 1 3 5 7 1 3 6 8 1 3 2 4 4 6 2 4 4 6 3 5 1 3 2 4 3 5 2 4 2 4 1 3 3 5 2 4 1 2 2 4 6 4 5 7 9 1 8 9 1 8 9 3 10 3 10 10 4 7 2 5 5 2 5 5 6 2 5 1 4 4 2 5 5 8 3 6 8 3 6 4 7 2 5 6 9 1 4 4 7 1 4 1 4 3 6 4 3 3 5 4 4 5 4 9 3 8 2 7 2 7 5 10 6 6 7 6 3 8 3 8 4 7 2 3 5 2 4 1 3 7 9 ...
output:
? 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000...
result:
ok Correct answer with 1427 queries.
Test #16:
score: 0
Accepted
time: 4ms
memory: 4016kb
input:
150 2 1 3 2 4 2 4 2 4 4 6 6 6 4 2 6 1 5 3 7 2 6 2 6 3 7 6 10 5 9 1 5 3 5 2 4 6 1 3 2 4 1 3 4 3 5 4 6 2 4 2 4 4 6 3 5 4 6 6 8 2 4 4 6 2 4 5 7 4 2 4 2 4 2 4 4 6 3 5 1 3 4 6 3 5 1 3 2 4 3 5 3 5 4 6 4 6 4 6 4 6 3 5 4 6 3 5 3 5 1 3 2 4 2 4 2 4 2 4 4 6 3 5 2 4 4 6 4 4 2 4 6 1 3 4 1 3 2 4 6 7 9 6 3 3 5 1 3...
output:
? 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000...
result:
ok Correct answer with 1963 queries.
Test #17:
score: 0
Accepted
time: 8ms
memory: 3840kb
input:
150 2 3 4 4 1 5 2 6 4 8 2 6 4 8 2 6 3 7 3 7 5 9 1 5 2 6 1 5 8 3 7 1 5 3 7 4 8 3 7 4 8 2 6 2 6 3 7 2 6 1 5 2 5 1 2 3 5 6 1 2 3 1 2 2 3 5 6 2 3 3 3 4 4 3 4 3 4 1 2 5 6 1 2 4 5 2 3 4 1 2 2 5 6 1 2 1 2 2 5 6 2 3 1 2 1 2 1 2 1 2 2 3 4 3 4 3 4 2 3 2 3 1 2 2 3 5 6 4 5 1 2 4 5 3 4 2 3 4 3 4 3 4 2 1 2 1 2 1 ...
output:
? 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000...
result:
ok Correct answer with 921 queries.
Test #18:
score: 0
Accepted
time: 16ms
memory: 3980kb
input:
150 3 5 8 2 5 3 6 4 7 3 6 2 5 2 5 1 4 3 6 3 4 3 3 6 3 6 2 5 2 5 2 5 2 5 2 5 7 10 3 6 2 5 2 4 3 2 5 3 6 5 3 6 7 2 5 1 4 6 9 4 7 2 5 8 10 3 5 8 5 8 7 6 9 1 4 4 2 5 2 5 6 1 4 3 5 4 3 7 3 7 2 6 11 4 8 1 5 4 8 4 7 2 4 6 3 5 3 5 5 7 5 7 5 7 1 3 2 4 2 4 1 3 4 9 7 2 4 5 7 6 3 5 3 5 4 6 4 6 4 5 7 5 2 2 1 3 5...
output:
? 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000...
result:
ok Correct answer with 1688 queries.
Test #19:
score: 0
Accepted
time: 5ms
memory: 4172kb
input:
150 2 3 5 4 6 2 4 3 5 5 7 1 3 1 1 2 1 3 1 3 1 3 2 4 1 3 1 3 1 3 1 3 2 4 1 3 1 3 3 5 3 1 3 1 3 2 4 2 4 1 3 5 7 3 5 1 3 2 4 4 6 2 4 3 5 2 4 2 4 1 3 2 4 2 4 1 3 2 4 2 4 3 5 1 3 2 4 2 4 3 5 2 4 1 3 2 4 3 5 1 3 1 3 1 3 1 1 3 1 4 1 4 4 4 6 6 2 5 4 4 2 5 5 6 2 5 1 4 1 4 1 4 5 5 5 2 5 5 2 5 3 6 2 5 4 5 8 3 ...
output:
? 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000 ? 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000...
result:
ok Correct answer with 2279 queries.
Test #20:
score: 0
Accepted
time: 17ms
memory: 4524kb
input:
200 2 1 3 2 4 2 4 2 4 2 4 1 2 2 1 1 1 1 2 3 4 1 2 1 2 3 4 1 2 2 3 1 2 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 3 4 2 3 2 3 1 2 1 2 3 4 1 2 2 3 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 1 2 1 2 1 2 1 2 1 2 1 2 2 3 2 3 1 2 1 2 2 3 1 2 1 2 1 2 1 2 1 2 1 2 2 3 1 2 1 2 1 2 2 3 1 2 2 3 2 3 3 4 2 3 2 3 1 2 1 2 1 2 1 2 1 2 ...
output:
? 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
result:
ok Correct answer with 2211 queries.
Test #21:
score: -100
Time Limit Exceeded
input:
200 2 2 4 2 4 2 3 2 4 6 5 7 2 4 5 7 2 4 2 4 2 4 2 4 3 5 2 4 2 4 3 5 3 5 2 4 1 3 3 5 2 4 3 5 4 6 1 3 3 5 1 3 2 4 1 3 2 4 1 3 3 5 2 4 1 3 1 3 3 5 1 3 1 3 1 3 1 3 1 3 2 4 1 3 2 4 2 4 3 5 1 3 1 3 3 5 1 3 1 3 4 2 4 1 3 1 3 2 4 2 4 2 4 1 3 2 4 1 3 4 6 3 5 1 3 2 4 1 3 2 4 4 6 2 4 1 3 3 5 2 4 2 4 5 7 2 4 4 ...
output:
? 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 ? 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...