Submission #2901907


Source Code Expand

#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define revv(V) reverse(allv(V))
#define sz(V) ((int)(V).size())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define rb(x) ((x)&(-(x)))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 205;

int A[MAXN];

vector<int> Ans;

int N;

int main() {
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];
	
	for(int t = 0; t <= N; t++) {
		vector<int> V;
		for(int i = 2; i <= N; i++) {
			if(A[i-1] > A[i]) {
				swap(A[i-1], A[i]);
				V.eb(i-1);
			}
		}
		if(V.empty()) break;

		for(int t = 0; t < V[0]; t++) Ans.eb(1);
		Ans.eb(N-1);
		for(int i = 1; i < sz(V); i++) {
			for(int t = 0; t < V[i]-V[i-1]; t++) Ans.eb(1);
			Ans.eb(N-1);
		}
		for(int t = 0; t < N-V.back(); t++) Ans.eb(1);
	}

	printf("%d\n", sz(Ans));
	for(int v : Ans) printf("%d\n", v);
	return 0;
}

Submission Info

Submission Time
Task B - Many Swaps Sorting
User youngyojun
Language C++14 (GCC 5.4.1)
Score 900
Code Size 1175 Byte
Status AC
Exec Time 6 ms
Memory 760 KB

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 300 / 300 400 / 400 200 / 200
Status
AC × 2
AC × 7
AC × 13
AC × 22
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt
Subtask1 00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt
Subtask2 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s2_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt
All 00_example_01.txt, 00_example_02.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s2_07.txt, s2_08.txt, s2_09.txt, s2_10.txt, s2_11.txt, s3_12.txt, s3_13.txt, s3_14.txt, s3_15.txt, s3_16.txt, s3_17.txt, s3_18.txt, s3_19.txt, s3_20.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 1 ms 256 KB
00_example_02.txt AC 1 ms 256 KB
s1_01.txt AC 1 ms 256 KB
s1_02.txt AC 1 ms 256 KB
s1_03.txt AC 1 ms 256 KB
s1_04.txt AC 1 ms 256 KB
s1_05.txt AC 1 ms 256 KB
s1_06.txt AC 1 ms 256 KB
s2_07.txt AC 1 ms 256 KB
s2_08.txt AC 1 ms 256 KB
s2_09.txt AC 1 ms 256 KB
s2_10.txt AC 1 ms 256 KB
s2_11.txt AC 1 ms 256 KB
s3_12.txt AC 2 ms 384 KB
s3_13.txt AC 3 ms 512 KB
s3_14.txt AC 2 ms 384 KB
s3_15.txt AC 2 ms 384 KB
s3_16.txt AC 6 ms 760 KB
s3_17.txt AC 5 ms 636 KB
s3_18.txt AC 5 ms 636 KB
s3_19.txt AC 6 ms 760 KB
s3_20.txt AC 1 ms 256 KB