Task: | Järjestys |
Sender: | vuolen |
Submission time: | 2016-10-11 21:45:10 +0300 |
Language: | C++ |
Status: | READY |
Result: | 0 |
group | verdict | score |
---|---|---|
#1 | WRONG ANSWER | 0 |
#2 | WRONG ANSWER | 0 |
#3 | TIME LIMIT EXCEEDED | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | WRONG ANSWER | 0.06 s | 1 | details |
#2 | WRONG ANSWER | 0.05 s | 2 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Compiler report
input/code.cpp: In function 'int main(int, char**)': input/code.cpp:45:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%" SCNu32, &n); ^ input/code.cpp:59:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result] scanf("%" SCNu32, arr + i); ^ input/code.cpp:81:30: warning: 'max_i' may be used uninitialized in this function [-Wmaybe-uninitialized] move_arr[move_n++] = max_i + i; ^
Code
#include <stdio.h> #include <stdint.h> #define __STDC_FORMAT_MACROS #include <inttypes.h> #include <stdlib.h> #include <math.h> void shuffle(uint32_t *array, uint32_t n) { uint32_t i; for (i = 0; i < n - 1; i++) { uint32_t j = i + rand() / (RAND_MAX / (n - i) + 1); int t = array[j]; array[j] = array[i]; array[i] = t; } } void flip(uint32_t *arr, uint32_t n) { uint32_t i; uint32_t j; uint32_t temp; for (i = 0, j = n; i < j; i++, j--) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } void print_arr(uint32_t *arr, uint32_t n) { uint32_t i; for (i = 0; i < n; i++) { printf("%" PRIu32 " ", arr[i]); } printf("\n"); } int main(int argc, char *argv[]) { uint32_t n; uint32_t *arr; uint32_t move_n; uint32_t *move_arr; scanf("%" SCNu32, &n); arr = (uint32_t *) calloc(n, sizeof(uint32_t)); move_n = 0; move_arr = (uint32_t *) calloc(5 * n, sizeof(uint32_t)); // uint32_t i; // for (i = 0; i < n; i++) { // arr[i] = i; // } // shuffle(arr, n); // print_arr(arr, n); uint32_t i; for (i = 0; i < n; i++) { scanf("%" SCNu32, arr + i); } uint32_t sorted = 0; uint32_t max = 0; uint32_t max_i; uint32_t j; for (j = 0; j < n; j++) { if (arr[j] > max && arr[j] != j + 1) { max = arr[j]; max_i = j; } } for (i = 0; i < 5 * n; i++) { for (j = 0; j < n - sorted; j++) { if (arr[j] == max) max_i = j; } if (max == 0) break; move_arr[move_n++] = max_i + i; flip(arr, max_i + 1); move_arr[move_n++] = max_i + i; flip(arr, arr[0]); sorted++; max--; } printf("%" PRIu32 "\n", move_n); print_arr(move_arr, move_n); free(arr); free(move_arr); return 0; }
Test details
Test 1
Group: 1
Verdict: WRONG ANSWER
input |
---|
10 9 3 4 7 6 5 10 2 8 1 |
correct output |
---|
32 10 10 9 10 9 8 7 9 4 2 1 4 5 2... |
user output |
---|
20 6 6 8 8 9 9 7 7 6 6 7 7 8 8 9 ... |
Test 2
Group: 2
Verdict: WRONG ANSWER
input |
---|
1000 650 716 982 41 133 1000 876 92... |
correct output |
---|
3984 207 207 206 207 128 127 126 12... |
user output |
---|
2000 5 5 781 781 483 483 704 704 46... |
Test 3
Group: 3
Verdict: TIME LIMIT EXCEEDED
input |
---|
100000 94703 47808 62366 31885 7091 8... |
correct output |
---|
399956 98676 98676 98675 98676 62994 ... |
user output |
---|
(empty) |