-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRailway System.cpp
More file actions
47 lines (43 loc) · 827 Bytes
/
Railway System.cpp
File metadata and controls
47 lines (43 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "algo/debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
auto Ask = [&](string s) {
cout << "? " << s << endl;
long long x;
cin >> x;
return x;
};
vector<long long> l(m);
for (int i = 0; i < m; i++) {
string s(m, '0');
s[i] = '1';
l[i] = Ask(s);
}
vector<int> order(m);
iota(order.begin(), order.end(), 0);
sort(order.begin(), order.end(), [&](int i, int j) {
return l[i] < l[j];
});
string s(m, '0');
long long ans = 0;
for (int i : order) {
s[i] = '1';
long long got = Ask(s);
if (got == ans + l[i]) {
ans = got;
} else {
s[i] = '0';
}
}
cout << "! " << ans << endl;
return 0;
}