Submission #2923741
Source Code Expand
#include <iostream> #include <algorithm> #include <vector> #include <set> #include <map> #include <queue> #include <stack> #include <cstdio> #include <cstring> #include <math.h> #include <string> using namespace std; typedef long long ll; typedef double D; typedef pair<ll,ll> P; #define INF 100000000000 #define M 1000000007 #define F first #define S second #define PB push_back vector<P>ans; int n,a[55]; void up(int x,int y){ ans.PB(P(x,y)); swap(a[x],a[y]); } void solve(void){ for(int i=1;i<=n;i++){ if(a[i]==1){ for(int j=i-1;j>=1;j--){ up(j+1,j); } break; } } for(int i=1;i<=n;i++){ if(a[i]==2){ if(i%2){ for(int j=i-2;j>=1;j-=2){ up(j+2,j); } up(2,3); }else{ for(int j=i-2;j>=1;j-=2){ up(j+2,j); } up(1,2); } break; } } for(int i=1;i<n;i++){ if(a[i]==n){ for(int j=3;j<i;j++){ up(j-2,j); up(j-1,j); } for(int j=i+1;j<=n;j++){ up(j-3,j-2); up(j,j-2); up(j-3,j-2); up(j-2,j-1); up(j,j-2); } break; } } } int main(void){ cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; for(;n>3;n--){ solve(); } if(n==3){ if(a[3]==1){ up(2,3); } if(a[1]==1){ up(1,2); } if(a[1]==3){ up(1,3); } } if(a[2]==1){ up(1,2); } cout<<ans.size()<<endl; for(int i=0;i<ans.size();i++){ cout<<ans[i].F<<' '<<ans[i].S<<endl; } }
Submission Info
Submission Time | |
---|---|
Task | I - そーっとソート |
User | nxteru |
Language | C++14 (GCC 5.4.1) |
Score | 100 |
Code Size | 1924 Byte |
Status | AC |
Exec Time | 13 ms |
Memory | 512 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 100 / 100 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example_0.txt |
All | backet_0.txt, backet_1.txt, backet_2.txt, backet_3.txt, backet_4.txt, corner_0.txt, corner_1.txt, corner_2.txt, example_0.txt, maxrand_0.txt, maxrand_1.txt, maxrand_2.txt, random_0.txt, random_1.txt, random_2.txt, random_3.txt, random_4.txt, shortswap_0.txt, shortswap_1.txt, shortswap_rev_0.txt, shortswap_rev_1.txt, smallrand_0.txt, smallrand_1.txt, smallrand_2.txt, smallrand_3.txt, smallrand_4.txt, example_0.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
backet_0.txt | AC | 8 ms | 512 KB |
backet_1.txt | AC | 8 ms | 512 KB |
backet_2.txt | AC | 2 ms | 256 KB |
backet_3.txt | AC | 4 ms | 256 KB |
backet_4.txt | AC | 6 ms | 384 KB |
corner_0.txt | AC | 1 ms | 256 KB |
corner_1.txt | AC | 1 ms | 256 KB |
corner_2.txt | AC | 13 ms | 512 KB |
example_0.txt | AC | 1 ms | 256 KB |
maxrand_0.txt | AC | 10 ms | 512 KB |
maxrand_1.txt | AC | 10 ms | 512 KB |
maxrand_2.txt | AC | 10 ms | 512 KB |
random_0.txt | AC | 3 ms | 256 KB |
random_1.txt | AC | 10 ms | 512 KB |
random_2.txt | AC | 1 ms | 256 KB |
random_3.txt | AC | 4 ms | 256 KB |
random_4.txt | AC | 7 ms | 384 KB |
shortswap_0.txt | AC | 8 ms | 512 KB |
shortswap_1.txt | AC | 8 ms | 512 KB |
shortswap_rev_0.txt | AC | 13 ms | 512 KB |
shortswap_rev_1.txt | AC | 12 ms | 512 KB |
smallrand_0.txt | AC | 1 ms | 256 KB |
smallrand_1.txt | AC | 1 ms | 256 KB |
smallrand_2.txt | AC | 1 ms | 256 KB |
smallrand_3.txt | AC | 1 ms | 256 KB |
smallrand_4.txt | AC | 1 ms | 256 KB |