Submission #1440942
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N];
bool vis[N];
vector<vector<int> > ans;
vector<int> cp;
bool solve () {
bool f = false;
for(int i=1;i<=n;i++) if(a[i] != i) f = true;
if(!f) return false;
fill(vis+1, vis+1+n, 0);
vector<int> st, ca;
for(int i=1;i<=n;i++) {
for(int j=i;!vis[j];j=a[j]) {
st.push_back(j); vis[j] = true;
}
for(int i=0;i+1<st.size();i+=2) {
ca.push_back(st[i]);
ca.push_back(st[i+1]);
swap(a[st[i]], a[st[i+1]]);
}
st.clear();
}
ans.push_back(ca);
return true;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) {
scanf("%d",&a[i]);
cp.push_back(a[i]);
}
sort(cp.begin(), cp.end());
for(int i=1;i<=n;i++) {
a[i] = lower_bound(cp.begin(), cp.end(), a[i]) - cp.begin() + 1;
}
while(solve());
printf("%d\n",ans.size());
for(int i=0;i<ans.size();i++) {
printf("%d ",ans[i].size()/2);
for(int j=0;j+1<ans[i].size();j++) {
printf("%d ",ans[i][j]);
}
printf("%d\n",ans[i].back());
}
}
Submission Info
Submission Time
2017-07-21 11:12:35+0900
Task
D - Distributed Sorting
User
khsoo01
Language
C++14 (GCC 5.4.1)
Score
0
Code Size
1054 Byte
Status
WA
Exec Time
57 ms
Memory
3440 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:44:26: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<std::vector<int> >::size_type {aka long unsigned int}’ [-Wformat=]
printf("%d\n",ans.size());
^
./Main.cpp:46:31: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<int>::size_type {aka long unsigned int}’ [-Wformat=]
printf("%d ",ans[i].size()/2);
^
./Main.cpp:34:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&n);
^
./Main.cpp:36:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&a[i]);
^
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
AC
1 ms
256 KB
hand_06.txt
WA
48 ms
3432 KB
hand_07.txt
AC
26 ms
2160 KB
hand_08.txt
AC
26 ms
2160 KB
random_01.txt
WA
57 ms
3396 KB
random_02.txt
WA
57 ms
3432 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
17 ms
1148 KB
three_01.txt
AC
18 ms
1272 KB
three_02.txt
AC
18 ms
1272 KB
three_03.txt
AC
26 ms
1656 KB
three_04.txt
AC
41 ms
2928 KB
three_05.txt
AC
41 ms
2928 KB
trans_01.txt
AC
18 ms
1272 KB
trans_02.txt
AC
18 ms
1272 KB
trans_03.txt
AC
18 ms
1272 KB
trans_04.txt
AC
18 ms
1272 KB
trans_05.txt
AC
22 ms
1400 KB
trans_06.txt
AC
37 ms
2288 KB
two_01.txt
WA
55 ms
3312 KB
two_02.txt
WA
54 ms
3440 KB
two_03.txt
WA
54 ms
3440 KB