Submission #935996

# Submission time Handle Problem Language Result Execution time Memory
935996 2024-02-29T21:58:20 Z ZeroCool Safety (NOI18_safety) C++14
100 / 100
210 ms 21052 KB
#define ONLINE_JUDGE // online judge
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
  
#define int long long
  
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
  
  
using ll = long long;
using ld = long double;
  
#define no cout<<"NO"<<endl
#define yes cout<<"YES"<<endl

#define da cout<<"DA"<<endl
#define ne cout<<"NE"<<endl
  
#define send ios::sync_with_stdio(false);
#define help cin.tie(0);
  
void solve(int T);
  
const int N = 505;
const int M = 405;
const int SQRT = sqrt(N);
const int LOG = 20;
const int INF = 1e12;
const int MOD = 998244353;
const ld EPS = 1e-9;
  
  
int ans;
int n, m, q, l, r, x, y, z, mx, mn;
  
  
int32_t main(){
    #ifndef ONLINE_JUDGE
        auto begin = chrono::high_resolution_clock::now();
    #endif
    cout<<setprecision(4)<<fixed;
      
    send help;
  
    int tt = 1;
//  cin>>tt; //? Comment if no testcases
    for(int i = 1;i<=tt;i++){
        #ifndef ONLINE_JUDGE
            cout<<"Case "<<i<<": "<<endl;
        #endif
        solve(i);
    }
    #ifndef ONLINE_JUDGE
        auto end = chrono::high_resolution_clock::now();
        cout<<"Time: "<<chrono::duration_cast<chrono::duration<double>>(end - begin).count()<<endl;
    #endif
    return 0;
}

multiset<int> lefts, rights;


void solve(int T){
    int h;
    cin>>n>>h;
    int x;
    cin>>x;
    lefts.insert(x);
    rights.insert(x);
    int loff = -h, roff = h;
    for(int i = 1;i<n;i++){
        cin>>x;
        l = *lefts.rbegin() + loff;
        r = *rights.begin() + roff;
        if(l >= x){
            ans += l - x;
            rights.insert(l - roff);
            lefts.erase(lefts.find(*lefts.rbegin()));
            lefts.insert(x - loff);
            lefts.insert(x - loff);

        }else if (r >= x){
            lefts.insert(x - loff);
            rights.insert(x - roff);
        }else{
            ans += x - r;
            lefts.insert(r - loff);
            rights.erase(rights.find(*rights.begin()));
            rights.insert(x - roff);
            rights.insert(x - roff);
        }
        loff -= h;
        roff += h;
    }    
    cout<<ans<<endl;
}   

  
  
  
//Te molam da raboti!!
# 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 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 102 ms 12628 KB Output is correct
2 Correct 151 ms 19684 KB Output is correct
3 Correct 197 ms 20540 KB Output is correct
# 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 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
# 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 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 356 KB Output is correct
23 Correct 1 ms 360 KB Output is correct
24 Correct 1 ms 356 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 360 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
# 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 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 356 KB Output is correct
23 Correct 1 ms 360 KB Output is correct
24 Correct 1 ms 356 KB Output is correct
25 Correct 1 ms 360 KB Output is correct
26 Correct 0 ms 360 KB Output is correct
27 Correct 0 ms 460 KB Output is correct
28 Correct 2 ms 872 KB Output is correct
29 Correct 3 ms 1304 KB Output is correct
30 Correct 2 ms 872 KB Output is correct
31 Correct 2 ms 736 KB Output is correct
32 Correct 1 ms 732 KB Output is correct
33 Correct 2 ms 872 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
# 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 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 0 ms 356 KB Output is correct
29 Correct 1 ms 360 KB Output is correct
30 Correct 1 ms 356 KB Output is correct
31 Correct 1 ms 360 KB Output is correct
32 Correct 0 ms 360 KB Output is correct
33 Correct 0 ms 460 KB Output is correct
34 Correct 2 ms 872 KB Output is correct
35 Correct 3 ms 1304 KB Output is correct
36 Correct 2 ms 872 KB Output is correct
37 Correct 2 ms 736 KB Output is correct
38 Correct 1 ms 732 KB Output is correct
39 Correct 2 ms 872 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 2 ms 856 KB Output is correct
42 Correct 2 ms 720 KB Output is correct
43 Correct 2 ms 720 KB Output is correct
44 Correct 2 ms 860 KB Output is correct
45 Correct 2 ms 860 KB Output is correct
46 Correct 2 ms 860 KB Output is correct
# 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 356 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 456 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 102 ms 12628 KB Output is correct
20 Correct 151 ms 19684 KB Output is correct
21 Correct 197 ms 20540 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 356 KB Output is correct
32 Correct 1 ms 360 KB Output is correct
33 Correct 1 ms 356 KB Output is correct
34 Correct 1 ms 360 KB Output is correct
35 Correct 0 ms 360 KB Output is correct
36 Correct 0 ms 460 KB Output is correct
37 Correct 2 ms 872 KB Output is correct
38 Correct 3 ms 1304 KB Output is correct
39 Correct 2 ms 872 KB Output is correct
40 Correct 2 ms 736 KB Output is correct
41 Correct 1 ms 732 KB Output is correct
42 Correct 2 ms 872 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 2 ms 856 KB Output is correct
45 Correct 2 ms 720 KB Output is correct
46 Correct 2 ms 720 KB Output is correct
47 Correct 2 ms 860 KB Output is correct
48 Correct 2 ms 860 KB Output is correct
49 Correct 2 ms 860 KB Output is correct
50 Correct 210 ms 21052 KB Output is correct
51 Correct 144 ms 17564 KB Output is correct
52 Correct 70 ms 16812 KB Output is correct
53 Correct 79 ms 19428 KB Output is correct
54 Correct 94 ms 20064 KB Output is correct
55 Correct 75 ms 17040 KB Output is correct
56 Correct 81 ms 18668 KB Output is correct
57 Correct 73 ms 17316 KB Output is correct
58 Correct 76 ms 14508 KB Output is correct
59 Correct 84 ms 19208 KB Output is correct