# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
71964 | 2018-08-26T04:16:02 Z | 이시대의진정한망겜스타투(#2267, cki86201, ainta) | Box Run (FXCUP3_box) | C++17 | 209 ms | 30772 KB |
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <memory.h> #include <math.h> #include <assert.h> #include <queue> #include <map> #include <set> #include <string> #include <algorithm> #include <iostream> #include <functional> #include <unordered_map> #include <unordered_set> #include <list> #include <bitset> using namespace std; typedef long long ll; #define Fi first #define Se second #define pb(x) push_back(x) #define szz(x) ((int)(x).size()) #define rep(i, n) for(int i=0;i<n;i++) #define all(x) (x).begin(), (x).end() typedef tuple<int, int, int> t3; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef long double ldouble; int N, H[500050]; int ans[2][500050]; int main() { scanf("%d", &N); for(int i=1;i<=N;i++) scanf("%d", H+i); H[0] = H[N + 1] = 1e9 + 10; vector <pii> V; for(int i=1;i<=N;i++) ans[0][i] = ans[1][i] = 1e9; for(int i=0;i<=N+1;i++) { while(szz(V) && V.back().Fi < H[i]) V.pop_back(); if(szz(V)) { int d = i - V.back().Se - 1; if(d) { ans[0][d] = min(ans[0][d], i); } } V.push_back(pii(H[i], i)); } for(int i=N-1;i;i--) ans[0][i] = min(ans[0][i], ans[0][i+1]); V.clear(); for(int i=N+1;i>=0;i--) { while(szz(V) && V.back().Fi < H[i]) V.pop_back(); if(szz(V)) { int d = V.back().Se - i - 1; if(d) { ans[1][d] = min(ans[1][d], i + 1); } } } for(int i=N-1;i;i--) ans[1][i] = min(ans[1][i], ans[1][i+1]); for(int i=1;i<=N;i++) { int val = min(ans[0][i] - i, ans[1][i]); if(val == N + 1 - i) val = -1; printf("%d ",val); } puts(""); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 528 KB | Output is correct |
4 | Correct | 3 ms | 528 KB | Output is correct |
5 | Correct | 3 ms | 528 KB | Output is correct |
6 | Correct | 3 ms | 628 KB | Output is correct |
7 | Correct | 3 ms | 756 KB | Output is correct |
8 | Correct | 2 ms | 756 KB | Output is correct |
9 | Correct | 3 ms | 756 KB | Output is correct |
10 | Correct | 2 ms | 756 KB | Output is correct |
11 | Correct | 2 ms | 756 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 4 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 528 KB | Output is correct |
4 | Correct | 3 ms | 528 KB | Output is correct |
5 | Correct | 3 ms | 528 KB | Output is correct |
6 | Correct | 3 ms | 628 KB | Output is correct |
7 | Correct | 3 ms | 756 KB | Output is correct |
8 | Correct | 2 ms | 756 KB | Output is correct |
9 | Correct | 3 ms | 756 KB | Output is correct |
10 | Correct | 2 ms | 756 KB | Output is correct |
11 | Correct | 2 ms | 756 KB | Output is correct |
12 | Correct | 3 ms | 756 KB | Output is correct |
13 | Correct | 5 ms | 756 KB | Output is correct |
14 | Correct | 23 ms | 1928 KB | Output is correct |
15 | Correct | 34 ms | 3348 KB | Output is correct |
16 | Correct | 46 ms | 4580 KB | Output is correct |
17 | Correct | 127 ms | 9764 KB | Output is correct |
18 | Correct | 169 ms | 14644 KB | Output is correct |
19 | Correct | 203 ms | 20608 KB | Output is correct |
20 | Correct | 209 ms | 26636 KB | Output is correct |
21 | Correct | 203 ms | 30772 KB | Output is correct |