# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
698924 | finn__ | Snake Escaping (JOI18_snake_escaping) | C++17 | 1 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define popcount(x) __builtin_popcount(x)
char snakes[1 << 20];
unsigned v[1 << 20], super[1 << 20], sub[1 << 20];
int main()
{
size_t l, q;
scanf("%zu %zu %s", &l, &q, snakes);
for (size_t i = 0; i < 1U << l; i++)
super[i] = sub[i] = v[i] = snakes[i] - '0';
for (size_t i = 0; i < l; i++)
for (size_t j = 0; j < 1U << l; j++)
if (j & (1 << i))
sub[j] += sub[j ^ (1 << i)];
else
super[j] += super[j ^ (1 << i)];
char s[20];
while (q--)
{
scanf("%s", s);
unsigned a = 0, b = 0, c = 0, ans = 0;
for (size_t i = 0; i < l; i++)
{
a <<= 1, b <<= 1, c <<= 1;
a |= s[i] == '0', b |= s[i] == '1', c |= s[i] == '?';
}
if (popcount(a) <= popcount(b) && popcount(a) <= popcount(c))
{
ans = super[b];
for (unsigned i = a; i; i = (i - 1) & a)
ans += super[b | i] * ((popcount(i) & 1) ? -1 : 1);
}
else if (popcount(b) <= popcount(a) && popcount(b) <= popcount(c))
{
ans = sub[c];
for (unsigned i = b; i; i = (i - 1) & b)
ans += sub[c | i] * ((popcount(b ^ i) & 1) ? -1 : 1);
}
else
{
ans = v[b];
for (unsigned i = c; i; i = (i - 1) & c)
ans += v[b | i];
}
printf("%u\n", ans);
}
}
컴파일 시 표준 에러 (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... |