Submission #1529430
Source Code Expand
#include<bits/stdc++.h> using namespace std; #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--) #define REP(i,n) for (int i=0;i<(n);i++) #define RREP(i,n) for (int i=(n)-1;i>=0;i--) typedef long long LL; int N; LL X[100001]; bool used[100001]; map<LL,int> m; typedef pair<int,int>P; vector<P>v; vector<P>v2; vector<LL>vv; LL Y[100001]; void dfs(LL x,int c){ //cout<<x<<"xxx"<<endl; used[x]=true; //正しい場所にいる if(X[x]==x){ return; } LL y=Y[x];//交換先(xの値を持っている人) if(c==0){ v.push_back(P{x+1,y+1}); X[y]=X[x]; }else{ v2.push_back(P{x+1,y+1}); X[y]=X[x]; } //cout<<"dfs"<<endl; dfs(y,1-c); } int main(){ int N; cin>>N; REP(i,N){ cin>>X[i]; vv.push_back(X[i]); } sort(vv.begin(),vv.end()); REP(i,N){ m[vv[i]]=i; //cout<<vv[i]<<" "<<m[vv[i]]<<endl; } REP(i,N){ X[i]=m[X[i]]; //cout<<"m"<<X[i]<<" "<<m[X[i]]<<endl; } REP(i,N){ Y[X[i]]=i; } REP(i,N){ used[i]=false; } REP(i,N){ if(used[i]==false){ //cout<<m[X[i]]<<endl; dfs(i,0); } } if(v.size()==0){ cout<<0<<endl; }else if(v2.size()==0){ cout<<1<<endl; cout<<v.size()<<" "; REP(i,v.size()){ cout<<v[i].first<<" "<<v[i].second; if(i==v.size()-1){ cout<<endl; }else{ cout<<" "; } } }else{ cout<<2<<endl; cout<<v.size()<<" "; REP(i,v.size()){ cout<<v[i].first<<" "<<v[i].second; if(i==v.size()-1){ cout<<endl; }else{ cout<<" "; } } cout<<v2.size()<<" "; REP(i,v2.size()){ cout<<v2[i].first<<" "<<v2[i].second; if(i==v2.size()-1){ cout<<endl; }else{ cout<<" "; } } } return(0); }
Submission Info
Submission Time | |
---|---|
Task | D - Distributed Sorting |
User | rapurasu |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2127 Byte |
Status | WA |
Exec Time | 148 ms |
Memory | 15988 KB |
Judge Result
Set Name | sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 100 | ||||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt, sample-03.txt |
All | sample-01.txt, sample-02.txt, sample-03.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, random_01.txt, random_02.txt, sample-01.txt, sample-02.txt, sample-03.txt, sorted_01.txt, three_01.txt, three_02.txt, three_03.txt, three_04.txt, three_05.txt, trans_01.txt, trans_02.txt, trans_03.txt, trans_04.txt, trans_05.txt, trans_06.txt, two_01.txt, two_02.txt, two_03.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
hand_01.txt | AC | 1 ms | 256 KB |
hand_02.txt | AC | 1 ms | 256 KB |
hand_03.txt | AC | 1 ms | 256 KB |
hand_04.txt | AC | 1 ms | 256 KB |
hand_05.txt | WA | 1 ms | 256 KB |
hand_06.txt | WA | 109 ms | 15988 KB |
hand_07.txt | AC | 91 ms | 10356 KB |
hand_08.txt | AC | 91 ms | 10356 KB |
random_01.txt | WA | 143 ms | 14964 KB |
random_02.txt | WA | 148 ms | 15988 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |
sample-03.txt | AC | 1 ms | 256 KB |
sorted_01.txt | AC | 81 ms | 8948 KB |
three_01.txt | AC | 80 ms | 8948 KB |
three_02.txt | AC | 81 ms | 8948 KB |
three_03.txt | AC | 95 ms | 9460 KB |
three_04.txt | AC | 121 ms | 10868 KB |
three_05.txt | AC | 124 ms | 10868 KB |
trans_01.txt | AC | 80 ms | 8948 KB |
trans_02.txt | AC | 81 ms | 8948 KB |
trans_03.txt | AC | 81 ms | 8948 KB |
trans_04.txt | AC | 82 ms | 8948 KB |
trans_05.txt | AC | 91 ms | 9204 KB |
trans_06.txt | AC | 119 ms | 10356 KB |
two_01.txt | WA | 129 ms | 12916 KB |
two_02.txt | WA | 129 ms | 14196 KB |
two_03.txt | WA | 130 ms | 12788 KB |