QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#583279 | #6414. Classical Maximization Problem | huaxiamengjin# | WA | 147ms | 18256kb | C++14 | 1.4kb | 2024-09-22 19:22:49 | 2024-09-22 19:22:51 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,tot;
int ct[200100],ct2[200100];
vector<int>g1[200100],g2[200100];
int a[400200];
int x[200100],y[200100];
vector<int>s;
priority_queue<pair<int,int>>q;
int used[200100];
void solve(){
cin>>n;tot=0;n*=2;
for (int i=1;i<=n;i++)
cin>>x[i]>>y[i],a[++tot]=x[i],a[++tot]=y[i],used[i]=0;
sort(a+1,a+tot+1);
tot=unique(a+1,a+tot+1)-a-1;
for (int i=1;i<=tot;i++)
g1[i].clear(),g2[i].clear(),ct[i]=ct2[i]=0;
for (int i=1;i<=n;i++)
x[i]=lower_bound(a+1,a+tot+1,x[i])-a,
y[i]=lower_bound(a+1,a+tot+1,y[i])-a;
for (int i=1;i<=n;i++)
g1[x[i]].push_back(i),g2[y[i]].push_back(i),
s.push_back(i),ct[x[i]]++,ct2[y[i]]++;
for (int i=1;i<=n;i++)
q.push({-(ct[x[i]]+ct[y[i]]),i});
int zong=0;
vector<pair<int,int> >ans;
while(q.size()){
int i=q.top().second;
q.pop();
if(used[i]==1)continue;
bool fl=1;used[i]=1;
while(g1[x[i]].size()&&used[g1[x[i]].back()]==1)g1[x[i]].pop_back();
if(g1[x[i]].size()){ans.push_back({i,g1[x[i]].back()}),zong++;used[g1[x[i]].back()]=1;continue;}
while(g2[x[i]].size()&&used[g2[x[i]].back()]==1)g2[x[i]].pop_back();
if(g2[x[i]].size()){ans.push_back({i,g2[x[i]].back()}),zong++;used[g2[x[i]].back()]=1;continue;}
while(used[s.back()]==1)s.pop_back();
ans.push_back({i,s.back()});used[s.back()]=1;
}
cout<<zong<<"\n";
for (auto i:ans)cout<<i.first<<" "<<i.second<<"\n";
}
int main(){
int T;cin>>T;
while(T--)solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 15896kb
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 4 3 2 1 2 4 3 2 1 0 4 3 2 1
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 147ms
memory: 18256kb
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 4 3 2 1 0 6 5 4 3 2 1 0 2 1 0 12 11 10 9 8 7 6 5 4 3 2 1 0 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 2 1 0 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 6 5 4 3...
result:
ok ok (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 138ms
memory: 16412kb
input:
10000 1 999855386 999580905 999342928 999615227 21 999601032 999015398 999155628 999176944 999309856 999524434 999121011 999509537 999323572 999685730 999272272 999769606 999450559 999390758 999632027 999178534 999024993 999463838 999784856 999374197 999980525 999366771 999241260 999516879 999599548...
output:
0 2 1 0 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 28 27 26 25 2...
result:
wrong answer wrong number of friendly pairs: printed 1, but it is actually 0 (test case 634)