제출 #43543

#제출 시각아이디문제언어결과실행 시간메모리
43543wxh010910Snake Escaping (JOI18_snake_escaping)C++14
100 / 100
1311 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define X first #define Y second #define mp make_pair #define pb push_back #define Debug(...) fprintf(stderr, __VA_ARGS__) typedef long long LL; typedef long double LD; typedef unsigned int uint; typedef pair <int, int> pii; typedef unsigned long long uLL; template <typename T> inline void Read(T &x) { char c = getchar(); bool f = false; for (x = 0; !isdigit(c); c = getchar()) { if (c == '-') { f = true; } } for (; isdigit(c); c = getchar()) { x = x * 10 + c - '0'; } if (f) { x = -x; } } template <typename T> inline bool CheckMax(T &a, const T &b) { return a < b ? a = b, true : false; } template <typename T> inline bool CheckMin(T &a, const T &b) { return a > b ? a = b, true : false; } const int N = 1048580; int n, m, a[N], b[N]; char s[N], t[N]; int main() { #ifdef wxh010910 freopen("d.in", "r", stdin); #endif Read(n), Read(m); scanf("%s", s); for (int i = 0; i < 1 << n; ++i) { a[i] = b[i] = s[i] - '0'; } for (int i = 1; i < 1 << n; i <<= 1) { for (int j = 0; j < 1 << n; j += i << 1) { for (int k = 0; k < i; ++k) { a[j + k] += a[j + k + i], b[j + k + i] += b[j + k]; } } } while (m--) { int x = 0, y = 0, z = 0, ans = 0; scanf("%s", t); for (int i = 0; i < n; ++i) { if (t[i] == '0') { x |= 1 << n - i - 1; } else if (t[i] == '1') { y |= 1 << n - i - 1; } else { z |= 1 << n - i - 1; } } if (__builtin_popcount(x) <= 6) { for (int i = x; ; i = i - 1 & x) { if (__builtin_popcount(i) & 1) { ans -= a[y | i]; } else { ans += a[y | i]; } if (!i) { break; } } } else if (__builtin_popcount(y) <= 6) { for (int i = y; ; i = i - 1 & y) { if (__builtin_popcount(i ^ y) & 1) { ans -= b[z | i]; } else { ans += b[z | i]; } if (!i) { break; } } } else { for (int i = z; ; i = i - 1 & z) { ans += s[y | i] - '0'; if (!i) { break; } } } printf("%d\n", ans); } #ifdef wxh010910 Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC); #endif return 0; }

컴파일 시 표준 에러 (stderr) 메시지

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:67:25: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
         x |= 1 << n - i - 1;
                         ^
snake_escaping.cpp:69:25: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
         y |= 1 << n - i - 1;
                         ^
snake_escaping.cpp:71:25: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
         z |= 1 << n - i - 1;
                         ^
snake_escaping.cpp:75:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
       for (int i = x; ; i = i - 1 & x) {
                               ^
snake_escaping.cpp:86:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
       for (int i = y; ; i = i - 1 & y) {
                               ^
snake_escaping.cpp:97:31: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
       for (int i = z; ; i = i - 1 & z) {
                               ^
snake_escaping.cpp:51:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s", s);
                 ^
snake_escaping.cpp:64:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s", t);
                   ^
#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...