Submission #559424

#TimeUsernameProblemLanguageResultExecution timeMemory
559424ahmet34Painting Squares (IOI20_squares)C++14
0 / 100
4 ms2384 KiB
#include "squares.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() const int INF = 2e9, N = 1e6+10, M = 1e9+7, LOG = 16; const ll LINF = 1e18; string res; map<string, bool> vis; void dfs(string node) { for(int i = 0; i < 2; i++) { string to = node + char('0' + i); if(!vis[to]) { vis[to] = true; dfs(to.substr(1)); res += to.back(); } } } int len; map<deque<int>, int> idx; void deBruijn () { string s = string(len-1, '0'); dfs(s); res += s; } vector<int> paint(int n) { len = min(10, n); deBruijn(); vector<int> labels(n); for(int i = 0; i < n; ++i) labels[i] = res[i]-'0'; deque<int> cur (labels.begin(), labels.begin() + len); for(int i = len; i < n; i++) { cur.push_back(labels[i]); if(i >= len) cur.pop_front(); assert(idx.count(cur) == 0); idx[cur] = i-len+1; } labels.push_back(len); return labels; } int find_location(int n, vector<int> c) { int cnt = count(all(c), -1); if(cnt) return n - (len - cnt); return idx[deque<int>(all(c))]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...