Submission #983189

# Submission time Handle Problem Language Result Execution time Memory
983189 2024-05-15T09:09:51 Z Muhammad_Aneeq Game (APIO22_game) C++17
Compilation error
0 ms 0 KB
// #include "game.h"
#include <vector>
#include <set>
using namespace std;
int N,K;
int const MAXN=300000+10;
set<int>nei[MAXN]={};
bool vis[MAXN]={};
int cur=1;
bool pre[N]={};
void init(int n, int k) 
{
  N=n,K=k;
  for (int i=0;i<k-1;i++)
    nei[i].insert(i+1);
}
vector<int>p;
bool check_cycle(int n)
{
  vis[n]=cur;
  pre[n]=1;
  p.push_back(n);
  for (auto i:nei[n])
  {
    if (vis[i]==cur&&pre[i])
    {
      bool w=0;
      for (int j=p.size()-1;j>=0;j--)
      {
        if (p[j]==i)
          break;
        w=(w||(p[j]<K));
      }
      if (w)
        return 1;
    }
    if (vis[i])
      continue;
    if (check_cycle(i))
      return 1;
  }
  p.pop_back();
  pre[n]=0;
  return 0;
}
int add_teleporter(int u, int v) 
{
  nei[u].insert(v);
  cur=1;
  for (int i=0;i<N;i++)
    vis[i]=0;
  for (int i=0;i<K;i++)
  {
    if (vis[i]==0)
    {
      p={};
      if (check_cycle(i))
        return 1;
    } 
    cur++;
  }
  return 0;
}

Compilation message

game.cpp:10:11: error: array bound is not an integer constant before ']' token
   10 | bool pre[N]={};
      |           ^
game.cpp: In function 'bool check_cycle(int)':
game.cpp:21:3: error: 'pre' was not declared in this scope
   21 |   pre[n]=1;
      |   ^~~