# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
72168 | 2018-08-26T05:42:46 Z | 유애나(#2199, kdh9949) | 박스런 (FXCUP3_box) | C++17 | 482 ms | 48600 KB |
#include <bits/stdc++.h> using namespace std; const int N = 500005; int n, h[N], lg[N], d[N][20], nx[N]; int g(int s, int e){ e = min(e, n + 1); int l = lg[e - s + 1]; int x = d[s][l], y = d[e - (1 << l) + 1][l]; return (h[x] > h[y] || (h[x] == h[y] && x < y)) ? x : y; } int main(){ scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", h + i); h[n + 1] = int(2e9); for(int i = 1, j = 0; i <= n + 1; i++){ while((2 << j) < i) j++; lg[i] = j; d[i][0] = i; } for(int i = 1; i < 20; i++){ for(int j = 1; j <= n + 1; j++){ int x = d[j][i - 1], y = d[min(n + 1, j + (1 << (i - 1)))][i - 1]; if(h[x] > h[y] || (h[x] == h[y] && x < y)) d[j][i] = x; else d[j][i] = y; } } for(int i = 1; i <= n; i++){ nx[i] = i; for(int j = 19; j >= 0; j--){ if(h[d[nx[i]][j]] <= h[i]) nx[i] += (1 << j); } } for(int i = 1; i <= n; i++){ int t = g(1, i); while(t < n){ int nt = nx[t]; if(nt <= min(n, t + i)){ t = nt - i; break; } else t = g(t + 1, t + i); } printf("%d ", t >= n ? -1 : t); } puts(""); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 412 KB | Output is correct |
4 | Correct | 3 ms | 488 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 544 KB | Output is correct |
7 | Correct | 2 ms | 544 KB | Output is correct |
8 | Correct | 3 ms | 544 KB | Output is correct |
9 | Correct | 2 ms | 544 KB | Output is correct |
10 | Correct | 3 ms | 544 KB | Output is correct |
11 | Correct | 2 ms | 544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 412 KB | Output is correct |
4 | Correct | 3 ms | 488 KB | Output is correct |
5 | Correct | 2 ms | 544 KB | Output is correct |
6 | Correct | 2 ms | 544 KB | Output is correct |
7 | Correct | 2 ms | 544 KB | Output is correct |
8 | Correct | 3 ms | 544 KB | Output is correct |
9 | Correct | 2 ms | 544 KB | Output is correct |
10 | Correct | 3 ms | 544 KB | Output is correct |
11 | Correct | 2 ms | 544 KB | Output is correct |
12 | Correct | 2 ms | 544 KB | Output is correct |
13 | Correct | 4 ms | 1056 KB | Output is correct |
14 | Correct | 31 ms | 4972 KB | Output is correct |
15 | Correct | 81 ms | 7676 KB | Output is correct |
16 | Correct | 68 ms | 10108 KB | Output is correct |
17 | Correct | 203 ms | 25008 KB | Output is correct |
18 | Correct | 314 ms | 34460 KB | Output is correct |
19 | Correct | 405 ms | 43092 KB | Output is correct |
20 | Correct | 482 ms | 48600 KB | Output is correct |
21 | Correct | 438 ms | 48600 KB | Output is correct |