Submission #559493

# Submission time Handle Problem Language Result Execution time Memory
559493 2022-05-10T04:28:14 Z Amylopectin Safety (NOI18_safety) C++14
100 / 100
63 ms 5452 KB
#include <iostream>
#include <stdio.h>
#include <vector>
#include <queue>
using namespace std;
const int mxn = 8e5 + 10;
struct cmple
{
    bool operator () (const long long &l,const long long &r)
    {
        return l < r;
    }
};
struct cmpri
{
    bool operator () (const long long &l,const long long &r)
    {
        return l > r;
    }
};
priority_queue<long long, vector<long long>, cmple> lef;
priority_queue<long long, vector<long long>, cmpri> rig;
int main()
{
    long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
    scanf("%lld %lld",&n,&h);
    for(i=0; i<n; i++)
    {
        scanf("%lld",&ch);
        if(i == 0)
        {
            lef.push(ch);
            rig.push(ch);
        }
        else
        {
            sh = h * i;
            lpo = lef.top() - sh;
            rpo = rig.top() + sh;
            if(ch < lpo)
            {
                rig.push(lpo - sh);
                lef.push(ch + sh);
                lef.push(ch + sh);
                lef.pop();
                ans += lpo - ch;
            }
            else if(ch > rpo)
            {
                lef.push(rpo + sh);
                rig.push(ch - sh);
                rig.push(ch - sh);
                rig.pop();
                ans += ch - rpo;
            }
            else
            {
                lef.push(ch + sh);
                rig.push(ch - sh);
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Compilation message

safety.cpp: In function 'int main()':
safety.cpp:25:17: warning: unused variable 'j' [-Wunused-variable]
   25 |     long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
      |                 ^
safety.cpp:25:21: warning: unused variable 'm' [-Wunused-variable]
   25 |     long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
      |                     ^
safety.cpp:25:25: warning: unused variable 'k' [-Wunused-variable]
   25 |     long long i,j,n,m,h,k,ch,lpo,rpo,sh,ans = 0;
      |                         ^
safety.cpp:26:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 |     scanf("%lld %lld",&n,&h);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
safety.cpp:29:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |         scanf("%lld",&ch);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 1 ms 308 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 4704 KB Output is correct
2 Correct 53 ms 5160 KB Output is correct
3 Correct 63 ms 5320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 296 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 3 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 396 KB Output is correct
32 Correct 1 ms 440 KB Output is correct
33 Correct 2 ms 468 KB Output is correct
34 Correct 2 ms 396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 296 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 2 ms 468 KB Output is correct
35 Correct 3 ms 468 KB Output is correct
36 Correct 2 ms 468 KB Output is correct
37 Correct 1 ms 396 KB Output is correct
38 Correct 1 ms 440 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 2 ms 396 KB Output is correct
41 Correct 2 ms 436 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 2 ms 468 KB Output is correct
44 Correct 2 ms 468 KB Output is correct
45 Correct 2 ms 440 KB Output is correct
46 Correct 2 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 296 KB Output is correct
5 Correct 1 ms 292 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 40 ms 4704 KB Output is correct
20 Correct 53 ms 5160 KB Output is correct
21 Correct 63 ms 5320 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 296 KB Output is correct
35 Correct 1 ms 212 KB Output is correct
36 Correct 1 ms 212 KB Output is correct
37 Correct 2 ms 468 KB Output is correct
38 Correct 3 ms 468 KB Output is correct
39 Correct 2 ms 468 KB Output is correct
40 Correct 1 ms 396 KB Output is correct
41 Correct 1 ms 440 KB Output is correct
42 Correct 2 ms 468 KB Output is correct
43 Correct 2 ms 396 KB Output is correct
44 Correct 2 ms 436 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 2 ms 468 KB Output is correct
47 Correct 2 ms 468 KB Output is correct
48 Correct 2 ms 440 KB Output is correct
49 Correct 2 ms 428 KB Output is correct
50 Correct 58 ms 5452 KB Output is correct
51 Correct 55 ms 4924 KB Output is correct
52 Correct 39 ms 5048 KB Output is correct
53 Correct 42 ms 5196 KB Output is correct
54 Correct 54 ms 5168 KB Output is correct
55 Correct 33 ms 5048 KB Output is correct
56 Correct 37 ms 5068 KB Output is correct
57 Correct 34 ms 5084 KB Output is correct
58 Correct 40 ms 4496 KB Output is correct
59 Correct 45 ms 4936 KB Output is correct