QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#472539 | #6414. Classical Maximization Problem | UESTC_xxx# | WA | 110ms | 8036kb | C++20 | 1.9kb | 2024-07-11 17:03:06 | 2024-07-11 17:03:06 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#include<map>
#define ll long long
#define lowbit(x) x&(-x)
using namespace std;
struct node{
int x,y,d,id;
}p[500005];
map<ll,ll>mp;
vector<int>e[500005];
int a[500005],n,tt,g[500005],cx[50005],cy[50005];
bool use[500005];
bool cmp(int ca,int cb){
return p[ca].d<p[cb].d;
}
bool cmp2(node a,node b){
return a.d<b.d;
}
int main(){
scanf("%d",&tt);
while(tt--){
scanf("%d",&n);
int tot=0;
for(int i=1;i<=2*n;++i){
p[i].id=i;
scanf("%d%d",&p[i].x,&p[i].y);
if(!mp[p[i].x]) tot++,mp[p[i].x]=tot;
if(!mp[p[i].y+1e10]) tot++,mp[p[i].y+1e10]=tot;
e[mp[p[i].x]].push_back(i);
e[mp[p[i].y+1e10]].push_back(i);
}
for(int i=1;i<=2*n;++i){
p[i].d=e[mp[p[i].x]].size()+e[mp[p[i].y+1e10]].size();
}
for(int i=1;i<=tot;++i){
for(int j=0;j<e[i].size();++j) a[j+1]=e[i][j];
sort(a+1,a+e[i].size()+1,cmp);
for(int j=0;j<e[i].size();++j) e[i][j]=a[j+1];
}
sort(p+1,p+n+1,cmp2);
int cnt=0;
for(int i=1;i<=2*n;++i){
if(use[i]) continue;
int u=mp[p[i].x],v=mp[p[i].y+1e10],p1=0,p2=0;
for(int j=g[u];j<e[u].size();++j){
g[u]=j;
int k=e[u][j];
if(use[k]||k==i) continue;
p1=k;
break;
}
for(int j=g[v];j<e[v].size();++j){
g[v]=j;
int k=e[v][j];
if(use[k]||k==i) continue;
p2=k;
break;
}
if(p1==0&&p2==0) continue;
cnt++;
if(!p1) p1=p2;
else if(p1&&p2) p1=(p[p1].d<=p[p2].d? p1 :p2);
cx[cnt]=p[i].id,cy[cnt]=p[p1].id;
use[p1]=1,use[i]=1;
}
printf("%d\n",cnt);
int ls=0;
for(int i=1;i<=2*n;++i){
if(!use[i]){
if(!ls) ls=i;
else{
cnt++;
cx[cnt]=p[ls].id,cy[cnt]=p[i].id;
ls=0;
}
}
use[i]=0;
}
for(int i=1;i<=n;++i) printf("%d %d\n",cx[i],cy[i]);
mp.clear();
for(int i=1;i<=tot;++i) e[i].clear();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7976kb
input:
3 2 0 0 0 1 1 0 1 1 2 0 0 0 1 0 2 0 3 2 0 0 1 1 2 2 3 3
output:
2 1 2 3 4 2 1 2 3 4 0 1 2 3 4
result:
ok ok (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 110ms
memory: 8036kb
input:
10000 2 -107276936 -310501829 419434212 585811870 -65754386 -491212232 381152038 897148193 3 -474045168 493506332 299114415 540203303 165808153 983551 -506936261 -694189769 766718170 -725540031 975267148 -593051087 1 -818952276 -762387923 584023914 -612401389 6 -77701228 -266484128 659434465 6322062...
output:
0 1 2 3 4 0 1 2 3 4 5 6 0 1 2 0 1 2 3 4 5 6 7 8 9 10 11 12 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 0 1 2 16 26 9 18 1 19 16 20 15 21 14 22 13 23 12 24 11 25 10 17 33 27 8 28 7 29 6 30 5 31 4 32 3 2 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 0 1 2 3 ...
result:
wrong answer wrong number of friendly pairs: printed 16, but it is actually 0 (test case 7)