QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#300498#7510. Independent Setdefyers#TL 1ms3584kbC++143.9kb2024-01-08 13:07:212024-01-08 13:07:22

Judging History

你现在查看的是最新测评结果

  • [2024-01-08 13:07:22]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3584kb
  • [2024-01-08 13:07:21]
  • 提交

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;
vector<int> f(vector<int> &s1, vector<int> &s2) {
    // 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 E;
	vector<int> tmp;
	for (auto i : s2) {
		tmp.push_back(i);
	}
	for (auto i : s1) {
		tmp.push_back(i);
	}
	auto ans = ask(tmp);
	if (s2.size() == 1) {
        // cout << "  s2.size()== 1" << endl;
		for (int i = 0; i < s1.size(); i++) {
			int num = ans[i + 1];
			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 cnts;
	}
	int p = 0;
	vector<int> nonzero;
    vector<int> cnts;
	for (int i = s2.size(); i < s2.size() + s1.size(); i++) {
		int cnt = ans[i];
		int id = s1[p];
		if (cnt != 0) {
			nonzero.push_back(id);
		}
		cnts.push_back(cnt);
		p++;
	}
	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> cnts1;
    // cout << "nonzero: ";
    // for (auto i : nonzero) {
    //     cout << i << " ";
    // }
    // cout << endl;
	cnts1 = f(nonzero, h1);
	vector<int> nonzero2;
	int pp = 0;
	for (int i = 0; i < nonzero.size(); i++) {
        // cout << "at " << i << ", nonzero[i]=" << nonzero[i] << endl;
		while (s1[pp] != nonzero[i]) pp++;
        // cout << "pp=" << pp << ", s1[pp]=" << s1[pp] << ", cnts[pp]=" << cnts[pp] << endl;
		if (cnts[pp] != cnts1[i]) {
            // cout << cnts[pp] << " != " << cnts1[i] << ", pushback " << nonzero[i] << endl;
            nonzero2.push_back(nonzero[i]);
        }
	}
    // cout << "nonzero2: ";
    // for (auto i : nonzero2) {
    //     cout << i << " ";
    // }
    // cout << endl;
	f(nonzero2, h2);
    return cnts;
}

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++) {
			vector<int> cnt;
            // cout << "start IS=";
            // for (auto k : IS[i]) cout << k << " ";
            // cout << " and IS=";
            // for (auto k : IS[j]) cout << k << " ";
            // cout << endl;
			f(IS[i], IS[j]);
		}
	}
	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);
	}
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3584kb

input:

4
0 2 1 0
0 0
0 0 3 0
0 2
0 1
0 0
0 0
0 0
0 1

output:

? 4 1 2 3 4
? 2 2 3
? 4 2 3 1 4
? 2 2 1
? 2 3 1
? 2 1 1
? 2 2 2
? 2 3 3
? 2 4 4
! 4 1 2 1 2 1 3 4 4

result:

ok Ok, Accepted!

Test #2:

score: -100
Time Limit Exceeded

input:

4000
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 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 1 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 2 1 0 1 0 0 0 0 1 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 1 0 0 0...

output:

? 4000 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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...

result: