Submission #3100202
Source Code Expand
#include <stdio.h> #include <stdlib.h> int N, *p, ans[100000], l = 0; void swaps(int k){ int i, tmp; for(i = k; i < N; i++){ tmp = p[i]; p[i] = p[i - k]; p[i - k] = tmp; } ans[l] = k; l++; } void out(){ int i; printf("p:"); for(i = 0; i < N; i++){ printf("%d ", p[i]); } printf("\n"); } int main(){ int i; scanf("%d", &N); p = (int *)malloc(sizeof(int) * N); for(i = 0; i < N; i++){ scanf("%d", &p[i]); // p[i] = (N / 2 - i + N) % N; } for(i = N - 2; i >= 0; i--){ // printf("i = %d\n", i); while(p[0] != i){ swaps(1); // out(); } while(p[1] != i + 1){ swaps(1); swaps(N - 1); // out(); } } // out(); printf("%d\n", l); for(i = 0; i < l; i++){ printf("%d\n", ans[i]); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | B - Many Swaps Sorting |
User | abc050 |
Language | C (GCC 5.4.1) |
Score | 900 |
Code Size | 792 Byte |
Status | AC |
Exec Time | 18 ms |
Memory | 512 KB |
Compile Error
./Main.c: In function ‘main’: ./Main.c:28:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &N); ^ ./Main.c:31:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &p[i]); ^
Judge Result
Set Name | Sample | Subtask1 | Subtask2 | All | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 400 / 400 | 200 / 200 | ||||||||
Status |
|
|
|
|
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 | 128 KB |
00_example_02.txt | AC | 1 ms | 128 KB |
s1_01.txt | AC | 1 ms | 128 KB |
s1_02.txt | AC | 1 ms | 128 KB |
s1_03.txt | AC | 1 ms | 128 KB |
s1_04.txt | AC | 1 ms | 128 KB |
s1_05.txt | AC | 1 ms | 128 KB |
s1_06.txt | AC | 1 ms | 128 KB |
s2_07.txt | AC | 1 ms | 128 KB |
s2_08.txt | AC | 1 ms | 128 KB |
s2_09.txt | AC | 1 ms | 128 KB |
s2_10.txt | AC | 1 ms | 128 KB |
s2_11.txt | AC | 1 ms | 128 KB |
s3_12.txt | AC | 3 ms | 256 KB |
s3_13.txt | AC | 7 ms | 384 KB |
s3_14.txt | AC | 2 ms | 256 KB |
s3_15.txt | AC | 2 ms | 256 KB |
s3_16.txt | AC | 18 ms | 512 KB |
s3_17.txt | AC | 17 ms | 512 KB |
s3_18.txt | AC | 17 ms | 512 KB |
s3_19.txt | AC | 18 ms | 512 KB |
s3_20.txt | AC | 16 ms | 384 KB |