Submission #774105

#TimeUsernameProblemLanguageResultExecution timeMemory
774105danikoynovGame (IOI14_game)C++14
42 / 100
1075 ms16836 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; const int maxn = 1510; int n; int used[maxn], in_st[maxn * maxn], in_mst[maxn * maxn]; vector < int > st, mst; mt19937 rng; void random_shuffle() { for (int i = 0; i < st.size(); i ++) { int idx = rng() % (int)(st.size()); swap(st[i], st[idx]); } } void initialize(int N) { n = N; for (int i = 0; i < n; i ++) for (int j = i + 1; j < n; j ++) { if (i != j) { if (i + 1 == j) mst.push_back(i * n + j), in_mst[i * n + j] = 1; else st.push_back(i * n + j), in_st[i * n + j] = 1; } } random_shuffle(); } vector < int > adj[maxn]; void dfs(int v, int cnt) { used[v] = cnt; for (int u : adj[v]) { if (!used[u]) dfs(u, cnt); } } int cnt = 0; int hasEdge(int u, int v) { cnt ++; if (n * (n - 1) / 2 - cnt < 1e4 && cnt % 10 ==0) random_shuffle(); //cout << "----------------" << endl; if (u > v) swap(u, v); int hs = u * n + v; if (!in_mst[hs]) { in_st[hs] = 0; return 0; } for (int i = 0; i < n; i ++) adj[i].clear(), used[i] = 0; vector < int > new_st; for (int cur: st) { if (in_st[cur]) new_st.push_back(cur); } st = new_st; for (int edge : mst) { if (edge == hs) continue; ///cout << edge / n << " " << edge % n << endl; adj[edge / n].push_back(edge % n); adj[edge % n].push_back(edge / n); } dfs(0, 1); for (int i = 0; i < n; i ++) if (used[i] == 0) { dfs(i, 2); break; } for (int edge : st) { if (edge == hs) continue; if (used[edge / n] != used[edge % n]) { ///cout << "replace " << edge / n << " " << edge % n << endl; in_st[hs] = 0; in_mst[edge] = 1; mst.push_back(edge); in_mst[hs] = 0; int pt = 0; while(mst[pt] != hs) pt ++; mst.erase(mst.begin() + pt); in_st[edge] = 0; /**st.erase(hs); mst.insert(edge); st.erase(edge); mst.erase(hs);*/ return 0; } } return 1; }

Compilation message (stderr)

game.cpp: In function 'void random_shuffle()':
game.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |     for (int i = 0; i < st.size(); i ++)
      |                     ~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...