제출 #1222824

#제출 시각아이디문제언어결과실행 시간메모리
1222824thdh__Snake Escaping (JOI18_snake_escaping)C++20
22 / 100
1899 ms24016 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define eb emplace_back #define pu push #define ins insert #define fi first #define se second #define all(a) a.begin(),a.end() #define bruh ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); #define fu(x,a,b) for (auto x=a;x<=b;x++) #define fd(x,a,b) for (auto x=a;x>=b;x--) #define int ll using namespace std; #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") //mt19937 mt(chrono::steady_clock::now().time_since_epoch().count()); /* Competitive Programming notes that I need to study & fix my dumbass self: 1. Coding: - Always be sure to check the memory of arrays (maybe use vectors), for loops, I don't know - Always try to maximize the memory if possible, even if you are going for subtasks - Do not exploit #define int long long, it will kill you 2. Stress: - Don't be cocky and think stressing with your dumbass brute-force solution will give you guaranteed AC. - Always try generating big testcases and try if they run 3. Time management: - Don't overcommit or undercommit, always spend a certain amount of time to think a problem, don't just look at it and say I'm fucked - Do not spend too much time coding brute-force solutions, they should be easily-codable solutions that don't take up too much time I hate offline because I am dumb */ typedef pair<int, int> ii; const int N = 1e6+5; const int M = 20; const int mod = 1e9+7; const int inf = 1e18; using cd = complex<double>; const long double PI = acos(-1); int power(int a,int b) {ll x = 1;if (a >= mod) a%=mod; while (b) {if (b & 1) x = x*a % mod;a = a*a % mod;b>>=1;}return x;} int n,q,m; int a[N], f1[N], f2[N]; void solve() { cin>>n>>q; m = (1<<n); for (int i = 0; i < m; i++) { char c; cin>>c; a[i] = c - '0'; // cout<<a[i]<<" "; f1[i] = f2[i] = a[i]; } // cout<<endl; for (int i = 0; i < n; i++) { for (int mask = 0; mask < m; mask++) if (mask>>i & 1) f1[mask] += f1[mask ^ (1<<i)]; } for (int i = 0; i < n; i++) { for (int mask = m-1; mask >= 0; mask--) if ((mask>>i & 1) == 0) f2[mask] += f2[mask ^ (1<<i)]; } while (q--) { string s; cin>>s; reverse(all(s)); int cnt1 = 0, cnt0 = 0, cntq = 0; int msk = 0, mskq = 0, msk1 = 0; for (int i = 0; i < n; i++) { if (s[i] == '1') cnt1++, msk |= (1<<i), msk1 |= (1<<i); else if (s[i] == '0') cnt0++; else cntq++, mskq |= (1<<i), msk1 |= (1<<i); // if (s[i] == '1') msk |= (1<<i); } // cout<<msk<<" "<<mskq<<" "<<msk1<<endl; // cout<<cnt<<endl; if (cnt1 <= 7) { int ans = 0; for (int nmsk = msk; ; nmsk = (nmsk - 1) & msk) { int nmsk1 = (nmsk | mskq), nmsk2 = nmsk; int diff = cnt1 - __builtin_popcount(nmsk); if (diff % 2 == 0) ans += f1[nmsk1] - f1[nmsk2]; else ans -= f1[nmsk1] - f1[nmsk2]; if (!diff) ans += a[nmsk2]; if (nmsk == 0) break; } cout<<ans<<endl; } else if (cntq <= 7) { int ans = 0; for (int nmsk = mskq; ; nmsk = (nmsk - 1) & mskq) { ans += a[(nmsk | msk)]; if (nmsk == 0) break; } cout<<ans<<endl; } else if (cnt0 <= 7) { int ans = 0; for (int nmsk = msk1; ; nmsk = (nmsk + 1) | msk1) { // cout<<nmsk<<" "; int nmsk1 = (nmsk ^ mskq), nmsk2 = nmsk; int diff = cnt0 - (n - __builtin_popcount(nmsk)); // cout<<nmsk<<" "<<nmsk1<<" "<<nmsk2<<" "<<f2[nmsk1]<<" "<<f2[nmsk2]<<endl; if (diff % 2 == 0) ans += f2[nmsk1] - f2[nmsk2]; else ans -= f2[nmsk1] - f2[nmsk2]; if (!diff) ans += a[nmsk2]; if (nmsk == (m-1)) break; } cout<<ans<<endl; } } } /* if (cnt1 <= 7) { int ans = 0; for (int nmsk = msk; ; nmsk = (nmsk - 1) & msk) { int nmsk1 = (nmsk | mskq), nmsk2 = nmsk; int diff = cnt1 - __builtin_popcount(nmsk); if (diff % 2 == 0) ans += f1[nmsk1] - f1[nmsk2]; else ans -= f1[nmsk1] - f1[nmsk2]; if (!diff) ans += a[nmsk2]; if (nmsk == 0) break; } cout<<ans<<endl; } else if (cntq <= 7) { int ans = 0; for (int nmsk = mskq; ; nmsk = (nmsk - 1) & mskq) { ans += a[(nmsk | msk)]; if (nmsk == 0) break; } cout<<ans<<endl; } else */ /* Go through the mistakes you usually make and revise your code, for god's sake... */ signed main() { bruh //freopen("input.inp","r",stdin); //freopen("output.inp","w",stdout); int t = 1; // cin>>t; while (t--) { solve(); cout<<"\n"; } }
#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...