답안 #575875

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575875 2022-06-11T12:42:40 Z onebit1024 게임 (APIO22_game) C++17
30 / 100
4000 ms 2196 KB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"




vector<vector<int>> adj,trans;

void dfs(vector<int>&order, int u,vector<bool>&visited){
  visited[u] = 1;
  for(int v : adj[u]){
    if(!visited[v])dfs(order, v, visited);
  }
  order.pb(u);
}

void SCC(vector<int>&scc, int u, vector<bool>&visited){
  visited[u] = 1;
  scc.pb(u);
  
  for(int v : trans[u]){
    if(!visited[v])SCC(scc, v, visited);
  }
}

int N;
int K;
void init(int n, int k) {
    adj.resize(n);
    trans.resize(n);
    N = n;
    K = k;
    for(int i = 0;i<=k-2;++i){
      adj[i].pb(i+1);
      trans[i+1].pb(i);
    }
}


int add_teleporter(int u, int v) {
  adj[u].pb(v);
  trans[v].pb(u);
  vector<int>order;
  vector<bool>visited(N);
  for(int i = 0;i<K;++i){
    if(find(all(adj[i]), i) != adj[i].end()){
      return 1;
    }
  }
  for(int i = 0;i<N;++i){
    if(!visited[i]){
      dfs(order, i, visited);
    }
  }
  visited.clear();
  visited = vector<bool>(N);
  for(int i = (int)(order.size()-1);i>=0;--i){
    if(!visited[order[i]]){
      vector<int>scc;
      SCC(scc, order[i], visited);
      if(scc.size() > 1){
        for(auto x : scc){

          if(x<K){
            return 1;
          }
        }
      }
    }
    
  }
  return 0;
}
// int32_t main(){
//   init(6,3);
//   add_teleporter(3,4);
//   add_teleporter(5, 0);
//   add_teleporter(4, 5);
//   add_teleporter(5, 3);
//   add_teleporter(1, 4);

//   // init(4,2);
//   // add_teleporter(1,1);
//   // init(3, 3);
//   // add_teleporter(2,2);
// }
/*
edge case 
init(6,3);
  add_teleporter(5,4);
  add_teleporter(4,3);
  add_teleporter(3,2);
  */
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 2 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 2 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
20 Correct 41 ms 336 KB Output is correct
21 Correct 5 ms 356 KB Output is correct
22 Correct 41 ms 388 KB Output is correct
23 Correct 44 ms 336 KB Output is correct
24 Correct 43 ms 448 KB Output is correct
25 Correct 208 ms 444 KB Output is correct
26 Correct 254 ms 504 KB Output is correct
27 Correct 227 ms 424 KB Output is correct
28 Correct 97 ms 408 KB Output is correct
29 Correct 196 ms 420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 2 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
20 Correct 41 ms 336 KB Output is correct
21 Correct 5 ms 356 KB Output is correct
22 Correct 41 ms 388 KB Output is correct
23 Correct 44 ms 336 KB Output is correct
24 Correct 43 ms 448 KB Output is correct
25 Correct 208 ms 444 KB Output is correct
26 Correct 254 ms 504 KB Output is correct
27 Correct 227 ms 424 KB Output is correct
28 Correct 97 ms 408 KB Output is correct
29 Correct 196 ms 420 KB Output is correct
30 Execution timed out 4073 ms 2196 KB Time limit exceeded
31 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 0 ms 208 KB Output is correct
3 Correct 2 ms 208 KB Output is correct
4 Correct 1 ms 208 KB Output is correct
5 Correct 2 ms 208 KB Output is correct
6 Correct 3 ms 208 KB Output is correct
7 Correct 2 ms 208 KB Output is correct
8 Correct 0 ms 208 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 0 ms 208 KB Output is correct
11 Correct 1 ms 208 KB Output is correct
12 Correct 1 ms 208 KB Output is correct
13 Correct 1 ms 208 KB Output is correct
14 Correct 1 ms 208 KB Output is correct
15 Correct 2 ms 208 KB Output is correct
16 Correct 2 ms 208 KB Output is correct
17 Correct 2 ms 208 KB Output is correct
18 Correct 1 ms 208 KB Output is correct
19 Correct 2 ms 208 KB Output is correct
20 Correct 41 ms 336 KB Output is correct
21 Correct 5 ms 356 KB Output is correct
22 Correct 41 ms 388 KB Output is correct
23 Correct 44 ms 336 KB Output is correct
24 Correct 43 ms 448 KB Output is correct
25 Correct 208 ms 444 KB Output is correct
26 Correct 254 ms 504 KB Output is correct
27 Correct 227 ms 424 KB Output is correct
28 Correct 97 ms 408 KB Output is correct
29 Correct 196 ms 420 KB Output is correct
30 Execution timed out 4073 ms 2196 KB Time limit exceeded
31 Halted 0 ms 0 KB -