QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200932 | #7510. Independent Set | w4p3r | ML | 0ms | 3572kb | C++20 | 2.5kb | 2023-10-05 01:22:18 | 2023-10-05 01:22:18 |
Judging History
answer
#include<bits/stdc++.h>
#define inf 1e9
#define eps 1e-6
#define FOR(i, a, b) for(int i = a; i <= b; i ++)
#define REP(i, a, b) for(int i = a; i >= b; i --)
#define pb push_back
#define fr first
#define sd second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
char ch = getchar();
ll s = 0, w = 1;
while (ch < '0' || ch > '9') {if (ch == '-')w = -1; ch = getchar();}
while (ch >= '0' && ch <= '9') {s = s * 10 + ch - '0'; ch = getchar();}
return s * w;
}
#define N 4010
int n, m;
int S = 0;
bool vst[N];
vector<pair<int, int>>ans;
vector<int> ask(vector<int>a)
{
if (a.empty())return {};
S += a.size(); assert(S <= 176000);
cout << "? " << a.size() << ' ';
for (int x : a)cout << x << ' '; cout << endl;
vector<int>b;
for (int x : a) {int t; cin >> t; b.push_back(t);}
return b;
}
void calc(const vector<int>a, int l, int r, vector<int>b, vector<int>cnt)
{
if (l == r)
{
int m = b.size();
FOR(i, 0, m - 1) {while (cnt[i] --)ans.push_back({a[l], b[i]});}
return ;
}
if (b.empty())return ;
// cout << "GG:" << l << ' ' << r << ' ' << b.size() << endl;
// for (int x : b)cout << x << ' '; cout << endl;
// for (int t : cnt)cout << t << ' '; cout << endl << endl;
vector<int>tmp;
int mid = (l + r) >> 1;
FOR(i, l, mid)tmp.push_back(a[i]);
for (int x : b)tmp.push_back(x);
vector<int>ans = ask(tmp);
int m = b.size();
vector<int>lb, lcnt, rb, rcnt;
FOR(i, 0, m - 1)
{
int vl = ans[i + (mid - l + 1)], vr = cnt[i] - vl;
// cout << "EE:" << b[i] << ' ' << vl << ' ' << vr << " " << cnt[i] << endl;
if (vl) {lcnt.push_back(vl); lb.push_back(b[i]);}
if (vr) {rcnt.push_back(vr); rb.push_back(b[i]);}
}
calc(a, l, mid, lb, lcnt); calc(a, mid + 1, r, rb, rcnt);
}
void sol(vector<int>c)
{
if (c.empty())return ;
vector<int>tc = c;
for (int x : c)tc.push_back(x), vst[x] = 0;;
vector<int>tmp = ask(tc);
vector<int>X, Y, cnt;
int m = c.size();
FOR(i, 0, m - 1)if (!tmp[i])X.push_back(c[i]); else Y.push_back(c[i]), cnt.push_back(tmp[i + m]);
int k = X.size();
calc(X, 0, k - 1, Y, cnt);
sol(Y);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
FOR(i, 1, n)
{
vector<int>t = ask({i, i});
while (t[1] --)ans.push_back({i, i});
}
vector<int>a(n);
FOR(i, 0, n - 1)a[i] = i + 1;
sol(a);
cout << "!" << ' ';
cout << ans.size() << ' ';
for (auto [x, y] : ans)cout << x << ' ' << y << ' '; cout << endl;
return 0;
}
/*
6
4 6 8 9 2 4
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
4 0 0 0 0 0 0 0 1 0 2 1 0 0 2 1 1 0 2 1 0 0 0 0
output:
? 2 1 1 ? 2 2 2 ? 2 3 3 ? 2 4 4 ? 8 1 2 3 4 1 2 3 4 ? 3 1 2 3 ? 4 2 3 2 3 ! 4 4 4 1 2 1 2 1 3
result:
ok Ok, Accepted!
Test #2:
score: -100
Memory Limit Exceeded
input:
4000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
? 2 1 1 ? 2 2 2 ? 2 3 3 ? 2 4 4 ? 2 5 5 ? 2 6 6 ? 2 7 7 ? 2 8 8 ? 2 9 9 ? 2 10 10 ? 2 11 11 ? 2 12 12 ? 2 13 13 ? 2 14 14 ? 2 15 15 ? 2 16 16 ? 2 17 17 ? 2 18 18 ? 2 19 19 ? 2 20 20 ? 2 21 21 ? 2 22 22 ? 2 23 23 ? 2 24 24 ? 2 25 25 ? 2 26 26 ? 2 27 27 ? 2 28 28 ? 2 29 29 ...