답안 #931413

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931413 2024-02-21T18:25:08 Z YassirSalama 게임 (APIO22_game) C++17
0 / 100
1 ms 1112 KB
#include "game.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <iomanip>
#include <cmath>
#include <limits>
#include <map>
#include <utility>
#include <cctype>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include<assert.h>
#include <functional>
#include <iterator>
using namespace std;
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
#define OVL(x,s) for(auto y:x) cout<<y<<s; cout<<"\n";
#ifdef IOI
void dbg_out() { cout << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cout << ' ' << H; dbg_out(T...); }
#define dbg(...) cout << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__);
#else
#define dbg(...) 1337;
#endif
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define ll long long
#define mod 1000000007
#define all(v) v.begin(),v.end()
const int MAXN=3e4+100;
vector<int> v[MAXN];
int k;
int n;
void init(int N, int K) {
  n=N;
  k=K;
  for(int i=0;i<=k-2;i++){
    // dbg(i,i+1)
    v[i].pb(i+1);
  }
}
bool visited[MAXN];
bool check(int a){
  return 0<=a&&a<=k-1;
}
bool dfs(int node,int top){
  // dbg(node,top)
  if(visited[node]) {
    if(check(node)) return top>=node;
    else return false;
  }
  visited[node]=true;
  for(auto x:v[node]){
    if(check(node)&&check(x)) {
      if(dfs(x,max(node,x))) return true;
    }else{
      if(dfs(x,top)) return true;
    }
  }
  return false;
}
int add_teleporter(int a, int b) {
  v[a].pb(b);
  memset(visited,false,sizeof(visited));
  bool ok=dfs(0,0);
  // dbg(ok);
  return ok;
}

#ifdef IOI
#include <cstdio>
#include <cstdlib>
#include <vector>
#include "game.h"

namespace {

int read_int() {
  int x;
  if (scanf("%d", &x) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  return x;
}

}  // namespace

int main() {
  int N = read_int();
  int M = read_int();
  int K = read_int();
  std::vector<int> u(M), v(M);
  for (int i = 0; i < M; ++i) {
    u[i] = read_int();
    v[i] = read_int();
  }

  init(N, K);
  int i;
  for (i = 0; i < M; ++i) {
    int answer = add_teleporter(u[i], v[i]);
    if (answer != 0 && answer != 1) {
      i = -1;
      break;
    } else if (answer == 1) {
      break;
    }
  }
  printf("%d\n", i);
  return 0;
}

#endif
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1112 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1112 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1112 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1112 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1112 KB Output is correct
2 Incorrect 1 ms 1112 KB Wrong Answer[1]
3 Halted 0 ms 0 KB -