# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
29534 | 2017-07-20T05:31:57 Z | 서규호(#1242) | Lightning Conductor (POI11_pio) | C++14 | 1000 ms | 11912 KB |
#include <bits/stdc++.h> #include <unistd.h> #define pii pair<int,int> #define pll pair<lld,lld> #define pb push_back #define next nextt #define left leftt #define right rightt #define lld long long #define Inf 1000000000 #define Mod 1000000007 #define Linf 1000000000000000000LL #define get gett using namespace std; int N,ans; int a[500002]; struct data{ int s,e,size; pii *q; void insert(int x){ while(s != (e%(size-1)) && q[e-1].first <= a[x]){ e--; if(e == 0) e = size-1; } if(e == size-1){ q[0] = pii(a[x],x); e = 1; }else{ q[e] = pii(a[x],x); e++; } } int get(){ return q[s].first; } void erase(int x){ if(q[s].second == x){ s++; if(s == size-1) s = 0; } } }S1[800],S2[800]; void calcans(int num){ ans = 0; int e = sqrt(num-1); if(e*e != num-1) e++; for(int i=1; i<=e; i++){ ans = max(ans,S1[i].get()+i-a[num]); } e = sqrt(N-num); if(e*e != N-num) e++; for(int i=1; i<=e; i++){ ans = max(ans,S2[i].get()+i-a[num]); } } int main(){ //freopen("input.txt","r",stdin); srand(time(NULL)); scanf("%d",&N); for(int i=1; i<=sqrt(N)+1; i++){ S1[i].size = S2[i].size = i*2+2; S1[i].s = S1[i].e = S2[i].s = S2[i].e = 1; S1[i].q = (pii*)malloc(sizeof(pii)*S1[i].size); S2[i].q = (pii*)malloc(sizeof(pii)*S2[i].size); } for(int i=1; i<=N; i++){ scanf("%d",&a[i]); } for(int i=2; i<=N; i++){ int t = sqrt(i-1); if(t*t != i-1) t++; S2[t].insert(i); } calcans(1); printf("%d\n",ans); for(int i=2; i<=N; i++){ S1[1].erase(i); S1[1].insert(i-1); for(int j=1; i-1-j*j>=1; j++){ int t = i-1-j*j; S1[j].erase(t); S1[j+1].insert(t); } for(int j=1; i+j*j<=N; j++){ int t = i+j*j; S2[j+1].erase(t); S2[j].insert(t); } calcans(i); printf("%d\n",ans); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 4024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 4024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 4024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 189 ms | 4552 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 473 ms | 4816 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 713 ms | 5080 KB | Output is correct |
2 | Correct | 369 ms | 5080 KB | Output is correct |
3 | Correct | 626 ms | 5080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 5612 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 7604 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 9612 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 11912 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1000 ms | 11912 KB | Execution timed out |
2 | Halted | 0 ms | 0 KB | - |