Submission #856081


Source Code Expand

Copy
#include <stdio.h>

int dp[20][100005];
int x[100005];

int main(){
    int N;
    scanf("%d", &N);
    for(int i=1; i<=N; i++) scanf("%d", &x[i]);
    int L, Q;
    scanf("%d%d", &L, &Q);
    int ptr=1;
    for(int i=1; i<=N; i++){
        while(x[i]-x[ptr] > L) ptr++;
        dp[0][i] = ptr;
    }
    for(int i=1; i<20; i++){
        for(int j=1; j<=N; j++){
            dp[i][j] = dp[i-1][dp[i-1][j]];
        }
    }
    for(int query=0; query<Q; query++){
        int a, b;
        scanf("%d%d", &a, &b);
        if(b < a){
            int temp = b;
            b = a;
            a = temp;
        }
        int res=0;
        while(b > a){
            if(dp[0][b] <= a){
                res += 1;
                break;
            }
            for(int i=0; i<19; i++){
                if(dp[i+1][b] < a || dp[i][b] == a){
                    b = dp[i][b];
                    res += (1<<i);
                    break;
                }
            }
        }
        printf("%d\n", res);
    }
    return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User zoomswk
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1067 Byte
Status WA
Exec Time 161 ms
Memory 8960 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:8:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
                    ^
./Main.cpp:9:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=N; i++) scanf("%d", &x[i]);
                                               ^
./Main.cpp:11:26: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &L, &Q);
                          ^
./Main.cpp:24:30: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &a, &b);
                              ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 0 / 200 0 / 500
Status
AC × 1
AC × 5
WA × 9
AC × 11
WA × 16
Set Name Test Cases
Sample example_01.txt
Subtask1 example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt
All example_01.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt, subtask2_13.txt
Case Name Status Exec Time Memory
example_01.txt AC 2 ms 256 KB
subtask1_01.txt WA 2 ms 256 KB
subtask1_02.txt AC 2 ms 256 KB
subtask1_03.txt WA 3 ms 256 KB
subtask1_04.txt WA 3 ms 256 KB
subtask1_05.txt WA 3 ms 256 KB
subtask1_06.txt WA 3 ms 256 KB
subtask1_07.txt WA 3 ms 256 KB
subtask1_08.txt AC 3 ms 256 KB
subtask1_09.txt AC 3 ms 256 KB
subtask1_10.txt WA 3 ms 256 KB
subtask1_11.txt WA 3 ms 256 KB
subtask1_12.txt AC 3 ms 256 KB
subtask1_13.txt WA 3 ms 256 KB
subtask2_01.txt AC 140 ms 8832 KB
subtask2_02.txt WA 161 ms 8960 KB
subtask2_03.txt WA 116 ms 8704 KB
subtask2_04.txt AC 56 ms 5760 KB
subtask2_05.txt WA 84 ms 5888 KB
subtask2_06.txt AC 82 ms 8576 KB
subtask2_07.txt WA 137 ms 8832 KB
subtask2_08.txt AC 156 ms 8960 KB
subtask2_09.txt WA 156 ms 8960 KB
subtask2_10.txt WA 157 ms 8960 KB
subtask2_11.txt AC 151 ms 8320 KB
subtask2_12.txt WA 96 ms 8960 KB
subtask2_13.txt AC 85 ms 8576 KB