QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#605617 | #7510. Independent Set | cjx | RE | 1ms | 5776kb | C++20 | 2.6kb | 2024-10-02 18:11:47 | 2024-10-02 18:11:48 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
long long read(){
long long x=0,f=1;char ch=getchar();
while(!isdigit(ch))
{if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;
}
void write(long long x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}
const int N=4010;
int n;
int edge[N][N],sum;
vector<int>a,b,ep;
ll cnt=0;
vector<int>ask(vector<int>e){
vector<int>g;
printf("? %d",e.size());
for(register auto x:e){
putchar(' ');write(x);cnt++;
}
puts("");
fflush(stdout);
g.clear();
for(register int i=0;i<e.size();i++){
g.push_back(read());
}
return g;
}
vector<int>ask2(vector<int>a,vector<int>b){
vector<int>c=a;
for(auto x:b)c.push_back(x);
vector<int>t=ask(c),d;d.clear();
for(int i=0;i<b.size();i++){
int x=t[i+a.size()];
for(int j=0;j<i;j++)
if(!t[j+a.size()])x-=edge[b[i]][b[j]];
d.push_back(x);
}
return d;
}
void solve2(vector<int>s1,vector<int>s2,vector<int>s3){
if(!s1.size()||!s2.size())return;
if(s1.size()==1){
for(int i=0;i<s2.size();i++){
edge[s1[0]][s2[i]]=edge[s2[i]][s1[0]]=s3[i];
}
return;
}
int mid=(s1.size()-1)/2;
vector<int>ls1,ls2,rs1,rs2,ls3,rs3,t;
for(int i=0;i<=mid;i++)
ls1.push_back(s1[i]);
for(int i=mid+1;i<s1.size();i++)
rs1.push_back(s1[i]);
t=ask2(ls1,s2);
for(int i=0;i<s2.size();i++){
if(t[i]>0)
ls2.push_back(s2[i]),ls3.push_back(t[i]);
if(t[i]<s3[s1.size()+i])
rs2.push_back(s2[i]),ls3.push_back(s3[i]-t[i]);
}
solve2(ls1,ls2,ls3);solve2(rs1,rs2,rs3);
}
void solve1(vector<int>s){
if(s.size()<=1)return;
vector<int>s1,s2;
vector<int>t=ask(s);s1.clear();s2.clear();
for(int i=0;i<s.size();i++){
if(!t[i])s1.push_back(s[i]);
else s2.push_back(s[i]);
}
solve1(s2);
solve2(s1,s2,ask2(s1,s2));
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
n=read();
for(register int i=1;i<=n;i++){
for(register int j=1;j<=n;j++){
edge[i][j]=-1;
}
}
for(register int i=1;i<=n;i++){
a.clear();a.push_back(i);
a.push_back(i);
b=ask(a);
edge[i][i]=b[1];
}
a.clear();
for(int i=1;i<=n;i++)a.push_back(i);
solve1(a);
for(register int i=1;i<=n;i++){
for(register int j=i;j<=n;j++){
if(edge[i][j]>0)sum+=edge[i][j];
}
}
printf("! %d",sum);
for(register int i=1;i<=n;i++){
for(register int j=i;j<=n;j++){
for(register int k=1;k<=edge[i][j];k++){
putchar(' ');write(i);
putchar(' ');write(j);
}
}
}
puts("");
fflush(stdout);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5776kb
input:
4 0 0 0 0 0 0 0 1 0 2 1 0 0 0 0 0 0 0 2 1 0 2 1
output:
? 2 1 1 ? 2 2 2 ? 2 3 3 ? 2 4 4 ? 4 1 2 3 4 ? 2 2 3 ? 2 2 3 ? 4 1 4 2 3 ? 3 1 2 3 ! 4 1 2 1 2 1 3 4 4
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 ? 2 30 30 ? 2 31 31 ? 2 32 3...