QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#200921 | #7510. Independent Set | w4p3r | RE | 1ms | 3844kb | C++20 | 2.1kb | 2023-10-05 00:53:34 | 2023-10-05 00:53:34 |
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, cnt[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>tmp, tb;
int mn = inf;
FOR(i, l, r)mn = min(mn, a[i]);
for (int x : b)if (x >= mn)tb.push_back(x); b = tb;
if (b.empty())return ;
FOR(i, l, r)tmp.push_back(a[i]);
for (int x : b)tmp.push_back(x);
vector<int>G = ask(tmp); int m = b.size();
vector<int>nb;
if (l == r)
{
FOR(i, 0, m - 1)
{
int x = a[l], y = b[i];
if (x <= y)while (G[i + 1] --)ans.push_back({x, y});
}
return ;
}
else
{
FOR(i, 0, m - 1)if (G[i + (r - l + 1)])nb.push_back(b[i]);
}
int mid = (l + r) >> 1;
calc(a, l, mid, nb); calc(a, mid + 1, r, nb);
}
void sol(vector<int>c)
{
if (c.empty())return ;
random_shuffle(c.begin(), c.end());
vector<int>tmp = ask(c);
vector<int>X, Y;
int m = c.size();
FOR(i, 0, m - 1)if (!tmp[i])X.push_back(c[i]); else Y.push_back(c[i]);
int k = X.size();
calc(X, 0, k - 1, Y);
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: 1ms
memory: 3844kb
input:
4 0 0 0 0 0 0 0 1 0 0 2 1 0 0 2 1 0 2 1 0 0
output:
? 2 1 1 ? 2 2 2 ? 2 3 3 ? 2 4 4 ? 4 1 4 2 3 ? 4 1 4 2 3 ? 3 1 2 3 ? 2 2 3 ! 4 4 4 1 2 1 2 1 3
result:
ok Ok, Accepted!
Test #2:
score: -100
Runtime Error
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 ...