Submission #125291

# Submission time Handle Problem Language Result Execution time Memory
125291 2019-07-05T04:50:01 Z 임유진(#3061) Long Mansion (JOI17_long_mansion) C++14
10 / 100
222 ms 6396 KB
#include <stdio.h>
#include<vector>

using namespace std;

#define MAXN 5005
#define MAXQ 500005

vector<int> A[MAXN];
int B[MAXN], C[MAXN];
int X[MAXQ], Y[MAXQ];
int L[MAXN], R[MAXN];
bool key[MAXN];

int main() {
	int N, Q;

	scanf("%d", &N);
	for(int i = 0; i < N - 1; i++) scanf("%d", C + i);
	for(int i = 0; i < N; i++) {
		scanf("%d", B + i);
		int t;
		for(int j = 0; j < B[i]; j++) {
			scanf("%d", &t);
			A[i].push_back(t);
		}
	}
	scanf("%d", &Q);
	for(int i = 0; i < Q; i++) scanf("%d%d", X + i, Y + i);

	for(int i = 0; i < Q; i++) {
		X[i]--;
		Y[i]--;
	}

	for(int i = 0; i < N; i++) {
		L[i] = R[i] = i;
		for(int i = 0; i < N; i++) key[i] = false;
		for(auto a : A[i]) key[a] = true;
		while(true) {
			if(L[i] > 0 && key[C[L[i] - 1]]) {
				L[i]--;
				for(auto a : A[L[i]]) key[a] = true;
			}
			else if(R[i] < N - 1 && key[C[R[i]]]) {
				R[i]++;
				for(auto a : A[R[i]]) key[a] = true;
			}
			else break;
		}
	}

	//for(int i = 0; i < N; i++) printf("L = %d, R = %d\n", L[i], R[i]);

	for(int i = 0; i < Q; i++) {
		if(L[X[i]] <= Y[i] && Y[i] <= R[X[i]]) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Compilation message

long_mansion.cpp: In function 'int main()':
long_mansion.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:19:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < N - 1; i++) scanf("%d", C + i);
                                 ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:21:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", B + i);
   ~~~~~^~~~~~~~~~~~~
long_mansion.cpp:24:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &t);
    ~~~~~^~~~~~~~~~
long_mansion.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &Q);
  ~~~~~^~~~~~~~~~
long_mansion.cpp:29:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0; i < Q; i++) scanf("%d%d", X + i, Y + i);
                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 632 KB Output is correct
2 Correct 34 ms 632 KB Output is correct
3 Correct 87 ms 760 KB Output is correct
4 Correct 7 ms 632 KB Output is correct
5 Correct 45 ms 632 KB Output is correct
6 Correct 13 ms 632 KB Output is correct
7 Correct 11 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 632 KB Output is correct
2 Correct 34 ms 632 KB Output is correct
3 Correct 87 ms 760 KB Output is correct
4 Correct 7 ms 632 KB Output is correct
5 Correct 45 ms 632 KB Output is correct
6 Correct 13 ms 632 KB Output is correct
7 Correct 11 ms 632 KB Output is correct
8 Correct 146 ms 6020 KB Output is correct
9 Correct 142 ms 5956 KB Output is correct
10 Correct 172 ms 6128 KB Output is correct
11 Correct 222 ms 6392 KB Output is correct
12 Correct 139 ms 6196 KB Output is correct
13 Correct 129 ms 6212 KB Output is correct
14 Correct 129 ms 6176 KB Output is correct
15 Correct 146 ms 6264 KB Output is correct
16 Correct 167 ms 6392 KB Output is correct
17 Correct 128 ms 6264 KB Output is correct
18 Correct 129 ms 6252 KB Output is correct
19 Correct 134 ms 6296 KB Output is correct
20 Correct 162 ms 6392 KB Output is correct
21 Correct 167 ms 6396 KB Output is correct
22 Correct 144 ms 6264 KB Output is correct
23 Correct 143 ms 6008 KB Output is correct
24 Correct 145 ms 6008 KB Output is correct
25 Correct 144 ms 6164 KB Output is correct
26 Correct 139 ms 6012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 6 ms 504 KB Time limit exceeded (wall clock)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 632 KB Output is correct
2 Correct 34 ms 632 KB Output is correct
3 Correct 87 ms 760 KB Output is correct
4 Correct 7 ms 632 KB Output is correct
5 Correct 45 ms 632 KB Output is correct
6 Correct 13 ms 632 KB Output is correct
7 Correct 11 ms 632 KB Output is correct
8 Correct 146 ms 6020 KB Output is correct
9 Correct 142 ms 5956 KB Output is correct
10 Correct 172 ms 6128 KB Output is correct
11 Correct 222 ms 6392 KB Output is correct
12 Correct 139 ms 6196 KB Output is correct
13 Correct 129 ms 6212 KB Output is correct
14 Correct 129 ms 6176 KB Output is correct
15 Correct 146 ms 6264 KB Output is correct
16 Correct 167 ms 6392 KB Output is correct
17 Correct 128 ms 6264 KB Output is correct
18 Correct 129 ms 6252 KB Output is correct
19 Correct 134 ms 6296 KB Output is correct
20 Correct 162 ms 6392 KB Output is correct
21 Correct 167 ms 6396 KB Output is correct
22 Correct 144 ms 6264 KB Output is correct
23 Correct 143 ms 6008 KB Output is correct
24 Correct 145 ms 6008 KB Output is correct
25 Correct 144 ms 6164 KB Output is correct
26 Correct 139 ms 6012 KB Output is correct
27 Execution timed out 6 ms 504 KB Time limit exceeded (wall clock)
28 Halted 0 ms 0 KB -