Submission #285063

#TimeUsernameProblemLanguageResultExecution timeMemory
285063mosiashvililukaDischarging (NOI20_discharging)C++14
20 / 100
866 ms32264 KiB
#include<bits/stdc++.h>
using namespace std;
long long f[1000009],mx,rg[1000009],mn[1000009];
long long dp[1000009],a,b,c,d,e,i,j,ii,jj,zx,xc;
stack <long long> st;
int main(){
    //ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    scanf("%I64d",&a);
    scanf("\n");
    for(i=1; i<=a; i++) scanf("%I64d",&f[i]);
    mx=0;
    st.push(0);
    mn[1]=f[1]*a;
    for(i=1; i<=a; i++){
        if(mx<f[i]) mx=f[i];
        dp[i]=mx*a;
        xc=999999999999999999LL;
        while(st.size()>0&&f[st.top()+1]<=f[i]){
            //zx=dp[st.top()]+(f[i]-f[st.top()+1])*(a-st.top());
            zx=dp[st.top()]+f[i]*(a-st.top());
            //if(xc>mn[st.size()]) xc=mn[st.size()];
            if(dp[i]>zx) dp[i]=zx;
            st.pop();
        }
        if(st.size()>0){
            //zx=dp[st.top()]+f[st.top()+1]*(a-st.top());
            zx=mn[st.size()];
            if(xc>mn[st.size()]) xc=mn[st.size()];
            if(dp[i]>zx) dp[i]=zx;
        }
        if(dp[i]>dp[i-1]+f[i]*(a-i+1)) dp[i]=dp[i-1]+f[i]*(a-i+1);
        st.push(i-1);
        mn[st.size()]=dp[i-1]+f[i]*(a-i+1);
        if(mn[st.size()]>xc) mn[st.size()]=xc;
        //cout<<dp[i]<<endl;
    }
    cout<<dp[a];
    return 0;
}

Compilation message (stderr)

Discharging.cpp: In function 'int main()':
Discharging.cpp:8:16: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
    8 |     scanf("%I64d",&a);
      |            ~~~~^  ~~
      |                |  |
      |                |  long long int*
      |                int*
      |            %I64lld
Discharging.cpp:10:36: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   10 |     for(i=1; i<=a; i++) scanf("%I64d",&f[i]);
      |                                ~~~~^  ~~~~~
      |                                    |  |
      |                                    |  long long int*
      |                                    int*
      |                                %I64lld
Discharging.cpp:8:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    8 |     scanf("%I64d",&a);
      |     ~~~~~^~~~~~~~~~~~
Discharging.cpp:9:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |     scanf("\n");
      |     ~~~~~^~~~~~
Discharging.cpp:10:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   10 |     for(i=1; i<=a; i++) scanf("%I64d",&f[i]);
      |                         ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...