Submission #91622

# Submission time Handle Problem Language Result Execution time Memory
91622 2018-12-28T17:04:35 Z model_code Safety (NOI18_safety) C++14
100 / 100
304 ms 21268 KB
#include <iostream>
#include <algorithm>
#include <set>
#include <functional>
using namespace std;
multiset<long long,greater<long long>> lefts;
multiset<long long,less<long long>> rights;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,h;
    cin>>n>>h;
    {
        int x;
        cin>>x;
        lefts.insert(x);
        rights.insert(x);
    }
    long long minval=0;
    for(int i=1;i<n;++i){
        int x;
        cin>>x;
        long long shift=static_cast<long long>(i)*h;
        auto leftborder=lefts.begin();
        long long leftborderval=*leftborder-shift;
        auto rightborder=rights.begin();
        long long rightborderval=*rightborder+shift;
        if(x<leftborderval){
            auto hint=lefts.insert(x+shift);
            lefts.insert(hint,x+shift);
            lefts.erase(leftborder);
            rights.insert(rightborder,leftborderval-shift);
            minval+=abs(leftborderval-x);
        }
        else if(x>rightborderval){
            auto hint=rights.insert(x-shift);
            rights.insert(hint,x-shift);
            rights.erase(rightborder);
            lefts.insert(leftborder,rightborderval+shift);
            minval+=abs(rightborderval-x);
        }
        else{
            lefts.insert(leftborder,x+shift);
            rights.insert(rightborder,x-shift);
        }
    }
    cout<<minval<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 252 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 12648 KB Output is correct
2 Correct 260 ms 19680 KB Output is correct
3 Correct 304 ms 20600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 420 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 380 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 3 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 420 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 5 ms 888 KB Output is correct
29 Correct 5 ms 760 KB Output is correct
30 Correct 5 ms 760 KB Output is correct
31 Correct 4 ms 760 KB Output is correct
32 Correct 4 ms 760 KB Output is correct
33 Correct 2 ms 760 KB Output is correct
34 Correct 5 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 380 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 420 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 5 ms 888 KB Output is correct
35 Correct 5 ms 760 KB Output is correct
36 Correct 5 ms 760 KB Output is correct
37 Correct 4 ms 760 KB Output is correct
38 Correct 4 ms 760 KB Output is correct
39 Correct 2 ms 760 KB Output is correct
40 Correct 5 ms 888 KB Output is correct
41 Correct 6 ms 888 KB Output is correct
42 Correct 5 ms 760 KB Output is correct
43 Correct 5 ms 760 KB Output is correct
44 Correct 5 ms 848 KB Output is correct
45 Correct 4 ms 760 KB Output is correct
46 Correct 4 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 252 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 168 ms 12648 KB Output is correct
20 Correct 260 ms 19680 KB Output is correct
21 Correct 304 ms 20600 KB Output is correct
22 Correct 3 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 380 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 3 ms 376 KB Output is correct
30 Correct 3 ms 376 KB Output is correct
31 Correct 2 ms 376 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 3 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 2 ms 420 KB Output is correct
36 Correct 2 ms 376 KB Output is correct
37 Correct 5 ms 888 KB Output is correct
38 Correct 5 ms 760 KB Output is correct
39 Correct 5 ms 760 KB Output is correct
40 Correct 4 ms 760 KB Output is correct
41 Correct 4 ms 760 KB Output is correct
42 Correct 2 ms 760 KB Output is correct
43 Correct 5 ms 888 KB Output is correct
44 Correct 6 ms 888 KB Output is correct
45 Correct 5 ms 760 KB Output is correct
46 Correct 5 ms 760 KB Output is correct
47 Correct 5 ms 848 KB Output is correct
48 Correct 4 ms 760 KB Output is correct
49 Correct 4 ms 760 KB Output is correct
50 Correct 287 ms 21268 KB Output is correct
51 Correct 228 ms 17500 KB Output is correct
52 Correct 85 ms 16764 KB Output is correct
53 Correct 87 ms 19576 KB Output is correct
54 Correct 118 ms 20188 KB Output is correct
55 Correct 87 ms 17060 KB Output is correct
56 Correct 80 ms 18808 KB Output is correct
57 Correct 75 ms 17272 KB Output is correct
58 Correct 86 ms 14588 KB Output is correct
59 Correct 110 ms 19064 KB Output is correct