Submission #1054210

# Submission time Handle Problem Language Result Execution time Memory
1054210 2024-08-12T07:37:36 Z Kipras Safety (NOI18_safety) C++17
3 / 100
2000 ms 4800 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pl;

const ll maxC = 5010;

ll n, h;
vector<ll> diffs;

ll res = 1e18;

int main() {

    ios_base::sync_with_stdio(false);cin.tie(nullptr);

    cin>>n>>h;
    ll aa;
    cin>>aa;
    for(int i = 0; i < n-1; i++) {
        ll bb;
        cin>>bb;
        diffs.push_back(bb-aa);
        //cout<<diffs.back()<<" ";
        aa=bb;
    }
    //cout<<"\n\n\n";


    ll lowB=0, highB=0;

    if(diffs[0]>0) {
        lowB=-diffs[0];
    }else {
        highB=-diffs[0];
    }

    for(int x = lowB; x <= highB; x++) {
        //cout<<"doing: "<<x<<"\n";
        vector<ll> tmp;
        for(int i = 0; i < n-1; i++) {
            tmp.push_back(diffs[i]);
        }

        ll lRes = abs(x);
        tmp[0]+=x;
        tmp.push_back(0);

        for(int i = 0; i < n-1; i++) {
            if(tmp[i]==0)continue;
            ll v = abs(tmp[i]);
            if(h>=v)continue;
            ll di = v-h;
            if(tmp[i]<0) {
                tmp[i]+=di;
                tmp[i+1]-=di;
            }else if(tmp[i]>0) {
                tmp[i]-=di;
                tmp[i+1]+=di;
            }
            //cout<<i<<" "<<di<<" "<<tmp[i]<<"\n";
            lRes+=di;
        }
        res=min(res, lRes);
    }

    cout<<res<<endl;
    return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2090 ms 348 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2062 ms 4800 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 Incorrect 0 ms 348 KB Output isn't correct
9 Halted 0 ms 0 KB -