Submission #568684

# Submission time Handle Problem Language Result Execution time Memory
568684 2022-05-26T04:56:01 Z dantoh000 Snowball (JOI21_ho_t2) C++14
0 / 100
2 ms 468 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n,q;
int p[200005];
int D[200005];
int l[200005];
int r[200005];
int pos[200005];
int ans[200005];
main(){
    scanf("%lld%lld",&n,&q);
    for (int i = 1; i <= n; i++){
        scanf("%lld",&p[i]);
    }
    int cur = 0;
    l[0] = r[0] = D[0] = 0;
    for (int i = 1, x; i <= q; i++){
        scanf("%lld",&x);
        cur += x;
        l[i] = min(l[i-1], cur);
        r[i] = max(r[i-1], cur);
        D[i] = r[i]-l[i];
        pos[i] = cur;
    }
    ans[1] += -l[q];
    ans[n] += r[q];
    for (int i = 1; i <= n; i++){
        int d = p[i+1]-p[i];
        int id = lower_bound(D, D+q, d) - D;

        int L = -l[id];
        int R = r[id];
        if (pos[id] == l[id]) L = min(L, max(0ll,d - R));
        else if (pos[id] == r[id]) R = min(R, max(0ll,d - L));
        ///printf("position %d moves %d left, position %d moves %d right\n",i+1,L,i,R);
        ans[i] += R;
        ans[i+1] += L;
    }
    for (int i = 1; i <= n; i++){
        printf("%lld\n",ans[i]);
    }


}

Compilation message

Main.cpp:11:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   11 | main(){
      | ^~~~
Main.cpp: In function 'int main()':
Main.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%lld%lld",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:14:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |         scanf("%lld",&p[i]);
      |         ~~~~~^~~~~~~~~~~~~~
Main.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         scanf("%lld",&x);
      |         ~~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Incorrect 2 ms 452 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 448 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 2 ms 468 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 444 KB Output is correct
10 Incorrect 2 ms 452 KB Output isn't correct
11 Halted 0 ms 0 KB -