답안 #753700

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753700 2023-06-05T17:47:09 Z epicci23 Alternating Heights (CCO22_day1problem1) C++17
10 / 25
1000 ms 13864 KB
#include "bits/stdc++.h"
#pragma optimize ("Bismillahirrahmanirrahim")
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define endl "\n" 
#define int long long
#define double long double
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define what_is(x) cerr << #x << " is " << x << endl;
//#define m (l+r)/2
constexpr int N=200005;
constexpr int MOD=1000000007;
constexpr int  INF2 = LLONG_MAX;
constexpr int INF=(int)1e18;
constexpr int LOG=30;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
typedef priority_queue<pii,vector<pii>,greater<pii>> min_pq;
typedef priority_queue<pii> max_pq;
typedef long long ll;
//to think//
/*
 * graph approach
 * dp
 * dividing the problem to smaller statements
 * finding the real constraint
 * sqrt decomposition
 * greedy approach
 * pigeonhole principle
 * rewriting the problem/equality 
 * bitwise approaches
 * binary search if monotonic
 * divide and conquer
 * combinatorics
 * inclusion - exclusion
 * think like bfs
*/



inline int in()
{
  int x;cin >> x;
  return x;
}

inline string in2()
{
  string x;cin >> x;
  return x;
}


vector<int> v[3003];
int col[3003];
bool ok=0;

void dfs(int c)
{
  if(ok) return;
  if(col[c]==1) {ok=1;return;}
  if(col[c]==2) return;
  col[c]=1;
  for(int x:v[c]) dfs(x);
  col[c]=2;
}

void solve()
{
  int n=in(),k=in(),q=in();
  int ar[n+2];
  for(int i=1;i<=n;i++) ar[i]=in();
  ar[n+1]=0;
  int xd[n+2];

  for(int i=1;i<=n;i++)
  {
    int l=i,r=n+1;
    while(l<r)
    {
      int mid=(l+r)/2;
      ok=0;
      for(int j=0;j<=k;j++) col[j]=0;
      for(int j=0;j<=k;j++) v[j].clear();
      for(int j=i;j<mid;j++)
      {
        if((j-i)&1) v[ar[j+1]].pb(ar[j]);
        else v[ar[j]].pb(ar[j+1]);
      }
      for(int j=1;j<=k;j++) dfs(j);
      if(ok) r=mid;
      else l=mid+1;
    }
    xd[i]=l;
  }

  for(int i=1;i<=q;i++)
  {
    int u=in(),r=in();
    if(xd[u]<=r) cout << "NO\n";
    else cout << "YES\n";
  }
}

int32_t main(){
   

     cin.tie(0); ios::sync_with_stdio(0);
     cout << fixed <<  setprecision(15);
   
   int t=1;//cin>> t;
 
 for(int i=1;i<=t;i++)
 {
  //  cout << "Case #" << i << ": ";
    solve();
 }
 
 return 0;
}

Compilation message

Main.cpp:2: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    2 | #pragma optimize ("Bismillahirrahmanirrahim")
      |
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 3400 KB Output is correct
2 Correct 183 ms 3400 KB Output is correct
3 Correct 192 ms 12828 KB Output is correct
4 Correct 116 ms 7256 KB Output is correct
5 Correct 133 ms 9332 KB Output is correct
6 Correct 190 ms 12792 KB Output is correct
7 Correct 199 ms 12752 KB Output is correct
8 Correct 210 ms 12892 KB Output is correct
9 Correct 222 ms 12920 KB Output is correct
10 Correct 350 ms 13272 KB Output is correct
11 Correct 507 ms 13864 KB Output is correct
12 Correct 527 ms 13188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 140 ms 3448 KB Output is correct
2 Correct 152 ms 11052 KB Output is correct
3 Correct 149 ms 10956 KB Output is correct
4 Correct 115 ms 8236 KB Output is correct
5 Correct 134 ms 9404 KB Output is correct
6 Correct 148 ms 10920 KB Output is correct
7 Correct 151 ms 11016 KB Output is correct
8 Correct 157 ms 11044 KB Output is correct
9 Correct 164 ms 11404 KB Output is correct
10 Correct 151 ms 11968 KB Output is correct
11 Correct 156 ms 11884 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 602 ms 504 KB Output is correct
3 Correct 658 ms 640 KB Output is correct
4 Correct 37 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 437 ms 504 KB Output is correct
8 Correct 806 ms 588 KB Output is correct
9 Execution timed out 1036 ms 560 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 3400 KB Output is correct
2 Correct 183 ms 3400 KB Output is correct
3 Correct 192 ms 12828 KB Output is correct
4 Correct 116 ms 7256 KB Output is correct
5 Correct 133 ms 9332 KB Output is correct
6 Correct 190 ms 12792 KB Output is correct
7 Correct 199 ms 12752 KB Output is correct
8 Correct 210 ms 12892 KB Output is correct
9 Correct 222 ms 12920 KB Output is correct
10 Correct 350 ms 13272 KB Output is correct
11 Correct 507 ms 13864 KB Output is correct
12 Correct 527 ms 13188 KB Output is correct
13 Correct 140 ms 3448 KB Output is correct
14 Correct 152 ms 11052 KB Output is correct
15 Correct 149 ms 10956 KB Output is correct
16 Correct 115 ms 8236 KB Output is correct
17 Correct 134 ms 9404 KB Output is correct
18 Correct 148 ms 10920 KB Output is correct
19 Correct 151 ms 11016 KB Output is correct
20 Correct 157 ms 11044 KB Output is correct
21 Correct 164 ms 11404 KB Output is correct
22 Correct 151 ms 11968 KB Output is correct
23 Correct 156 ms 11884 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 602 ms 504 KB Output is correct
27 Correct 658 ms 640 KB Output is correct
28 Correct 37 ms 468 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 437 ms 504 KB Output is correct
32 Correct 806 ms 588 KB Output is correct
33 Execution timed out 1036 ms 560 KB Time limit exceeded
34 Halted 0 ms 0 KB -