Submission #706168

#TimeUsernameProblemLanguageResultExecution timeMemory
706168SamNguyenScales (IOI15_scales)C++14
3.43 / 100
1 ms308 KiB
#include "scales.h" #include <bits/stdc++.h> using namespace std; class DAG { private: int n; vector<vector<int>> adj; public: DAG(int n): n(n) { adj.assign(n + 1, vector<int>()); } inline void add_edge(int u, int v) { adj[u].push_back(v); } vector<int> unique_topo_order() { vector<int> deg(n + 1, 0); for (int u = 1; u <= n; u++) for (int v : adj[u]) deg[v]++; queue<int> q; for (int u = 1; u <= n; u++) if (deg[u] == 0) q.push(u); if (q.size() > 1) return vector<int>(); vector<int> res; while (not q.empty()) { int u = q.front(); q.pop(); res.push_back(u); if (int(res.size()) == n) break; vector<int> nxts; for (int v : adj[u]) { deg[v]--; if (deg[v] == 0) nxts.push_back(v); } if (nxts.size() > 1) return vector<int>(); q.push(nxts.front()); } return res; } }; mt19937 rnd(82394 + time(NULL)); void init(int T) { } void orderCoins() { DAG dag(6); vector<int> inds = {1, 2, 3, 4, 5, 6}; vector<int> topo; while (true) { topo = dag.unique_topo_order(); if (not topo.empty()) break; shuffle(inds.begin(), inds.end(), rnd); int A = inds[0], B = inds[1], C = inds[2]; int X = getLightest(A, B, C); int Y = getMedian(A, B, C); int Z = getHeaviest(A, B, C); dag.add_edge(X, Y); dag.add_edge(Y, Z); } int W[5]; copy(topo.begin(), topo.end(), W); answer(W); }

Compilation message (stderr)

scales.cpp: In constructor 'DAG::DAG(int)':
scales.cpp:11:10: warning: declaration of 'n' shadows a member of 'DAG' [-Wshadow]
   11 |  DAG(int n): n(n) {
      |      ~~~~^
scales.cpp:7:6: note: shadowed declaration is here
    7 |  int n;
      |      ^
scales.cpp: In constructor 'DAG::DAG(int)':
scales.cpp:11:10: warning: declaration of 'n' shadows a member of 'DAG' [-Wshadow]
   11 |  DAG(int n): n(n) {
      |      ~~~~^
scales.cpp:7:6: note: shadowed declaration is here
    7 |  int n;
      |      ^
scales.cpp: In constructor 'DAG::DAG(int)':
scales.cpp:11:10: warning: declaration of 'n' shadows a member of 'DAG' [-Wshadow]
   11 |  DAG(int n): n(n) {
      |      ~~~~^
scales.cpp:7:6: note: shadowed declaration is here
    7 |  int n;
      |      ^
scales.cpp: In function 'void init(int)':
scales.cpp:57:15: warning: unused parameter 'T' [-Wunused-parameter]
   57 | void init(int T) {
      |           ~~~~^
#Verdict Execution timeMemoryGrader output
Fetching results...