이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
#include <climits>
#include <stack>
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.1,sse4.2,popcnt,abm,mmx,avx,avx2,tune=native")*/
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr
map <string, int> cnt;
string t;
void calc(int l, string & s) {
int ans = 0;
loop(i, (1ll << l)) {
bool f = 1;
loop(bit, l)
if (t[bit] != '?' && bool(i & (1ll << bit)) != t[bit] - '0') {
f = 0; break;
}
if (f)
ans += s[i] - '0';
}
cnt[t] = ans;
}
void precalc(int l, string &s) {
if (t.size() == l) {
calc(l, s);
return;
}
t.pb('0');
precalc(l, s);
t[t.size() - 1] = '1';
precalc(l, s);
t[t.size() - 1] = '?';
precalc(l, s);
t.pop_back();
}
void solve() {
int l, q;
string s;
cin >> l >> q >> s;
precalc(l, s);
loop(i, q) {
string t; cin >> t;
reverse(all(t));
cout << cnt[t] << "\n";
}
}
signed main() {
//freopen("b2.txt", "r", stdin);
//freopen("ans9.txt", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//int t; cin >> t; loop(i, t)
solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
snake_escaping.cpp: In function 'void precalc(ll, std::string&)':
snake_escaping.cpp:70:18: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
70 | if (t.size() == l) {
| ~~~~~~~~~^~~~
# | 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... |