이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// fest
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second
#define y1 dasdasfasfas
#define x1 wqdadfasfasfas
#define All(c) c.begin(), c.end()
#define SZ(A) (int((A).size()))
#define umap unordered_map
#define FILENAME ""
#define __ fflush(stdout)
typedef long long ll;
typedef long double ld;
using namespace std;
void FREOPEN() {
#ifdef COMP
freopen(".in", "r", stdin);
freopen("2.out", "w", stdout);
#endif
}
inline double Time() {return (clock() * 1.0) / CLOCKS_PER_SEC; }
const int N = 1594323, inf = 1e9 * 2, MOD = (int)1e9 + 7, M = 13;
char CH[N];
const ll INF = 1e18;
const int dx[] = {1, -1, 0, 0, -1, 1, -1, 1};
const int dy[] = {0, 0, 1, -1, -1, 1, 1, -1};
int n;
int ans[N], dp[N], pos[N], p[M + 1], cost[(1 << 20)], qs[20];
vector<pair<int, int> > have[(1 << (20 - M))];
int main() {
FREOPEN();
int q;
cin >> n >> q;
scanf("\n");
for (int i = 0; i < (1 << n); i++) {
char x;
scanf("%c", &x);
cost[i] = int(x - '0');
}
p[0] = 1;
for (int i = 1; i <= M; i++) p[i] = p[i - 1] * 3;
for (int qq = 1; qq <= q; qq++) {
scanf("\n");
for (int i = n - 1; i >= 0; i--) {
char x;
scanf("%c", &x);
if (x == '?') qs[i] = 2;
else qs[i] = int(x - '0');
}
if (n <= M) {
int go = 0;
for (int i = n - 1; i >= 0; i--) {
go += qs[i] * p[i];
}
have[0].pb({go, qq});
}
else {
int go = 0;
for (int i = M - 1; i >= 0; i--) {
go += qs[i] * p[i];
}
for (int mask = 0; mask < (1 << (20 - M)); mask++) {
bool ok = 1;
for (int i = 19; i >= M; i--) {
if (qs[i] == 2) continue;
int bit = ((mask & (1 << (i - M))) > 0);
if (bit != qs[i]) {
ok = 0;
break;
}
}
if (ok) have[mask].pb({go, qq});
}
}
}
for (int x = 0; x < p[M]; x++) {
int y = x;
int two = 0;
int posi = 0;
while (y) {
if (y % 3 == 2) {
two = -posi - 1;
break;
}
if (y % 3 == 1) two |= (1 << posi);
y /= 3;
posi++;
}
pos[x] = two;
}
for (int mask = 0; mask < (1 << (20 - M)); mask++) {
if (have[mask].empty()) continue;
for (int x = 0; x < p[M]; x++) {
dp[x] = 0;
if (pos[x] >= 0) {
dp[x] = cost[(mask << M) | pos[x]];
}
else {
int dec = p[-pos[x] - 1];
if (x - dec >= 0) dp[x] += dp[x - dec];
if (x - dec - dec >= 0) dp[x] += dp[x - dec - dec];
}
}
for (auto i : have[mask]) {
ans[i.S] += dp[i.F];
}
}
for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:49:13: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("\n");
^
snake_escaping.cpp:52:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c", &x);
^
snake_escaping.cpp:58:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("\n");
^
snake_escaping.cpp:61:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%c", &x);
^
# | 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... |