Submission #521966

# Submission time Handle Problem Language Result Execution time Memory
521966 2022-02-03T14:06:23 Z DanerZein Discharging (NOI20_discharging) C++14
47 / 100
1000 ms 54504 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N=1e6+10;
const int MAX_P=MAX_N*4;
const int MAX=1e9;
ll val[MAX_N];
int tr[MAX_P];
ll ma[MAX_N];
ll n;
void maxi(){
  int m=-1,id;
  for(int i=0;i<n;i++){
    if(m<val[i]){
      m=val[i];
      id=i;
    }
    ma[i]=id;
  }
}
int unir(int a,int b){
  if(a==n || b==n){
    if(a==n) return b;
    if(b==n) return a;
    return n;
  }
  if(val[a]>val[b]) return a;
  else{
    if(val[a]==val[b]) return min(a,b);
    else return b;
  }
}
void init(int node,int a,int b){
  if(a==b){
    tr[node]=a;
    return;
  }
  int mid=(a+b)/2,le=2*node+1,ri=2*node+2;
  init(le,a,mid);
  init(ri,mid+1,b);
  tr[node]=unir(tr[le],tr[ri]);
}
ll query(int node,int a,int b,int l,int r){
  if(b<l || a>r) return n;
  if(l<=a && r>=b) return tr[node];
  int mid=(a+b)/2,le=2*node+1,ri=2*node+2;
  return unir(query(le,a,mid,l,r),query(ri,mid+1,b,l,r));
}
ll dp[MAX_N];
ll maxres(int l,int r){
  if(dp[r]!=-1) return dp[r];
  int i=ma[r];
  if(i==0) return val[i]*n;
  ll d=(n-i);
  ll ans=val[i]*n;
  for(int k=i-1;k>=0;k--){
    ans=min(ans,val[i]*d+maxres(0,k));
    d++;
  }
  return dp[r]=ans;
}
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(dp,-1,sizeof dp);
  cin>>n;
  for(int i=0;i<n;i++){
    int a; cin>>a;
    val[i]=a;
  }
  maxi();
  val[n]=-MAX;
  // init(0,0,n-1);
  cout<<maxres(0,n-1)<<endl;
}

Compilation message

Discharging.cpp: In function 'void maxi()':
Discharging.cpp:18:11: warning: 'id' may be used uninitialized in this function [-Wmaybe-uninitialized]
   18 |     ma[i]=id;
      |           ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8140 KB Output is correct
