# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1233602 | BuiDucManh123 | Snake Escaping (JOI18_snake_escaping) | C++20 | 401 ms | 21892 KiB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define taskname ""
#define ld long double
const int mod = 1e9+7;
using namespace std;
int f[2000009], g[2000009], cnt[2000009];
signed main() {
if (fopen(taskname".inp","r")) {
freopen(taskname".inp","r",stdin);
freopen(taskname".out","w",stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int l, q;
cin >> l >> q;
string s;
cin >> s;
for(int i = 0; i < (1 << l); i++){
f[i] = s[i] - '0';
g[i] = s[i] - '0';
}
for(int i = 0; i < l; i++){
for(int mask = 0; mask < (1 << l); mask++){
if((mask >> i) & 1){
cnt[mask]++;
f[mask] += f[mask ^ (1 << i)];
}else{
g[mask] += g[mask ^ (1 << i)];
}
}
}
while(q--){
string t;
cin >> t;
int x = 0, y = 0, z = 0, cx = 0, cy = 0, cz = 0;
for(int i = 0; i < t.size(); i++){
if(t[i] == '0'){
cx++;
x += (1 << (l - 1 - i));
}
if(t[i] == '1'){
cy++;
y += (1 << (l - 1 - i));
}
if(t[i] == '?'){
cz++;
z += (1 << (l - 1 - i));
}
}
int ans = 0;
if(cy <= 6){
ans += f[y | z];
for(int i = y; i > 0; i = (i - 1) & y){
if(cnt[i] & 1){
ans -= f[z | (y ^ i)];
}else{
ans += f[z | (y ^ i)];
}
}
cout << ans << "\n";
continue;
}
if(cx <= 6){
ans += g[y];
for(int i = x; i > 0; i = (i - 1) & x){
if(cnt[i] & 1){
ans -= g[y | i];
}else{
ans += g[y | i];
}
}
cout << ans << "\n";
continue;
}
for(int i = z; i > 0; i = (i - 1) & z){
ans += s[i | y] - '0';
}
ans += s[y] - '0';
cout << ans << "\n";
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |