# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
271874 | 2020-08-18T07:51:18 Z | 반딧불(#5113) | Archery (IOI09_archery) | C++17 | 2000 ms | 13868 KB |
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; typedef long long ll; int n, k, val; int arr[400005]; int tmpArr[400005]; int ans, finish = 1e9; int tryIfAble(){ vector<int> v(arr+1, arr+2*n+1); int cnt = 2*n; if(val > n+1){ set<int> st; for(int i=0; i<2*n; i++){ if(v[i] > n+1) tmpArr[v[i]] = i/2; } for(int i=1; i<n; i++) st.insert(i); int ret = 0; for(int i=2*n; i>=val; i--){ int tmp = tmpArr[i]; if(st.upper_bound(tmp) != st.begin()) ret = *prev(st.upper_bound(tmp)); else ret = *st.rbegin(); st.erase(ret); } return ret; } else{ while(cnt--){ for(int i=0; i<n; i++){ if(i==0 && v[i*2] > v[i*2+1]) swap(v[i*2], v[i*2+1]); else if(i && v[i*2] < v[i*2+1]) swap(v[i*2], v[i*2+1]); } int tmp = v[1]; for(int i=0; i<n-1; i++) v[i*2+1] = v[i*2+3]; v.back()=tmp; } int idx = -1; for(int i=0; i<2*n; i++) if(v[i] == val) idx = i; if(idx%2==0) return idx/2+1; idx /= 2, idx += (n-k), idx %= n, idx++; return idx; } } int main(){ scanf("%d %d %d", &n, &k, &val); if(val == 1){ printf("%d", n); return 0; } k%=n; arr[1] = val; for(int i=2; i<=2*n; i++) scanf("%d", &arr[i]); for(int i=1; i<=2*n; i+=2){ int tmp = tryIfAble(); if(finish >= tmp) finish = tmp, ans = (i+1)/2; swap(arr[i], arr[i+1]); swap(arr[i+1], arr[i+2]); } printf("%d\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 256 KB | Output is correct |
2 | Correct | 0 ms | 256 KB | Output is correct |
3 | Correct | 5 ms | 384 KB | Output is correct |
4 | Execution timed out | 2079 ms | 384 KB | Time limit exceeded |
5 | Correct | 0 ms | 256 KB | Output is correct |
6 | Correct | 4 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 384 KB | Output is correct |
2 | Correct | 30 ms | 376 KB | Output is correct |
3 | Execution timed out | 2087 ms | 384 KB | Time limit exceeded |
4 | Execution timed out | 2089 ms | 608 KB | Time limit exceeded |
5 | Execution timed out | 2094 ms | 2936 KB | Time limit exceeded |
6 | Correct | 29 ms | 376 KB | Output is correct |
7 | Execution timed out | 2080 ms | 384 KB | Time limit exceeded |
8 | Execution timed out | 2088 ms | 632 KB | Time limit exceeded |
9 | Execution timed out | 2078 ms | 676 KB | Time limit exceeded |
10 | Execution timed out | 2053 ms | 384 KB | Time limit exceeded |
11 | Execution timed out | 2057 ms | 680 KB | Time limit exceeded |
12 | Execution timed out | 2072 ms | 384 KB | Time limit exceeded |
13 | Execution timed out | 2071 ms | 2296 KB | Time limit exceeded |
14 | Execution timed out | 2070 ms | 384 KB | Time limit exceeded |
15 | Execution timed out | 2078 ms | 768 KB | Time limit exceeded |
16 | Correct | 42 ms | 376 KB | Output is correct |
17 | Execution timed out | 2065 ms | 384 KB | Time limit exceeded |
18 | Execution timed out | 2065 ms | 384 KB | Time limit exceeded |
19 | Execution timed out | 2088 ms | 384 KB | Time limit exceeded |
20 | Execution timed out | 2086 ms | 384 KB | Time limit exceeded |
21 | Execution timed out | 2087 ms | 676 KB | Time limit exceeded |
22 | Execution timed out | 2087 ms | 768 KB | Time limit exceeded |
23 | Execution timed out | 2090 ms | 3192 KB | Time limit exceeded |
24 | Correct | 8 ms | 384 KB | Output is correct |
25 | Correct | 236 ms | 384 KB | Output is correct |
26 | Execution timed out | 2074 ms | 640 KB | Time limit exceeded |
27 | Execution timed out | 2064 ms | 2004 KB | Time limit exceeded |
28 | Execution timed out | 2090 ms | 8872 KB | Time limit exceeded |
29 | Correct | 435 ms | 472 KB | Output is correct |
30 | Execution timed out | 2084 ms | 640 KB | Time limit exceeded |
31 | Execution timed out | 2092 ms | 1804 KB | Time limit exceeded |
32 | Execution timed out | 2091 ms | 12064 KB | Time limit exceeded |
33 | Correct | 9 ms | 384 KB | Output is correct |
34 | Correct | 5 ms | 384 KB | Output is correct |
35 | Correct | 1089 ms | 516 KB | Output is correct |
36 | Correct | 1625 ms | 544 KB | Output is correct |
37 | Execution timed out | 2086 ms | 1540 KB | Time limit exceeded |
38 | Execution timed out | 2068 ms | 2256 KB | Time limit exceeded |
39 | Correct | 8 ms | 384 KB | Output is correct |
40 | Correct | 256 ms | 444 KB | Output is correct |
41 | Correct | 1177 ms | 512 KB | Output is correct |
42 | Correct | 1628 ms | 532 KB | Output is correct |
43 | Execution timed out | 2041 ms | 640 KB | Time limit exceeded |
44 | Execution timed out | 2053 ms | 1312 KB | Time limit exceeded |
45 | Execution timed out | 2070 ms | 1852 KB | Time limit exceeded |
46 | Execution timed out | 2029 ms | 2040 KB | Time limit exceeded |
47 | Execution timed out | 2081 ms | 13868 KB | Time limit exceeded |