Submission #362082

#TimeUsernameProblemLanguageResultExecution timeMemory
362082idk321Jousting tournament (IOI12_tournament)C++11
17 / 100
1087 ms2028 KiB
#include <bits/stdc++.h> using namespace std; const int N = 5005; int tree[4 * N]; void make(int i, int num, int a, int b, int node) { if (a == b) { tree[node] = num; return; } int mid = (a + b) / 2; if (i <= mid) make(i, num, a, mid, node * 2); else make(i, num, mid + 1, b, node * 2 + 1); tree[node] = tree[node * 2] + tree[node * 2 + 1]; } int kth(int k, int a, int b, int node) { if (a == b) return a; int mid = (a + b) / 2; if (tree[node * 2] > k) return kth(k, a, mid, node * 2); return kth(k - tree[node * 2], mid + 1, b, node * 2 + 1); } int GetBestPosition(int n, int c, int r, int *k, int *s, int *e) { int best = -1; int pos = -1; //cout << endl; for (int i = 0; i < n; i++) { vector<int> nr(n); nr[i] = r; for (int j = 0; j < n - 1; j++) { if (j < i) nr[j] = k[j]; else nr[j + 1] = k[j]; } for (int i = 0; i < n; i++) make(i, 1, 0, n - 1, 1); int cur = 0; for (int j = 0; j < c; j++) { int ci = -1; int cbest = -1; for (int l = s[j]; l <= e[j]; l++) { int ki = kth(s[j], 0, n - 1, 1); if (nr[ki] > cbest) { cbest = nr[ki]; ci = ki; } make(ki, 0, 0, n - 1, 1); } make(ci, 1, 0, n - 1, 1); //cout << i << " " << cbest << endl; if (cbest == r) cur++; } if (cur > best) { best = cur; pos = i; } } return pos; } /* 5 3 2 1 0 4 3 0 1 0 1 1 3 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...