3 Correct 4 ms 8112 KB Output is correct
4 Correct 4 ms 8140 KB Output is correct
5 Correct 3 ms 8140 KB Output is correct
6 Correct 3 ms 8140 KB Output is correct
7 Correct 3 ms 8064 KB Output is correct
8 Correct 5 ms 8140 KB Output is correct
9 Correct 3 ms 8076 KB Output is correct
10 Correct 4 ms 8140 KB Output is correct
11 Correct 4 ms 8140 KB Output is correct
12 Correct 4 ms 8140 KB Output is correct
13 Correct 4 ms 8140 KB Output is correct
14 Correct 4 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8292 KB Output is correct
2 Correct 5 ms 8268 KB Output is correct
3 Correct 5 ms 8268 KB Output is correct
4 Correct 5 ms 8268 KB Output is correct
5 Correct 5 ms 8268 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 6 ms 8268 KB Output is correct
8 Correct 5 ms 8268 KB Output is correct
9 Correct 5 ms 8268 KB Output is correct
10 Correct 5 ms 8268 KB Output is correct
11 Correct 5 ms 8268 KB Output is correct
12 Correct 6 ms 8152 KB Output is correct
13 Correct 7 ms 8268 KB Output is correct
14 Correct 6 ms 8268 KB Output is correct
15 Correct 7 ms 8268 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8292 KB Output is correct
2 Correct 5 ms 8268 KB Output is correct
3 Correct 5 ms 8268 KB Output is correct
4 Correct 5 ms 8268 KB Output is correct
5 Correct 5 ms 8268 KB Output is correct
6 Correct 5 ms 8140 KB Output is correct
7 Correct 6 ms 8268 KB Output is correct
8 Correct 5 ms 8268 KB Output is correct
9 Correct 5 ms 8268 KB Output is correct
10 Correct 5 ms 8268 KB Output is correct
11 Correct 5 ms 8268 KB Output is correct
12 Correct 6 ms 8152 KB Output is correct
13 Correct 7 ms 8268 KB Output is correct
14 Correct 6 ms 8268 KB Output is correct
15 Correct 7 ms 8268 KB Output is correct
16 Execution timed out 1091 ms 54504 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 23760 KB Output is correct
2 Correct 96 ms 23764 KB Output is correct
3 Correct 96 ms 23664 KB Output is correct
4 Correct 94 ms 23772 KB Output is correct
5 Correct 94 ms 23728 KB Output is correct
6 Correct 96 ms 23764 KB Output is correct
7 Correct 94 ms 23676 KB Output is correct
8 Correct 98 ms 23876 KB Output is correct
9 Correct 99 ms 23768 KB Output is correct
10 Correct 103 ms 23748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8140 KB Output is correct
3 Correct 4 ms 8112 KB Output is correct
4 Correct 4 ms 8140 KB Output is correct
5 Correct 3 ms 8140 KB Output is correct
6 Correct 3 ms 8140 KB Output is correct
7 Correct 3 ms 8064 KB Output is correct
8 Correct 5 ms 8140 KB Output is correct
9 Correct 3 ms 8076 KB Output is correct
10 Correct 4 ms 8140 KB Output is correct
11 Correct 4 ms 8140 KB Output is correct
12 Correct 4 ms 8140 KB Output is correct
13 Correct 4 ms 8140 KB Output is correct
14 Correct 4 ms 8140 KB Output is correct
15 Correct 5 ms 8292 KB Output is correct
16 Correct 5 ms 8268 KB Output is correct
17 Correct 5 ms 8268 KB Output is correct
18 Correct 5 ms 8268 KB Output is correct
19 Correct 5 ms 8268 KB Output is correct
20 Correct 5 ms 8140 KB Output is correct
21 Correct 6 ms 8268 KB Output is correct
22 Correct 5 ms 8268 KB Output is correct
23 Correct 5 ms 8268 KB Output is correct
24 Correct 5 ms 8268 KB Output is correct
25 Correct 5 ms 8268 KB Output is correct
26 Correct 6 ms 8152 KB Output is correct
27 Correct 7 ms 8268 KB Output is correct
28 Correct 6 ms 8268 KB Output is correct
29 Correct 7 ms 8268 KB Output is correct
30 Correct 5 ms 8140 KB Output is correct
31 Correct 6 ms 8184 KB Output is correct
32 Correct 4 ms 8140 KB Output is correct
33 Correct 5 ms 8140 KB Output is correct
34 Correct 5 ms 8140 KB Output is correct
35 Correct 6 ms 8180 KB Output is correct
36 Correct 5 ms 8140 KB Output is correct
37 Correct 5 ms 8140 KB Output is correct
38 Correct 8 ms 8140 KB Output is correct
39 Correct 5 ms 8140 KB Output is correct
40 Correct 6 ms 8140 KB Output is correct
41 Correct 5 ms 8140 KB Output is correct
42 Correct 5 ms 8140 KB Output is correct
43 Correct 5 ms 8268 KB Output is correct
44 Correct 5 ms 8140 KB Output is correct
45 Correct 5 ms 8140 KB Output is correct
46 Correct 6 ms 8140 KB Output is correct
47 Correct 9 ms 8192 KB Output is correct
48 Correct 5 ms 8140 KB Output is correct
49 Correct 5 ms 8140 KB Output is correct
50 Correct 5 ms 8140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8140 KB Output is correct
3 Correct 4 ms 8112 KB Output is correct
4 Correct 4 ms 8140 KB Output is correct
5 Correct 3 ms 8140 KB Output is correct
6 Correct 3 ms 8140 KB Output is correct
7 Correct 3 ms 8064 KB Output is correct
8 Correct 5 ms 8140 KB Output is correct
9 Correct 3 ms 8076 KB Output is correct
10 Correct 4 ms 8140 KB Output is correct
11 Correct 4 ms 8140 KB Output is correct
12 Correct 4 ms 8140 KB Output is correct
13 Correct 4 ms 8140 KB Output is correct
14 Correct 4 ms 8140 KB Output is correct
15 Correct 5 ms 8292 KB Output is correct
16 Correct 5 ms 8268 KB Output is correct
17 Correct 5 ms 8268 KB Output is correct
18 Correct 5 ms 8268 KB Output is correct
19 Correct 5 ms 8268 KB Output is correct
20 Correct 5 ms 8140 KB Output is correct
21 Correct 6 ms 8268 KB Output is correct
22 Correct 5 ms 8268 KB Output is correct
23 Correct 5 ms 8268 KB Output is correct
24 Correct 5 ms 8268 KB Output is correct
25 Correct 5 ms 8268 KB Output is correct
26 Correct 6 ms 8152 KB Output is correct
27 Correct 7 ms 8268 KB Output is correct
28 Correct 6 ms 8268 KB Output is correct
29 Correct 7 ms 8268 KB Output is correct
30 Execution timed out 1091 ms 54504 KB Time limit exceeded
31 Halted 0 ms 0 KB -