Submission #855769


Source Code Expand

Copy
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
//typedef long long int LL;
//typedef __int64 LL;

int n, x[100005];
int L;
int dp[18][100005];

void preprocess() {
	int end = n;
	for (int i = n; i >= 1; i--) {
		while (x[end] - x[i] > L) end--;
		dp[0][i] = end;
		for (int j = 1; j <= 17; j++) {
			dp[j][i] = dp[j - 1][dp[j - 1][i]];
		}
	}
}

int query(int a, int b) {
	int ret = 0;
	for (int i = 17; i >= 0; i--) {
		if (dp[i][a] >= b) continue;
		ret += 1 << i;
		a = dp[i][a];
	}
	while (a != b) {
		a = dp[0][a];
		ret++;
	}
	return ret;
}
int main()
{
	int Q, a, b;

	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &x[i]);

	scanf("%d", &L);
	preprocess();
	scanf("%d", &Q);
	for (int i = 1; i <= Q; i++) {
		scanf("%d %d", &a, &b);
		if (a > b) swap(a, b);
		printf("%d\n", query(a, b));
	}
	return 0;
}

Submission Info

Submission Time
Task E - Tak and Hotels
User dragoon
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1889 Byte
Status TLE
Exec Time 3154 ms
Memory 8192 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:79:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
./Main.cpp:80:49: 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:82:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &L);
                 ^
./Main.cpp:84:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
                 ^
./Main.cpp:86:25: 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 × 4
TLE × 10
AC × 5
TLE × 22
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 4 ms 256 KB
subtask1_01.txt TLE 3153 ms 256 KB
subtask1_02.txt AC 4 ms 256 KB
subtask1_03.txt TLE 3153 ms 384 KB
subtask1_04.txt AC 5 ms 384 KB
subtask1_05.txt TLE 3153 ms 384 KB
subtask1_06.txt AC 4 ms 384 KB
subtask1_07.txt TLE 3153 ms 384 KB
subtask1_08.txt TLE 3153 ms 384 KB
subtask1_09.txt TLE 3153 ms 384 KB
subtask1_10.txt TLE 3153 ms 384 KB
subtask1_11.txt TLE 3153 ms 384 KB
subtask1_12.txt TLE 3153 ms 384 KB
subtask1_13.txt TLE 3153 ms 384 KB
subtask2_01.txt TLE 3154 ms 7680 KB
subtask2_02.txt AC 140 ms 8192 KB
subtask2_03.txt TLE 3154 ms 7680 KB
subtask2_04.txt TLE 3154 ms 5120 KB
subtask2_05.txt TLE 3154 ms 5120 KB
subtask2_06.txt TLE 3154 ms 7680 KB
subtask2_07.txt TLE 3154 ms 7680 KB
subtask2_08.txt TLE 3154 ms 7680 KB
subtask2_09.txt TLE 3154 ms 7680 KB
subtask2_10.txt TLE 3154 ms 7680 KB
subtask2_11.txt TLE 3154 ms 7168 KB
subtask2_12.txt TLE 3154 ms 7680 KB
subtask2_13.txt TLE 3154 ms 7680 KB