제출 #38644

#제출 시각아이디문제언어결과실행 시간메모리
3864414kg게임 (IOI14_game)C++11
0 / 100
0 ms19568 KiB
#include "game.h" #include <vector> #include <queue> #define N 1501 using namespace std; int n, r[N][N], r_cnt[N]; int d[N]; vector<int> link[N]; queue<int> Q; void initialize(int _n) { n = _n; for (int i = 1; i < n; i++) { r[i][i + 1] = r[i + 1][i] = 1; link[i].push_back(i + 1), link[i + 1].push_back(i); r_cnt[i]++, r_cnt[i + 1]++; } } int hasEdge(int x, int y) { int lev, empty_num1 = 0, empty_num2 = 0; x++, y++; if (r[x][y] == 0) { r[x][y] = r[y][x] = -2; r_cnt[x]++, r_cnt[y]++; return 0; } if (r[x][y] != 1) return r[x][y] > 0 ? 1 : 0; for (int i = 1; i <= n; i++) d[i] = 2; d[x] = 1, Q.push(x); while (!Q.empty()) { lev = Q.front(), Q.pop(); for (auto i : link[lev]) if (d[i] == 2 && i != y && (r[lev][i] == 1 || r[lev][i] == 2)) d[i] = 1, Q.push(i); } for (int i = 1; i <= n && (empty_num1 == 0 || empty_num2 == 0); i++) if (d[i] == 1 && r_cnt[i] < n - 1 && (i == x && empty_num2 == y) == false && r[i][empty_num2] != -2) empty_num1 = i; else if (d[i] == 2 && r_cnt[i] < n - 1 && (empty_num1 == x && i == y)==false && r[empty_num1][i] != -2) empty_num2 = i; if (empty_num1 && empty_num2) { int tx = empty_num1, ty = empty_num2; r[x][y] = r[y][x] = -2; r[tx][ty] = r[ty][tx] = 1; r_cnt[tx]++, r_cnt[ty]++; return 0; } else { r[x][y] = r[y][x] = 2; return 1; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...