Submission #836269

#TimeUsernameProblemLanguageResultExecution timeMemory
836269rainboyPainting Squares (IOI20_squares)C++17
100 / 100
184 ms628 KiB
#include "squares.h" #include <cstring> #include <functional> #include <vector> using namespace std; typedef vector<int> vi; vi paint(int n) { const int K = 10, N = 1 << K - 1; char used[N * 2]; int qu[N * 2], cnt; function<void(int)> dfs = [&](int u) { if (!used[u << 1 | 0]) used[u << 1 | 0] = 1, dfs((u << 1 | 0) & N - 1), qu[cnt++] = u << 1 | 0; if (!used[u << 1 | 1]) used[u << 1 | 1] = 1, dfs((u << 1 | 1) & N - 1), qu[cnt++] = u << 1 | 1; }; memset(used, 0, N * 2 * sizeof *used); cnt = 0, dfs(0); vi aa(n + 1, 0); aa[n] = K; for (int i = K - 1; i < n; i++) aa[i] = qu[--cnt] & 1; return aa; } int find_location(int n, vi cc) { const int K = 10, N = 1 << K - 1; char used[N * 2]; int qu[N * 2], cnt; function<void(int)> dfs = [&](int u) { if (!used[u << 1 | 0]) used[u << 1 | 0] = 1, dfs((u << 1 | 0) & N - 1), qu[cnt++] = u << 1 | 0; if (!used[u << 1 | 1]) used[u << 1 | 1] = 1, dfs((u << 1 | 1) & N - 1), qu[cnt++] = u << 1 | 1; }; memset(used, 0, N * 2 * sizeof *used); cnt = 0, dfs(0); int u = 0; for (int i = 0; i < K; i++) { if (cc[i] == -1) return n - i; u = u << 1 | cc[i]; } for (int h = cnt - 1; h >= 0; h--) if (u == qu[h]) return cnt - 1 - h; return -1; }

Compilation message (stderr)

squares.cpp: In function 'vi paint(int)':
squares.cpp:11:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   11 |  const int K = 10, N = 1 << K - 1;
      |                             ~~^~~
squares.cpp: In lambda function:
squares.cpp:15:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   15 |    used[u << 1 | 0] = 1, dfs((u << 1 | 0) & N - 1), qu[cnt++] = u << 1 | 0;
      |                                             ~~^~~
squares.cpp:17:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   17 |    used[u << 1 | 1] = 1, dfs((u << 1 | 1) & N - 1), qu[cnt++] = u << 1 | 1;
      |                                             ~~^~~
squares.cpp: In function 'int find_location(int, vi)':
squares.cpp:28:31: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   28 |  const int K = 10, N = 1 << K - 1;
      |                             ~~^~~
squares.cpp: In lambda function:
squares.cpp:32:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   32 |    used[u << 1 | 0] = 1, dfs((u << 1 | 0) & N - 1), qu[cnt++] = u << 1 | 0;
      |                                             ~~^~~
squares.cpp:34:47: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   34 |    used[u << 1 | 1] = 1, dfs((u << 1 | 1) & N - 1), qu[cnt++] = u << 1 | 1;
      |                                             ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...