제출 #1306764

#제출 시각아이디문제언어결과실행 시간메모리
1306764muhammad-mutahirAlternating Heights (CCO22_day1problem1)C++20
25 / 25
974 ms4616 KiB
#include <bits/stdc++.h> using namespace std; #define print(l) for(auto i:l) cout<<i<<" ";cout<<endl; #define input(t,l,n) vector<t>l(n);for(int i = 0;i<n;i++)cin>>l[i]; // #define int long long #define pb push_back #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define all(l) l.begin(),l.end() #define pii pair<int,int> #define fi first #define se second const int M = 1e9+7; const int inf = 1e18; int bp(int x, int y, int p){ int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } int MI(int n, int p){ return bp(n, p - 2, p); } int mul(int x,int y, int p){ return x * 1ull * y % p; } int di(int x,int y, int p){ return mul(x, MI(y, p), p); } int n , m , k , q; vector<vector<int>>adj; vector<int>ind; bool ck0(){ vector<int>ind1(k+1,0); queue<int>Q; // vis[scr] = 1; int tot = 0; int vi = 0; for(int i = 1;i<=k;i++){ if(ind[i] == 0){ // vis[i+1] = 1; Q.push(i); } tot++; } while(Q.size()){ int u = Q.front(); Q.pop(); vi++; for(int v :adj[u]){ ind1[v]++; if(ind1[v] == ind[v]){ // vis[v] = 1; Q.push(v); } } } return tot!=vi; } void solve(int testcase_number){ cin>>n>>k>>q; input(int,a,n); vector<int>maxl(n+1,1); for(int i = 0;i<n;i++){ int ans = maxl[i]; adj.clear(); adj.resize(n+1); ind.clear(); ind.resize(k+1,0); int lasj = i-1; for(int j = i;j +1< i+maxl[i];j++){ if(j%2 == i%2) { adj[a[j]].pb(a[j+1]); ind[a[j+1]]++; ind[a[j]] = ind[a[j]]; } else{ adj[a[j+1]].pb(a[j]); ind[a[j+1]] = ind[a[j+1]]; ind[a[j]]++; } lasj = j; } for(int j = lasj+1;j+1<n;j++){ if(j%2 == i%2) { adj[a[j]].pb(a[j+1]); ind[a[j+1]]++; ind[a[j]] = ind[a[j]]; } else{ adj[a[j+1]].pb(a[j]); ind[a[j+1]] = ind[a[j+1]]; ind[a[j]]++; } if(ck0()){ break; } ans++; } // cout<<ans<<endl; int jj = i; while(jj<n){ // cout<<jj<<" "<<ans<<endl; maxl[jj] = max(ans,maxl[jj]); jj++; ans--; } } // print(maxl); for(int i = 0;i<q;i++){ int l,r; cin>>l>>r; l--; if(l+maxl[l] >= r){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } } } signed main(){ ios::sync_with_stdio(0);//DO NOT USE IN INTERACTIVE cin.tie(0), cout.tie(0); cout << fixed<<setprecision(9); int t = 1; // cin>>t; for(int i = 1;i<=t;i++){ solve(i); } }

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp:15:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   15 | const int inf = 1e18;
      |                 ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...