Submission #817517

#TimeUsernameProblemLanguageResultExecution timeMemory
817517hugo_pmComparing Plants (IOI20_plants)C++17
0 / 100
49 ms4776 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = (a); i < (b); i++) int N, K; int add(int x, int y) { x += y; if (x >= N) x -= N; return x; } int sub(int x, int y) { x -= y; if (x < 0) x += N; return x; } int dist(int x, int y) { return min(sub(x,y), sub(y,x)); } vector<int> relative, height; const int MAX_GRAPH = 300; bool graph[MAX_GRAPH][MAX_GRAPH]; void pop(int cur, int &toPut) { assert(relative[cur] == 0); relative[cur] = -1; rep(delta, 1, K) { int nxt = sub(cur, delta); if (relative[nxt] == 0) pop(nxt, toPut); } height[cur] = toPut--; rep(delta, 1, K) { relative[sub(cur, delta)]--; } rep(delta, 1, K) { if (relative[sub(cur,delta)] == 0) { pop(sub(cur, delta), toPut); } } } void init(int _k, std::vector<int> _r) { K = _k; relative = _r; N = _r.size(); //-- height.resize(N); int toPut = N-1; for (int i = 0; i < N; ++i) { if (relative[i] == 0) pop(i, toPut); } if (N <= MAX_GRAPH) { rep(i, 0, N) rep(j, 0, N) { graph[i][j] = (dist(i,j) < K && height[i] > height[j]); } rep(k, 0, N) rep(i, 0, N) rep(j, 0, N) { graph[i][j] |= (graph[i][k] && graph[k][j]); } } } int compare_plants(int x, int y) { int xy = (height[x] > height[y]); int yx = (height[y] > height[x]); if (N <= MAX_GRAPH) { xy = graph[x][y], yx = graph[y][x]; } return xy - yx; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...