답안 #521962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521962 2022-02-03T14:01:30 Z DanerZein Discharging (NOI20_discharging) C++14
20 / 100
1000 ms 24388 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 n;
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=query(0,0,n-1,0,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(){
  memset(dp,-1,sizeof dp);
  cin>>n;
  for(int i=0;i<n;i++){
    int a; cin>>a;
    val[i]=a;
  }
  val[n]=-MAX;
  init(0,0,n-1);
  cout<<maxres(0,n-1)<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8012 KB Output is correct
3 Correct 4 ms 8012 KB Output is correct
4 Correct 3 ms 8140 KB Output is correct
5 Correct 3 ms 8132 KB Output is correct
6 Correct 4 ms 8020 KB Output is correct
7 Correct 4 ms 8124 KB Output is correct
8 Correct 3 ms 8140 KB Output is correct
9 Correct 3 ms 8012 KB Output is correct
10 Correct 3 ms 8140 KB Output is correct
11 Correct 3 ms 8140 KB Output is correct
12 Correct 3 ms 8124 KB Output is correct
13 Correct 3 ms 8140 KB Output is correct
14 Correct 3 ms 8140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 8140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1086 ms 8140 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 379 ms 24388 KB Output is correct
2 Correct 363 ms 24140 KB Output is correct
3 Correct 358 ms 24104 KB Output is correct
4 Correct 361 ms 24112 KB Output is correct
5 Correct 360 ms 24108 KB Output is correct
6 Correct 361 ms 24036 KB Output is correct
7 Correct 363 ms 24180 KB Output is correct
8 Correct 354 ms 24104 KB Output is correct
9 Correct 371 ms 24076 KB Output is correct
10 Correct 367 ms 24028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8012 KB Output is correct
3 Correct 4 ms 8012 KB Output is correct
4 Correct 3 ms 8140 KB Output is correct
5 Correct 3 ms 8132 KB Output is correct
6 Correct 4 ms 8020 KB Output is correct
7 Correct 4 ms 8124 KB Output is correct
8 Correct 3 ms 8140 KB Output is correct
9 Correct 3 ms 8012 KB Output is correct
10 Correct 3 ms 8140 KB Output is correct
11 Correct 3 ms 8140 KB Output is correct
12 Correct 3 ms 8124 KB Output is correct
13 Correct 3 ms 8140 KB Output is correct
14 Correct 3 ms 8140 KB Output is correct
15 Execution timed out 1086 ms 8140 KB Time limit exceeded
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8140 KB Output is correct
2 Correct 4 ms 8012 KB Output is correct
3 Correct 4 ms 8012 KB Output is correct
4 Correct 3 ms 8140 KB Output is correct
5 Correct 3 ms 8132 KB Output is correct
6 Correct 4 ms 8020 KB Output is correct
7 Correct 4 ms 8124 KB Output is correct
8 Correct 3 ms 8140 KB Output is correct
9 Correct 3 ms 8012 KB Output is correct
10 Correct 3 ms 8140 KB Output is correct
11 Correct 3 ms 8140 KB Output is correct
12 Correct 3 ms 8124 KB Output is correct
13 Correct 3 ms 8140 KB Output is correct
14 Correct 3 ms 8140 KB Output is correct
15 Execution timed out 1086 ms 8140 KB Time limit exceeded
16 Halted 0 ms 0 KB -