답안 #935997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
935997 2024-02-29T21:58:32 Z ZeroCool Safety (NOI18_safety) C++14
100 / 100
153 ms 19088 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!!
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 12568 KB Output is correct
2 Correct 130 ms 17964 KB Output is correct
3 Correct 135 ms 18512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 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 0 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 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 600 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 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 0 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 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 2 ms 860 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 860 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 2 ms 828 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
18 Correct 0 ms 372 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 1 ms 600 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 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 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 2 ms 860 KB Output is correct
35 Correct 2 ms 604 KB Output is correct
36 Correct 2 ms 860 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 2 ms 828 KB Output is correct
40 Correct 2 ms 860 KB Output is correct
41 Correct 3 ms 860 KB Output is correct
42 Correct 2 ms 740 KB Output is correct
43 Correct 2 ms 872 KB Output is correct
44 Correct 2 ms 872 KB Output is correct
45 Correct 1 ms 872 KB Output is correct
46 Correct 1 ms 616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 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 0 ms 348 KB Output is correct
18 Correct 0 ms 372 KB Output is correct
19 Correct 80 ms 12568 KB Output is correct
20 Correct 130 ms 17964 KB Output is correct
21 Correct 135 ms 18512 KB Output is correct
22 Correct 0 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 2 ms 860 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 860 KB Output is correct
40 Correct 1 ms 600 KB Output is correct
41 Correct 1 ms 604 KB Output is correct
42 Correct 2 ms 828 KB Output is correct
43 Correct 2 ms 860 KB Output is correct
44 Correct 3 ms 860 KB Output is correct
45 Correct 2 ms 740 KB Output is correct
46 Correct 2 ms 872 KB Output is correct
47 Correct 2 ms 872 KB Output is correct
48 Correct 1 ms 872 KB Output is correct
49 Correct 1 ms 616 KB Output is correct
50 Correct 153 ms 19088 KB Output is correct
51 Correct 106 ms 15956 KB Output is correct
52 Correct 64 ms 15196 KB Output is correct
53 Correct 77 ms 17748 KB Output is correct
54 Correct 82 ms 18276 KB Output is correct
55 Correct 65 ms 15560 KB Output is correct
56 Correct 86 ms 16972 KB Output is correct
57 Correct 66 ms 15700 KB Output is correct
58 Correct 71 ms 13584 KB Output is correct
59 Correct 80 ms 17316 KB Output is correct