제출 #38647

#제출 시각아이디문제언어결과실행 시간메모리
3864714kg게임 (IOI14_game)C++11
42 / 100
1000 ms20236 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; int d1_len, d1[N], d2_len, d2[N]; 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); } // !!! d1_len = d2_len = 0; for (int i = 1; i <= n; i++) if (d[i] == 1) d1[++d1_len] = i; else d2[++d2_len] = i; for(int i=1; i<=d1_len && empty_num1==0; i++) if (r_cnt[d1[i]] < n - 1) { for (int j = 1; j <= d2_len && empty_num1==0; j++) if (r_cnt[d2[j]] < n - 1 && (d1[i] == x && d2[j] == y) == false && r[d1[i]][d2[j]] != -2) { empty_num1 = d1[i], empty_num2 = d2[j]; } } 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; link[tx].push_back(ty), link[ty].push_back(tx); 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...