Submission #285050

# Submission time Handle Problem Language Result Execution time Memory
285050 2020-08-28T09:30:59 Z mosiashvililuka Discharging (NOI20_discharging) C++14
20 / 100
982 ms 61904 KB
#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;
multiset <long long> s;
multiset <long long>::iterator it;
vector <long long> v[1000009];
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());
            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);
        mn[st.size()]=dp[i-1]+f[i]*(a-i+1);
        if(mn[st.size()]>xc) mn[st.size()]=xc;
        //cout<<dp[i]<<endl;
        st.push(i-1);
    }
    cout<<dp[a];
    return 0;
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:11:16: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   11 |     scanf("%I64d",&a);
      |            ~~~~^  ~~
      |                |  |
      |                |  long long int*
      |                int*
      |            %I64lld
Discharging.cpp:13:36: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
   13 |     for(i=1; i<=a; i++) scanf("%I64d",&f[i]);
      |                                ~~~~^  ~~~~~
      |                                    |  |
      |                                    |  long long int*
      |                                    int*
      |                                %I64lld
Discharging.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |     scanf("%I64d",&a);
      |     ~~~~~^~~~~~~~~~~~
Discharging.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   12 |     scanf("\n");
      |     ~~~~~^~~~~~
Discharging.cpp:13:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |     for(i=1; i<=a; i++) scanf("%I64d",&f[i]);
      |                         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23808 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 916 ms 56164 KB Output is correct
2 Correct 940 ms 56840 KB Output is correct
3 Correct 982 ms 56852 KB Output is correct
4 Correct 932 ms 61832 KB Output is correct
5 Correct 936 ms 61868 KB Output is correct
6 Correct 898 ms 61804 KB Output is correct
7 Correct 977 ms 61828 KB Output is correct
8 Correct 926 ms 61900 KB Output is correct
9 Correct 936 ms 61904 KB Output is correct
10 Correct 963 ms 61784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23808 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Incorrect 16 ms 23808 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 16 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 15 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 16 ms 23808 KB Output is correct
10 Correct 17 ms 23808 KB Output is correct
11 Correct 16 ms 23808 KB Output is correct
12 Correct 17 ms 23808 KB Output is correct
13 Correct 17 ms 23808 KB Output is correct
14 Correct 16 ms 23808 KB Output is correct
15 Incorrect 16 ms 23808 KB Output isn't correct
16 Halted 0 ms 0 KB -