Submission #856118


Source Code Expand

Copy
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX = 100000 + 10;

int rec[MAX];
int tar[MAX];

int go(int x, int y){
  int ret = 0;
  while(x < y){
    x = tar[x];
    ret ++;
  }
  return ret;
}

int main(){
  int n, l;
  scanf("%d", &n);
  
  for(int i = 0 ; i < n ; i++){
    scanf("%d", &rec[i]);
  }

  scanf("%d", &l);
  int ls = 0;
  for(int i = 1 ; i < n ; i++){
    while (rec[i] - rec[ls] > l) {
      tar[ls] = i-1;
      ls++;
    }
  }
  for(int i = ls ; i < n ; i++){
    tar[i] = n;
  }
  
  int q;
  scanf("%d", &q);
  while(q--){
    int p, s;
    scanf("%d %d", &p, &s);
    p--, s--;
    if(p > s) swap(p, s);
    printf("%d\n", go(p,s));
  }

  return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User bigelephant29
Language C++14 (GCC 5.4.1)
Score 200
Code Size 748 Byte
Status TLE
Exec Time 3153 ms
Memory 1408 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:20:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &n);
                  ^
./Main.cpp:23:25: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &rec[i]);
                         ^
./Main.cpp:26:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &l);
                  ^
./Main.cpp:39:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &q);
                  ^
./Main.cpp:42:27: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &p, &s);
                           ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 200 / 200 0 / 500
Status
AC × 1
AC × 14
AC × 21
TLE × 6
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 128 KB
subtask1_01.txt AC 2 ms 128 KB
subtask1_02.txt AC 2 ms 128 KB
subtask1_03.txt AC 3 ms 128 KB
subtask1_04.txt AC 4 ms 128 KB
subtask1_05.txt AC 3 ms 128 KB
subtask1_06.txt AC 3 ms 128 KB
subtask1_07.txt AC 2 ms 128 KB
subtask1_08.txt AC 3 ms 128 KB
subtask1_09.txt AC 3 ms 128 KB
subtask1_10.txt AC 4 ms 128 KB
subtask1_11.txt AC 4 ms 128 KB
subtask1_12.txt AC 3 ms 128 KB
subtask1_13.txt AC 3 ms 128 KB
subtask2_01.txt AC 1654 ms 1408 KB
subtask2_02.txt TLE 3153 ms 1024 KB
subtask2_03.txt AC 502 ms 1280 KB
subtask2_04.txt AC 47 ms 768 KB
subtask2_05.txt AC 808 ms 1024 KB
subtask2_06.txt AC 70 ms 1152 KB
subtask2_07.txt AC 2110 ms 1408 KB
subtask2_08.txt TLE 3153 ms 1152 KB
subtask2_09.txt TLE 3153 ms 1152 KB
subtask2_10.txt TLE 3153 ms 1280 KB
subtask2_11.txt TLE 3153 ms 1152 KB
subtask2_12.txt TLE 3153 ms 1024 KB
subtask2_13.txt AC 70 ms 1152 KB