# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
699028 | 2023-02-15T11:08:40 Z | gghx | Alternating Heights (CCO22_day1problem1) | C++14 | 582 ms | 13980 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long int main(){ ios::sync_with_stdio(0); cin.tie(0); ll n,k,qn; cin>>n>>k>>qn; ll arr[n]; for(int i=0;i<n;i++){ cin>>arr[i]; arr[i]--; } ll rightmost[n]; //the rightmost workable n for(int i=0;i<n;i++) rightmost[i]=i; ll right=0; for(int i=0;i<n;i++){ //check range (i,right+1) while(true){ rightmost[i]=right; if(right>n-1) break; right++; vector<ll> adj[k],adj1[k]; bool bigger=true; bool die=false; for(int j=i;j<right-1;j++){ if(arr[j]==arr[j+1]){ die=true; } if(bigger) adj[arr[j]].push_back(arr[j+1]); else adj[arr[j+1]].push_back(arr[j]); if(bigger) adj1[arr[j+1]].push_back(arr[j]); else adj1[arr[j]].push_back(arr[j+1]); bigger=1-bigger; } if(die==true){ right--; break; } ll indeg[k]; for(int j=0;j<k;j++) indeg[j]=adj[j].size(); queue<ll> q; ll count=0; for(int j=0;j<k;j++){ if(indeg[j]==0){ q.push(j); count++; } } while(!q.empty()){ ll tp=q.front(); q.pop(); for(int j=0;j<adj1[tp].size();j++){ ll neighbour=adj1[tp][j]; if(indeg[neighbour]==0) continue; if(indeg[neighbour]==1){ indeg[neighbour]=0; q.push(neighbour); count++; } else indeg[neighbour]--; } } if(count<k){ right--; break; } } rightmost[i]--; } for(int i=0;i<qn;i++){ ll x,y; cin>>x>>y; x--; y--; if(y<=rightmost[x]) cout<<"YES\n"; else cout<<"NO\n"; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 158 ms | 12692 KB | Output is correct |
2 | Correct | 152 ms | 12632 KB | Output is correct |
3 | Correct | 154 ms | 12848 KB | Output is correct |
4 | Correct | 112 ms | 7160 KB | Output is correct |
5 | Correct | 127 ms | 9164 KB | Output is correct |
6 | Correct | 154 ms | 12672 KB | Output is correct |
7 | Correct | 154 ms | 12704 KB | Output is correct |
8 | Correct | 159 ms | 12912 KB | Output is correct |
9 | Correct | 159 ms | 12732 KB | Output is correct |
10 | Correct | 207 ms | 13248 KB | Output is correct |
11 | Correct | 216 ms | 13772 KB | Output is correct |
12 | Correct | 260 ms | 13016 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 146 ms | 10948 KB | Output is correct |
2 | Correct | 152 ms | 10956 KB | Output is correct |
3 | Correct | 140 ms | 10832 KB | Output is correct |
4 | Correct | 118 ms | 8128 KB | Output is correct |
5 | Correct | 132 ms | 9280 KB | Output is correct |
6 | Correct | 142 ms | 11032 KB | Output is correct |
7 | Correct | 139 ms | 10912 KB | Output is correct |
8 | Correct | 142 ms | 11072 KB | Output is correct |
9 | Correct | 148 ms | 11336 KB | Output is correct |
10 | Correct | 140 ms | 11924 KB | Output is correct |
11 | Correct | 139 ms | 11876 KB | Output is correct |
12 | Correct | 0 ms | 320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 351 ms | 596 KB | Output is correct |
3 | Correct | 387 ms | 612 KB | Output is correct |
4 | Correct | 2 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 324 KB | Output is correct |
7 | Correct | 257 ms | 516 KB | Output is correct |
8 | Correct | 403 ms | 736 KB | Output is correct |
9 | Correct | 561 ms | 588 KB | Output is correct |
10 | Correct | 380 ms | 548 KB | Output is correct |
11 | Correct | 415 ms | 972 KB | Output is correct |
12 | Correct | 318 ms | 636 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 158 ms | 12692 KB | Output is correct |
2 | Correct | 152 ms | 12632 KB | Output is correct |
3 | Correct | 154 ms | 12848 KB | Output is correct |
4 | Correct | 112 ms | 7160 KB | Output is correct |
5 | Correct | 127 ms | 9164 KB | Output is correct |
6 | Correct | 154 ms | 12672 KB | Output is correct |
7 | Correct | 154 ms | 12704 KB | Output is correct |
8 | Correct | 159 ms | 12912 KB | Output is correct |
9 | Correct | 159 ms | 12732 KB | Output is correct |
10 | Correct | 207 ms | 13248 KB | Output is correct |
11 | Correct | 216 ms | 13772 KB | Output is correct |
12 | Correct | 260 ms | 13016 KB | Output is correct |
13 | Correct | 146 ms | 10948 KB | Output is correct |
14 | Correct | 152 ms | 10956 KB | Output is correct |
15 | Correct | 140 ms | 10832 KB | Output is correct |
16 | Correct | 118 ms | 8128 KB | Output is correct |
17 | Correct | 132 ms | 9280 KB | Output is correct |
18 | Correct | 142 ms | 11032 KB | Output is correct |
19 | Correct | 139 ms | 10912 KB | Output is correct |
20 | Correct | 142 ms | 11072 KB | Output is correct |
21 | Correct | 148 ms | 11336 KB | Output is correct |
22 | Correct | 140 ms | 11924 KB | Output is correct |
23 | Correct | 139 ms | 11876 KB | Output is correct |
24 | Correct | 0 ms | 320 KB | Output is correct |
25 | Correct | 0 ms | 212 KB | Output is correct |
26 | Correct | 351 ms | 596 KB | Output is correct |
27 | Correct | 387 ms | 612 KB | Output is correct |
28 | Correct | 2 ms | 340 KB | Output is correct |
29 | Correct | 1 ms | 340 KB | Output is correct |
30 | Correct | 1 ms | 324 KB | Output is correct |
31 | Correct | 257 ms | 516 KB | Output is correct |
32 | Correct | 403 ms | 736 KB | Output is correct |
33 | Correct | 561 ms | 588 KB | Output is correct |
34 | Correct | 380 ms | 548 KB | Output is correct |
35 | Correct | 415 ms | 972 KB | Output is correct |
36 | Correct | 318 ms | 636 KB | Output is correct |
37 | Correct | 582 ms | 13540 KB | Output is correct |
38 | Correct | 521 ms | 13468 KB | Output is correct |
39 | Correct | 150 ms | 12624 KB | Output is correct |
40 | Correct | 118 ms | 8140 KB | Output is correct |
41 | Correct | 131 ms | 9632 KB | Output is correct |
42 | Correct | 450 ms | 13428 KB | Output is correct |
43 | Correct | 561 ms | 13936 KB | Output is correct |
44 | Correct | 433 ms | 13388 KB | Output is correct |
45 | Correct | 540 ms | 13876 KB | Output is correct |
46 | Correct | 537 ms | 13900 KB | Output is correct |
47 | Correct | 546 ms | 13980 KB | Output is correct |