제출 #1175480

#제출 시각아이디문제언어결과실행 시간메모리
1175480TrendBattlesSnake Escaping (JOI18_snake_escaping)C++17
75 / 100
217 ms15216 KiB
#include <bits/stdc++.h> using namespace std; using lli = long long int; #define INFILE "main.inp" #define OUTFILE "main.out" namespace SUBTASK_small_L { void main(int L, int Q, string digits) { vector <int> pow_3(L + 1); pow_3[0] = 1; for (int i = 1; i <= L; ++i) { pow_3[i] = pow_3[i - 1] * 3; } const int M = pow_3[L]; vector <int> mask_3(1 << L); vector <int> finale(M), value(1 << L); for (int m = 1; m < (1 << L); ++m) { int p = m & -m; mask_3[m] = mask_3[m ^ p] + pow_3[__builtin_ctz(p)]; } for (int m = 0; m < (1 << L); ++m) { value[m] = digits[m] - '0'; finale[mask_3[m]] = value[m]; } for (int b = 0; b < L; ++b) { for (int m = 0; m < M; ++m) { if (m / pow_3[b] % 3 != 2) continue; finale[m] += finale[m - pow_3[b]] + finale[m - pow_3[b] * 2]; } } for (int _ = 0; _ < Q; ++_) { string que; cin >> que; int m = 0; for (int i = 0; i < L; ++i) { if (que[i] == '1') m += pow_3[L - i - 1]; else if (que[i] == '?') m += pow_3[L - i - 1] * 2; } cout << finale[m] << '\n'; } } } namespace SUBTASK_small_Q { const int HIGH_BIT = 20, MAX_MASK = 1 << HIGH_BIT; int sum_A[MAX_MASK], sum_B[MAX_MASK]; int bit_cnt[MAX_MASK]; void main(int L, int Q, string digits) { for (int m = 0; m < (1 << L); ++m) { sum_A[m] = digits[m] - '0'; sum_B[~(-1 << L) ^ m] = sum_A[m]; bit_cnt[m] = bit_cnt[m >> 1] ^ (m & 1); } for (int b = 0; b < L; ++b) { for (int m = 0; m < (1 << L); ++m) { if ((m >> b & 1) == 0) { sum_A[m] += sum_A[m ^ (1 << b)]; sum_B[m] += sum_B[m ^ (1 << b)]; } } } for (int _ = 0; _ < Q; ++_) { string que; cin >> que; int ans = 0; if (count(que.begin(), que.end(), '0') <= L / 2) { int allowed = 0, banned = 0; for (int i = 0; i < L; ++i) { if (que[i] == '1') allowed ^= 1 << (L - i - 1); if (que[i] == '0') banned ^= 1 << (L - i - 1); } for (int p = banned; p >= 0; p = (p - 1) & banned) { if (bit_cnt[p]) { ans -= sum_A[allowed ^ p]; } else { ans += sum_A[allowed ^ p]; } if (p == 0) break; } } else { int allowed = 0, banned = 0; for (int i = 0; i < L; ++i) { if (que[i] == '0') allowed ^= 1 << (L - i - 1); if (que[i] == '1') banned ^= 1 << (L - i - 1); } for (int p = banned; p >= 0; p = (p - 1) & banned) { if (bit_cnt[p]) { ans -= sum_B[allowed ^ p]; } else { ans += sum_B[allowed ^ p]; } if (p == 0) break; } } cout << ans << '\n'; } } } int main() { ios::sync_with_stdio(0); cin.tie(0); if (fopen(INFILE, "r")) { freopen(INFILE, "r", stdin); freopen(OUTFILE, "w", stdout); } int L, Q; cin >> L >> Q; string digits; cin >> digits; if (L <= 13) { SUBTASK_small_L::main(L, Q, digits); return 0; } if (Q <= 50'000) { SUBTASK_small_Q::main(L, Q, digits); return 0; } return 0; }

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

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen(INFILE, "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:117:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |         freopen(OUTFILE, "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...