Submission #1084423

# Submission time Handle Problem Language Result Execution time Memory
1084423 2024-09-06T08:35:23 Z _rain_ Discharging (NOI20_discharging) C++14
9 / 100
9 ms 3164 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long

#define fixbug true

const ll INF = (ll)1e18+7;
const int maxn = 1e5;
ll a[maxn+2] ;
int n;

namespace subtask1{
    bool check(){
        return n <= 1500;
    }
    const int N = 1500;
    ll f[N+2] , sum[N+2] = {};
    void main_code(){
        for (int i = 1; i <= n; ++i) f[i] = INF ;
        for (int i = 1; i <= n; ++i){
            ll mx = a[i];
            for (int j = i; j >= 1; --j){
                mx = max(mx , a[j]);
                //ll v = f[j - 1] + sum[j - 1] * i - sum[j - 1] * (j + 1) + mx * i - mx * (j + 1);
                ll v = f[j - 1] + (sum[j - 1] + mx) * (i - j + 1);
                if (f[i] == v){
                    sum[i] = min(sum[i] , sum[j - 1] + mx);
                }
                else if (f[i] > v) {
                    f[i] = v;
                    sum[i] = sum[j - 1] + mx;
                }
            }
        }
        cout << f[n];
        return;
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #define name "main"
    if (fopen(name".inp","r")){
        freopen(name".inp","r",stdin);
    }

    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];

    if (subtask1::check()) {
        subtask1::main_code();
        exit(0);
    }
    //subtask2::main_code();
    exit(0);
}

Compilation message

Discharging.cpp: In function 'int main()':
Discharging.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen(name".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 9 ms 3164 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 2 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Incorrect 2 ms 348 KB Output isn't correct
16 Halted 0 ms 0 KB -