Submission #1440980


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;

int n, a[100010], xx[100010], chk[100010];
vector<vector<pii>> ans;

void swp(int c, int x, int y){
	ans[c].push_back(pii(x, y));
}

void f(deque<int> &dq){
	int sz = dq.size();
	if(sz == 1) return;
	ans.push_back(vector<pii>());
	if(sz == 2){
		swp(0, dq[0], dq[1]);
		return;
	}
	ans.push_back(vector<pii>());
	if(sz & 1){
		swp(0, dq.front(), dq.back());
		dq.pop_front();
		sz--;
	}
	while(sz > 2){
		swp(0, dq.front(), dq[sz - 2]);
		swp(1, dq.front(), dq.back());
		dq.pop_front();
		dq.pop_back();
		sz -= 2;
	}
	swp(1, dq.front(), dq.back());
}

int main(){
	scanf("%d", &n);
	for(int i = 1; i <= n; i++){
		scanf("%d", a + i);
		xx[i] = a[i];
	}
	sort(xx + 1, xx + n + 1);
	for(int i = 1; i <= n; i++){
		a[i] = int(lower_bound(xx + 1, xx + n + 1, a[i]) - xx);
	}
	for(int i = 1; i <= n; i++){
		if(chk[i]) continue;
		deque<int> dq;
		for(int t = i; !chk[t]; t = a[t]){
			chk[t] = 1;
			dq.push_back(t);
		}
		f(dq);
	}
	printf("%d\n", ans.size());
	for(auto &v : ans){
		printf("%d ", v.size());
		for(int i = 0; i < int(v.size()) - 1; i++){
			printf("%d %d ", v[i].first, v[i].second);
		}
		printf("%d %d\n", v.back().first, v.back().second);
	}
}

Submission Info

Submission Time
Task D - Distributed Sorting
User kdh9949
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1299 Byte
Status RE
Exec Time 141 ms
Memory 6828 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:55:27: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<std::vector<std::pair<int, int> > >::size_type {aka long unsigned int}’ [-Wformat=]
  printf("%d\n", ans.size());
                           ^
./Main.cpp:57:25: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘std::vector<std::pair<int, int> >::size_type {aka long unsigned int}’ [-Wformat=]
   printf("%d ", v.size());
                         ^
./Main.cpp:37:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:39:21: 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
AC × 2
RE × 1
AC × 13
RE × 18
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 AC 38 ms 3844 KB
hand_07.txt RE 136 ms 4020 KB
hand_08.txt RE 128 ms 4020 KB
random_01.txt RE 141 ms 3676 KB
random_02.txt RE 141 ms 3804 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt AC 1 ms 256 KB
sample-03.txt RE 96 ms 256 KB
sorted_01.txt AC 33 ms 1408 KB
three_01.txt AC 25 ms 1408 KB
three_02.txt RE 120 ms 1408 KB
three_03.txt RE 128 ms 2356 KB
three_04.txt RE 141 ms 6828 KB
three_05.txt RE 141 ms 5292 KB
trans_01.txt AC 30 ms 1408 KB
trans_02.txt RE 122 ms 1408 KB
trans_03.txt RE 122 ms 1408 KB
trans_04.txt RE 122 ms 1408 KB
trans_05.txt RE 130 ms 2048 KB
trans_06.txt RE 140 ms 4020 KB
two_01.txt RE 139 ms 3448 KB
two_02.txt RE 139 ms 3700 KB
two_03.txt RE 140 ms 3580 KB