답안 #745275

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745275 2023-05-19T17:21:47 Z speedyArda 게임 (APIO22_game) C++17
0 / 100
209 ms 262144 KB
#include "game.h"
#include "bits/stdc++.h"
using namespace std;
const int MAXN = 3e4+5;
const int MAXK = 1e3+5;
vector< vector<int> > adj(MAXN);
bool visited[MAXN][MAXK];
int ans = 0;
int special = 0;
void dfs(int v, int x)
{
  visited[v][x] = true;
  if(v <= x) // v is also a special node in this case, as we know x is special and all specials are 0, 1, 2 .... k - 1
    ans = 1; // Came to smaller special node so we can go v -> x and repeat the cycle
  for(int e : adj[v])
  {
    if(visited[e][x])
      continue;
    dfs(e, v);
  }
}

void init(int n, int k) {
  special = k;
  for(int i = 0; i < n; i++)
    adj[i].clear();
  for(int i = 0; i <= k - 2; i++)
  {
    adj[i].push_back(i + 1);
  }
  for(int i = 0; i < k - 1; i++)
    dfs(i + 1, i); // if we do i, i then it will trigger if(v <= x) in the dfs false.
} 

int add_teleporter(int u, int v) {
  adj[u].push_back(v);
  for(int i = 0; i < special; i++)
  {
    if((u == i || visited[u][i]) && !visited[v][i])
      dfs(v, i);
  }
  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Runtime error 209 ms 262144 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Runtime error 209 ms 262144 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Runtime error 209 ms 262144 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Runtime error 209 ms 262144 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 976 KB Output is correct
2 Correct 1 ms 976 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 1 ms 976 KB Output is correct
5 Runtime error 209 ms 262144 KB Execution killed with signal 9
6 Halted 0 ms 0 KB -