QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#300508 | #7510. Independent Set | defyers# | WA | 1ms | 3620kb | C++14 | 4.1kb | 2024-01-08 13:27:41 | 2024-01-08 13:27:42 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using LL = long long;
using pii = pair<int, int>;
int n;
vector<int> v;
vector<vector<int>> IS;
vector<int> edge[4005];
int asked;
vector<int> ask(vector<int> &v) {
asked += (int)v.size();
if (asked > 176000) {
while (true) {
asked++;
}
}
cout << "? " << (int)v.size();
for (auto i : v) {
cout << " " << i;
}
cout << "\n";
cout.flush();
vector<int> ans;
for (int i = 0; i < v.size(); i++) {
int tmp;
cin >> tmp;
ans.push_back(tmp);
}
return ans;
}
vector<int> E;
void f(vector<int> &s1, vector<int> &s2, vector<int> &ans) {
// cout << "at s1=";
// for (auto i : s1) {
// cout << i <<" ";
// }
// cout << " s2=";
// for (auto i : s2) {
// cout << i << " ";
// }
// cout << endl;
if (!s1.size() || !s2.size()) return;
if (s2.size() == 1) {
// cout << " s2.size()== 1" << endl;
for (int i = 0; i < s1.size(); i++) {
int num = ans[i];
for (int j = 1; j <= num; j++) {
edge[s1[i]].push_back(s2[0]);
}
}
// cout << " leave" << endl;
// vector<int> cnts;
// for (int i = 1; i < ans.size(); i++) {
// cnts.push_back(ans[i]);
// }
return;
}
vector<int> h1, h2;
for (int i = 0; i < s2.size(); i++) {
if (i < s2.size() / 2) h1.push_back(s2[i]);
else h2.push_back(s2[i]);
}
vector<int> q;
for (auto i : h1) {
q.push_back(i);
}
for (auto i : s1) {
q.push_back(i);
}
auto t = ask(q);
vector<int> res, nonzero1;
int p = 0;
for (int i = h1.size(); i < h1.size() + s1.size(); i++) {
ans[p] -= t[i];
if (t[i] > 0) {
res.push_back(t[i]);
nonzero1.push_back(s1[p]);
}
p++;
}
f(nonzero1, h1, res);
q.clear();
for (auto i : h2) {
q.push_back(i);
}
vector<int> res2, nonzero2;
for (int i = 0; i < ans.size(); i++) {
if (ans[i] > 0) {
res2.push_back(ans[i]);
nonzero2.push_back(s1[i]);
}
}
f(nonzero2, h2, res2);
return;
}
void solve(int TC) {
cin >> n;
asked = 0;
for (int i = 1; i <= n; i++) {
v.push_back(i);
}
while (v.size() > 1) {
auto ans = ask(v);
vector<int> v2, s;
for (int i = 0; i < v.size(); i++) {
if (ans[i] == 0) s.push_back(v[i]);
else v2.push_back(v[i]);
}
v = v2;
IS.push_back(s);
}
if (v.size() == 1) {
IS.push_back(v);
v.clear();
}
for (int i = 0; i < IS.size(); i++) {
for (int j = i + 1; j < IS.size(); j++) {
// cout << "start IS=";
// for (auto k : IS[i]) cout << k << " ";
// cout << " and IS=";
// for (auto k : IS[j]) cout << k << " ";
// cout << endl;
vector<int> ij;
for (auto k : IS[i]) ij.push_back(k);
for (auto k : IS[j]) ij.push_back(k);
auto t = ask(ij);
vector<int> ans;
for (int k = IS[j].size(); k < IS[i].size() + IS[j].size(); k++) {
ans.push_back(t[k]);
}
vector<int> i2, ans2;
for (int k = 0; k < ans.size(); k++) {
if (ans[k] > 0) {
ans2.push_back(ans[k]);
i2.push_back(IS[i][k]);
}
}
f(i2, IS[j], ans2);
}
}
for (int i = 1; i <= n; i++) {
vector<int> tmp;
tmp.push_back(i);
tmp.push_back(i);
auto ans = ask(tmp);
int num = ans[1];
for (int j = 1; j <= num; j++) {
edge[i].push_back(i);
}
}
int total = 0;
for (int i = 1; i <= n; i++) {
total += edge[i].size();
}
cout << "! " << total;
for (int i = 1; i <= n; i++) {
for (auto j : edge[i]) {
cout << " " << i << " " << j;
}
}
cout << "\n";
cout.flush();
return;
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
cout << fixed << setprecision(10);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
solve(i);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3620kb
input:
4 0 2 1 0 0 0 0 0 2 1 0 2 0 0 0 0 0 0 0 0 1
output:
? 4 1 2 3 4 ? 2 2 3 ? 4 1 4 2 3 ? 3 2 1 4 ? 2 1 1 ? 2 2 2 ? 2 3 3 ? 2 4 4 ! 4 1 2 1 2 4 3 4 4
result:
wrong answer Wrong graph