Submission #5855964


Source Code Expand

Copy
#include<bits/stdc++.h>
using namespace std;

const int MN = 200010;

int N, M;
int A[MN], X[MN], psum[MN];

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N - 1; i++) {
        scanf("%d", &A[i]);
    }

    scanf("%d", &M);

    for(int i = 0; i < M; i++) {
        scanf("%d", &X[i]);
    }

    for(int i = 0; i < N - 1; i++) {
        psum[i] = A[i];
        if(i) psum[i] += psum[i - 1];
    }

    if(N == 3) {
        for(int i = 0; i < M; i++) {
            printf("%d\n", X[i] + A[0] - A[1]);
        }
        return 0;
    }

    deque<int> dq;
    for(int i = 0; i >= -psum[1]; i--) dq.push_front(i);

    for(int i = 3; i < N - 1; i++) {
        vector<int> add;
        int q = 1;
        for(int j = -psum[i - 2] - 1; j >= -psum[i - 1]; j--) {
            if(dq.size() <= q) add.push_back(q + 1 - (int)dq.size());
            else add.push_back(dq[q]);
            q++;
        }
        for(int j = 0; j < add.size(); j++) dq.push_front(add[j]);
    }

    for(int i = 0; i < M; i++) {
        int t = X[i] - psum[N - 2];
        if(t < -psum[N - 3]) t = -2 * psum[N - 3] - t;
        t += psum[N - 3];

        printf("%d\n", (t < dq.size()? dq[t] : t + 1 - (int)dq.size()) + psum[1] + A[0] - A[1]);
    }
}

Submission Info

Submission Time
Task H - Tokaido
User choikiwon
Language C++14 (GCC 5.4.1)
Score 1600
Code Size 1292 Byte
Status
Exec Time 99 ms
Memory 10608 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:10:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
./Main.cpp:13:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &A[i]);
                           ^
./Main.cpp:16:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &M);
                    ^
./Main.cpp:19:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &X[i]);
                           ^

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt
dataset1 700 / 700 sample-01.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt
dataset2 900 / 900 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt 55 ms 5888 KB
01-02.txt 1 ms 256 KB
01-03.txt 13 ms 4736 KB
01-04.txt 38 ms 5120 KB
01-05.txt 55 ms 5888 KB
01-06.txt 55 ms 5888 KB
01-07.txt 30 ms 4736 KB
01-08.txt 53 ms 5888 KB
01-09.txt 53 ms 5888 KB
01-10.txt 12 ms 6004 KB
01-11.txt 16 ms 7920 KB
01-12.txt 35 ms 8660 KB
01-13.txt 36 ms 7356 KB
01-14.txt 36 ms 9068 KB
01-15.txt 36 ms 9324 KB
01-16.txt 27 ms 9840 KB
01-17.txt 23 ms 5888 KB
01-18.txt 23 ms 5888 KB
01-19.txt 22 ms 5888 KB
02-01.txt 29 ms 4992 KB
02-02.txt 98 ms 8576 KB
02-03.txt 97 ms 9088 KB
02-04.txt 99 ms 7040 KB
02-05.txt 53 ms 6016 KB
02-06.txt 92 ms 7040 KB
02-07.txt 94 ms 7296 KB
02-08.txt 55 ms 8008 KB
02-09.txt 54 ms 8500 KB
02-10.txt 66 ms 9324 KB
02-11.txt 78 ms 9324 KB
02-12.txt 77 ms 9456 KB
02-13.txt 78 ms 9328 KB
02-14.txt 68 ms 10608 KB
02-15.txt 65 ms 8192 KB
02-16.txt 65 ms 8192 KB
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB