답안 #386928

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
386928 2021-04-07T16:14:17 Z lukameladze Growing Vegetables is Fun 4 (JOI21_ho_t1) C++14
100 / 100
95 ms 10348 KB
# include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
using namespace std;
const int N=1e6+5;
long long n,a[N],dp[N],pre,a1[N],dp1[N],a2[N],ans;
vector <long long> v;
int main() {
     cin>>n;
     for (int i=1; i<=n; i++) {
          cin>>a[i];
          a1[i]=a[i];
          a2[i]=a[i];
     }
     for (int i=1; i<=n; i++) {
          a1[i]+=pre;
          //cout<<a1[i]<<" "<<a1[i-1]<<endl;
          if(a1[i]<=a1[i-1]) {
               pre+=abs(a1[i-1]-a1[i])+1LL;
               a1[i]=a1[i-1]+1;
          }
          dp[i]=pre;
      //    cout<<a1[i]<<" ";
          //cout<<dp[i]<<" ";
          //cout<<a1[i]<<" ";
     }
   //  cout<<endl;
     //for (int i=1; i<=n; i++)
     //cout<<dp[i]<<" ";
     //cout<<endl;
     pre=0;
     for (int i=n; i>=1; i--) {
          a2[i]+=pre;
          if (a2[i]<=a2[i+1]) {
               pre+=abs(a2[i+1]-a2[i])+1LL;
               a2[i]=a2[i+1]+1;
          }
          dp1[i]=pre;
         // cout<<dp1[i]<<" ";
     }
    // cout<<endl;
     ans=min(dp[n],dp1[1]);
     for (int i=1; i<n; i++) {
          //cout<<dp[i]<<" "<<dp[i+1]<<endl;
          long long anss=max(dp[i],dp1[i+1]);
          if (a1[i]+anss==a2[i+1]+anss) ans=min(ans,max(dp[i],dp1[i+1])+1);
          else
          ans=min(ans,max(dp[i],dp1[i+1]));
     }
     cout<<ans<<endl;
   //  for (int i=1; i<=n; i++) {
     //     cout<<dp[i]<<" "<<dp1[i+1]<<endl;
     //}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 456 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 4 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 3 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 2 ms 492 KB Output is correct
6 Correct 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 456 KB Output is correct
9 Correct 3 ms 492 KB Output is correct
10 Correct 2 ms 492 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 2 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 2 ms 492 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 2 ms 492 KB Output is correct
18 Correct 4 ms 492 KB Output is correct
19 Correct 2 ms 492 KB Output is correct
20 Correct 2 ms 620 KB Output is correct
21 Correct 2 ms 492 KB Output is correct
22 Correct 3 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 91 ms 10092 KB Output is correct
27 Correct 95 ms 10092 KB Output is correct
28 Correct 95 ms 10348 KB Output is correct
29 Correct 90 ms 10156 KB Output is correct
30 Correct 69 ms 9452 KB Output is correct
31 Correct 91 ms 10128 KB Output is correct
32 Correct 92 ms 10220 KB Output is correct
33 Correct 90 ms 10220 KB Output is correct
34 Correct 91 ms 10220 KB Output is correct
35 Correct 78 ms 9324 KB Output is correct
36 Correct 75 ms 9452 KB Output is correct
37 Correct 71 ms 9452 KB Output is correct
38 Correct 90 ms 10092 KB Output is correct
39 Correct 90 ms 10220 KB Output is correct
40 Correct 91 ms 10220 KB Output is correct
41 Correct 90 ms 10196 KB Output is correct
42 Correct 83 ms 9964 KB Output is correct
43 Correct 90 ms 10220 KB Output is correct
44 Correct 94 ms 10092 KB Output is correct
45 Correct 89 ms 10092 KB Output is correct
46 Correct 90 ms 10220 KB Output is correct
47 Correct 89 ms 10220 KB Output is correct
48 Correct 93 ms 10252 KB Output is correct