# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63869 | 2018-08-03T05:48:55 Z | ainta(#1864) | Ranklist Sorting (BOI07_sorting) | C++11 | 1000 ms | 544 KB |
#include<cstdio> #include<algorithm> #include<vector> using namespace std; #define pii pair<int,int> int n, w[1010], ow[1010]; struct point { int a, num; bool operator < (const point &p)const { return a < p.a; } }ord[1010]; int chk[1010]; vector<pii>RR; void Move(int b, int e) { int t = w[b]; if (b < e) { int i; for (i = b; i < e; i++)w[i] = w[i + 1]; w[e] = t; } else { int i; for (i = b; i > e; i--)w[i] = w[i - 1]; w[e] = t; } } int res = 1e9; int main() { int i, j; scanf("%d", &n); for (i = 1; i <= n; i++) { scanf("%d", &ord[i].a); ord[i].num = i; } sort(ord + 1, ord + n + 1); for (i = 1; i <= n; i++) { w[ord[i].num] = n+1-i; } for (i = 1; i <= n; i++)ow[i] = w[i]; for (i = 1; i < (1 << n); i++) { for (j = 1; j <= n; j++)w[j] = ow[j]; for (j = 0; j < n; j++) { if ((i >> j) & 1)chk[j + 1] = 1; else chk[j + 1] = 0; } int Mx = 0, ck = 0; for (j = 1; j <= n; j++) { if (chk[w[j]]) { if (Mx > w[j])ck = 1; Mx = w[j]; } } if (ck)continue; vector<pii>V; int cost = 0; while (1) { for (j = 1; j <= n; j++) { if (!chk[w[j]])break; } if (j == n + 1)break; int b = j; int pv = 0; for (j = 1; j <= n; j++) { if (chk[w[j]]) { if (w[j] > w[b])break; pv = j; } } chk[w[b]] = 1; if (b < pv + 1)pv--; Move(b, pv + 1); cost += b + pv + 1; V.push_back({ b, pv + 1 }); } if (res > cost) { res = cost; RR = V; } } printf("%d\n", RR.size()); for (auto &t : RR) { printf("%d %d\n", t.first, t.second); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 416 KB | Output is correct |
4 | Incorrect | 83 ms | 416 KB | Output isn't correct |
5 | Incorrect | 3 ms | 432 KB | not sorted |
6 | Incorrect | 3 ms | 480 KB | not sorted |
7 | Execution timed out | 1078 ms | 488 KB | Time limit exceeded |
8 | Incorrect | 4 ms | 544 KB | not sorted |
9 | Incorrect | 3 ms | 544 KB | not sorted |
10 | Incorrect | 4 ms | 544 KB | not sorted |