Submission #1072119

# Submission time Handle Problem Language Result Execution time Memory
1072119 2024-08-23T14:36:36 Z vjudge1 Alternating Heights (CCO22_day1problem1) C++14
25 / 25
378 ms 14164 KB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int MAXN = 3000;
 
int N, K, Q;
int A[MAXN+10], ans[MAXN+10];
 
int vis[MAXN+10];
vector<int> adj[MAXN+10];
bool dfs(int now)
{
	vis[now]=1;
	bool ret=false;
	for(auto nxt : adj[now])
	{
		if(vis[nxt]==1) return true;
		if(vis[nxt]==0) ret|=dfs(nxt);
	}
	vis[now]=2;
	return ret;
}
 
bool f(int l, int r)
{
	for(int i=l; i<r; i++)
	{
		if(i%2==l%2) adj[A[i+1]].push_back(A[i]);
		else adj[A[i]].push_back(A[i+1]);
	}
 
	bool ret=false;
	for(int i=1; i<=K; i++) if(!vis[i]) ret|=dfs(i);
 
	for(int i=1; i<=K; i++)
	{
		adj[i].clear(), adj[i].shrink_to_fit();
		vis[i]=0;
	}
	return !ret;
}
 
int main()
{
	scanf("%d%d%d", &N, &K, &Q);
	for(int i=1; i<=N; i++) scanf("%d", &A[i]);
 
	for(int i=N; i>=1; i--)
	{
		int pos=N;
		if(i+2<=N) pos=ans[i+2];
		for(; pos>=i && !f(i, pos); pos--) ;
		ans[i]=pos;
	}
 
	while(Q--)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		if(ans[x]>=y) printf("YES\n");
		else printf("NO\n");
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  scanf("%d%d%d", &N, &K, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
Main.cpp:50:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  for(int i=1; i<=N; i++) scanf("%d", &A[i]);
      |                          ~~~~~^~~~~~~~~~~~~
Main.cpp:63:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 129 ms 12884 KB Output is correct
2 Correct 131 ms 12884 KB Output is correct
3 Correct 131 ms 12804 KB Output is correct
4 Correct 122 ms 7252 KB Output is correct
5 Correct 115 ms 9300 KB Output is correct
6 Correct 130 ms 12884 KB Output is correct
7 Correct 132 ms 12884 KB Output is correct
8 Correct 132 ms 13068 KB Output is correct
9 Correct 155 ms 12912 KB Output is correct
10 Correct 143 ms 13400 KB Output is correct
11 Correct 166 ms 14164 KB Output is correct
12 Correct 180 ms 13136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 118 ms 11092 KB Output is correct
2 Correct 147 ms 11092 KB Output is correct
3 Correct 125 ms 11092 KB Output is correct
4 Correct 100 ms 8272 KB Output is correct
5 Correct 114 ms 9556 KB Output is correct
6 Correct 121 ms 11120 KB Output is correct
7 Correct 119 ms 11092 KB Output is correct
8 Correct 119 ms 11092 KB Output is correct
9 Correct 135 ms 11376 KB Output is correct
10 Correct 141 ms 12088 KB Output is correct
11 Correct 134 ms 12004 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 182 ms 568 KB Output is correct
3 Correct 155 ms 560 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 133 ms 348 KB Output is correct
8 Correct 176 ms 348 KB Output is correct
9 Correct 168 ms 596 KB Output is correct
10 Correct 189 ms 348 KB Output is correct
11 Correct 161 ms 580 KB Output is correct
12 Correct 282 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 129 ms 12884 KB Output is correct
2 Correct 131 ms 12884 KB Output is correct
3 Correct 131 ms 12804 KB Output is correct
4 Correct 122 ms 7252 KB Output is correct
5 Correct 115 ms 9300 KB Output is correct
6 Correct 130 ms 12884 KB Output is correct
7 Correct 132 ms 12884 KB Output is correct
8 Correct 132 ms 13068 KB Output is correct
9 Correct 155 ms 12912 KB Output is correct
10 Correct 143 ms 13400 KB Output is correct
11 Correct 166 ms 14164 KB Output is correct
12 Correct 180 ms 13136 KB Output is correct
13 Correct 118 ms 11092 KB Output is correct
14 Correct 147 ms 11092 KB Output is correct
15 Correct 125 ms 11092 KB Output is correct
16 Correct 100 ms 8272 KB Output is correct
17 Correct 114 ms 9556 KB Output is correct
18 Correct 121 ms 11120 KB Output is correct
19 Correct 119 ms 11092 KB Output is correct
20 Correct 119 ms 11092 KB Output is correct
21 Correct 135 ms 11376 KB Output is correct
22 Correct 141 ms 12088 KB Output is correct
23 Correct 134 ms 12004 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 182 ms 568 KB Output is correct
27 Correct 155 ms 560 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 133 ms 348 KB Output is correct
32 Correct 176 ms 348 KB Output is correct
33 Correct 168 ms 596 KB Output is correct
34 Correct 189 ms 348 KB Output is correct
35 Correct 161 ms 580 KB Output is correct
36 Correct 282 ms 576 KB Output is correct
37 Correct 378 ms 13376 KB Output is correct
38 Correct 307 ms 13396 KB Output is correct
39 Correct 135 ms 12884 KB Output is correct
40 Correct 100 ms 8308 KB Output is correct
41 Correct 120 ms 9812 KB Output is correct
42 Correct 302 ms 13400 KB Output is correct
43 Correct 364 ms 13652 KB Output is correct
44 Correct 299 ms 13396 KB Output is correct
45 Correct 253 ms 13912 KB Output is correct
46 Correct 328 ms 13904 KB Output is correct
47 Correct 260 ms 13908 KB Output is correct