Submission #371619

#TimeUsernameProblemLanguageResultExecution timeMemory
371619Lam_lai_cuoc_doiPainting Squares (IOI20_squares)C++17
0 / 100
1 ms328 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; const int N = 1e3 + 5; map<int, int> ck; int a[N], m, s, ans; bool dfs(int v, int dep) { ck[v] = dep; if (dep == 971) return true; int u = v >> 1; if (!ck[u + (1 << 29)]) if (dfs(u + (1 << 29), dep + 1)) return true; if (!ck[u]) if (dfs(u, dep + 1)) return true; return false; } void fillout(int v, int dep) { if (dep > m - 30 + 1) return; if (s == v) { ans = dep - 1; return; } int u = v >> 1; if (ck[u] == dep + 1) fillout(u, dep + 1); else if (ck[u + (1 << 29)] == dep + 1) fillout(u + (1 << 29), dep + 1); } void fillin(int v, int dep) { if (dep == m - 30 + 1) { for (int i = 0; i < 30; ++i) a[m - 30 + 1 + i] = (v >> i) & 1; return; } a[dep - 1] = v & 1; int u = v >> 1; if (ck[u] == dep + 1) fillin(u, dep + 1); else if (ck[u + (1 << 29)] == dep + 1) fillin(u + (1 << 29), dep + 1); } int *paint(int n) { if (n <= 30) { for (int i = 0; i < n; ++i) a[i] = 1; a[n] = n; return a; } m = n; ck.clear(); ck[1] = 1; dfs(1, 1); fillin(1, 1); return a; } int find_location(int n, vector<int> c) { if (n <= 30) { for (int i = 0; i < n; ++i) if (c[i] != 1) return -1; return 0; } m = n; ck.clear(); ck[1] = 1; dfs(1, 1); s = 0; for (int i = 0; i < 30; ++i) s += (c[i]) * (1 << i); ans = -1; fillout(1, 1); return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...