QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#317841 | #6414. Classical Maximization Problem | Endline | WA | 67ms | 11984kb | C++14 | 2.7kb | 2024-01-29 20:18:07 | 2024-01-29 20:18:08 |
Judging History
answer
/*
* Author: Endline
* Time: 2024/01/29 19:51:47
* File: Graph-B.cpp
*/
#include<bits/stdc++.h>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
using ll=long long;
const int MAXN=400002;
const int mod=998244353;
template<typename _Tp>inline void Add(_Tp&x,ll y){x=x+y>=mod?x+y-mod:x+y;}
template<typename _Tp>inline void Mul(_Tp&x,ll y){x=x*y>=mod?x*y%mod:x*y;}
int T,n,len,ecnt,acnt;
bool used[MAXN];
int pos[MAXN],head[MAXN],vis[MAXN];
pair<int,int>a[MAXN],ans[MAXN];
struct edge
{
int v,id,nxt;
}e[MAXN<<1];
inline void addedge(int u,int v,int id)
{
e[++ecnt]={v,id,head[u]};
head[u]=ecnt;
}
void dfs(int u,int pre)
{
vis[u]=1;
vector<int>bck,son;
for(int i=head[u];i;i=e[i].nxt)
{
int v=e[i].v;
if(e[i].id==pre)continue;
if(vis[v]==1)bck.push_back(e[i].id);
else if(vis[v]!=2)
{
dfs(v,e[i].id);
if(!used[e[i].id])son.push_back(e[i].id);
}
}
while(son.size()>=2)
{
ans[++acnt]={son[son.size()-1],son[son.size()-2]};
used[ans[acnt].first]=used[ans[acnt].second]=true;
son.pop_back(),son.pop_back();
}
while(bck.size()>=2)
{
ans[++acnt]={bck[bck.size()-1],bck[bck.size()-2]};
used[ans[acnt].first]=used[ans[acnt].second]=true;
bck.pop_back(),bck.pop_back();
}
if(son.size()&&bck.size())
{
ans[++acnt]={son.back(),bck.back()};
used[ans[acnt].first]=used[ans[acnt].second]=true;
son.pop_back(),bck.pop_back();
}
if(son.size()&&pre)ans[++acnt]={pre,son.back()},used[ans[acnt].first]=used[ans[acnt].second]=true;
if(bck.size()&&pre)ans[++acnt]={pre,bck.back()},used[ans[acnt].first]=used[ans[acnt].second]=true;
vis[u]=2;
}
inline void solve()
{
cin>>n;acnt=ecnt=0;
for(int i=1;i<=n*2;i++)
{
cin>>a[i].first>>a[i].second;
tie(pos[i*2-1],pos[i*2])=a[i];
}
sort(pos+1,pos+n*4+1);
len=unique(pos+1,pos+n*4+1)-pos-1;
for(int i=1;i<=len;i++)head[i]=0;
for(int i=1;i<=n*2;i++)
{
int p1=lower_bound(pos+1,pos+len+1,a[i].first)-pos,p2=lower_bound(pos+1,pos+len+1,a[i].second)-pos;
addedge(p1,p2,i);
if(p1!=p2)addedge(p2,p1,i);
}
for(int i=1;i<=len;i++)vis[i]=0,used[i]=false;
for(int i=1;i<=len;i++)
if(!vis[i])dfs(i,0);
printf("%d\n",acnt);
for(int i=1;i<=acnt;i++)
printf("%d %d\n",ans[i].first,ans[i].second);
for(int i=1,opt=0;i<=n*2;i++)
if(!used[i])printf("%d",i),printf("%c"," \n"[opt]),opt^=1;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>T;
while(T--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 11984kb
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 2 4 3 1 2 2 3 4 1 0 1 2 3 4
result:
ok ok (3 test cases)
Test #2:
score: 0
Accepted
time: 67ms
memory: 10224kb
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 0 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 0 1 2 3 4...
result:
ok ok (10000 test cases)
Test #3:
score: -100
Wrong Answer
time: 67ms
memory: 11984kb
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 1 2 0 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 0 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 0 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 0 1 2 3 4 5 6 7...
result:
wrong answer wrong number of friendly pairs: printed 1, but it is actually 0 (test case 634)