Task: | Järjestys |
Sender: | Shrike |
Submission time: | 2016-10-15 20:20:44 +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.05 s | 1 | details |
#2 | WRONG ANSWER | 0.06 s | 2 | details |
#3 | TIME LIMIT EXCEEDED | -- | 3 | details |
Compiler report
input/code.cpp: In function 'void insertionSort(int*, int)': input/code.cpp:67:12: warning: unused variable 'j' [-Wunused-variable] int i, j; ^ input/code.cpp: In function 'int main()': input/code.cpp:125:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] for (i = 0; i < moves.size(); i++) ^
Code
#include <iostream> #include <string> #include <vector> #include <sstream> #include <cstdlib> using namespace std; vector<int> moves; int ceilSearch(int arr[], int low, int high, int x) { int mid; /* If x is smaller than or equal to the first element, then return the first element */ if(x <= arr[low]) return low; /* If x is greater than the last element, then return -1 */ if(x > arr[high]) return -1; /* get the index of middle element of arr[low..high]*/ mid = (low + high)/2; /* low + (high – low)/2 */ /* If x is same as middle element, then return mid */ if(arr[mid] == x) return mid; /* If x is greater than arr[mid], then either arr[mid + 1] is ceiling of x, or ceiling lies in arr[mid+1...high] */ if(arr[mid] < x) { if(mid + 1 <= high && x <= arr[mid+1]) return mid + 1; else return ceilSearch(arr, mid+1, high, x); } /* If x is smaller than arr[mid], then either arr[mid] is ceiling of x or ceiling lies in arr[mid-1...high] */ if (mid - 1 >= low && x > arr[mid-1]) return mid; else return ceilSearch(arr, low, mid - 1, x); } /* Reverses arr[0..i] */ void flip(int arr[], int i) { moves.push_back(i+1); int temp, start = 0; while (start < i) { temp = arr[start]; arr[start] = arr[i]; arr[i] = temp; start++; i--; } } /* Function to sort an array using insertion sort, binary search and flip */ void insertionSort(int arr[], int size) { int i, j; // Start from the second element and one by one insert arr[i] // in already sorted arr[0..i-1] for(i = 1; i < size; i++) { // Find the smallest element in arr[0..i-1] which is also greater than // or equal to arr[i] int j = ceilSearch(arr, 0, i-1, arr[i]); // Check if there was no element greater than arr[i] if (j != -1) { // Put arr[i] before arr[j] using following four flip operations flip(arr, j-1); flip(arr, i-1); flip(arr, i); flip(arr, j); } } } int atoi (string c) { stringstream s; int i; s << c; s >> i; return i; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); string in; int c; getline (cin, in); c = atoi (in); int jarj[c]; getline (cin, in); istringstream ssin(in); int i; i = 0; while (ssin >> jarj[i]) { i++; } insertionSort (jarj, c); cout << moves.size() << "\n"; for (i = 0; i < moves.size(); i++) cout << moves[i] << " "; cout << "\n"; 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 |
---|
32 0 1 2 1 1 2 3 2 2 3 4 3 2 4 5 ... |
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 |
---|
3984 0 3 4 1 1 4 5 2 4 6 7 5 1 7 8 ... |
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) |