Submission #873406

#TimeUsernameProblemLanguageResultExecution timeMemory
873406garam1732Snake Escaping (JOI18_snake_escaping)C++14
100 / 100
1401 ms53508 KiB
#include <bits/stdc++.h> using namespace std; #define ff first #define ss second #define bl " " #define endl "\n" #define all(v) v.begin(), v.end() #define comp(v) v.erase(unique(all(v)), v.end()) typedef long long ll; typedef pair<int, int> pi; typedef pair<pi, int> pii; typedef pair<ll, ll> pll; const int MAXN = 1000100/5; const int MOD = 1e9+7; struct Query { string s; int x; ll v; }qry[MAXN]; vector<int> v; int ans[MAXN]; void solve(int s, int e, int l, int r, int x) { if(s > e) return; if(l == r) { for(int i = s; i <= e; i++) ans[qry[i].x] = v[l]; return; } int a = s, mid = l+r>>1; for(a = s; a <= e; a++) { if(qry[a].s[x] != '0') break; } solve(s, a-1, l, mid, x+1); s = a; for(; a <= e; a++) { if(qry[a].s[x] != '1') break; } solve(s, a-1, mid+1, r, x+1); s = a; for(int i = l, j = mid+1; j <= r; i++, j++) v[i] += v[j]; solve(s, e, l, mid, x+1); for(int i = l, j = mid+1; j <= r; i++, j++) v[i] -= v[j]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int l, q; cin >> l >> q; char x; for(int i = 0; i < (1<<l); i++) { cin >> x; v.push_back(x-'0'); } int sz = 5; for(int i = 0; i < sz; i++) { int s = q*i/sz+1, e = q*(i+1)/sz; for(int j = s; j <= e; j++) { cin >> qry[j-s].s; qry[j-s].x = j-s; } for(int j = 0; j <= e-s; j++) { qry[j].v = 0; for(int k = 0; k < l; k++) { qry[j].v *= 3; if(qry[j].s[k] == '1') qry[j].v += 1; else if(qry[j].s[k] == '?') qry[j].v += 2; } } sort(qry, qry+e-s+1, [](Query &a, Query &b){return a.v<b.v;}); solve(0, e-s, 0, (1<<l)-1, 0); for(int j = 0; j <= e-s; j++) cout << ans[j] << endl; } }

Compilation message (stderr)

snake_escaping.cpp: In function 'void solve(int, int, int, int, int)':
snake_escaping.cpp:32:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   32 |     int a = s, mid = l+r>>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...
#Verdict Execution timeMemoryGrader output
Fetching results...