Submission #735817

#TimeUsernameProblemLanguageResultExecution timeMemory
735817lovrotSnake Escaping (JOI18_snake_escaping)C++17
100 / 100
1910 ms46300 KiB
#include <cstdio> #include <vector> #include <cstring> #include <string> #include <algorithm> #define X first #define Y second #define pb push_back using namespace std; typedef pair<int, int> pii; const int LOG = 20; const int OFF = 1 << LOG; int n, m, P[OFF], sum; int POP[OFF], SUB[OFF], HIP[OFF]; int count(int mask) { return __builtin_popcount(mask); } int main() { scanf("%d%d", &n, &m); int off = 1 << n; for(int i = 0; i < off; i++) { char c; scanf(" %c", &c); P[i] = c - '0'; SUB[i] = HIP[i] = P[i]; sum += P[i]; POP[i] = count(i); } for(int i = 0; i < n; i++) for(int mask = 0; mask < off; mask++) { if(mask & 1 << i) SUB[mask] += SUB[mask ^ 1 << i]; else HIP[mask] += HIP[mask ^ 1 << i]; } for(int t = 0; t < m; t++) { int zer = 0; int one = 0; int que = 0; for(int i = 0, j = n - 1; i < n; i++, j--) { char c; scanf(" %c", &c); if(c == '?') que |= 1 << j; else if (c == '1') one |= 1 << j; else zer |= 1 << j; } int nim = min({POP[zer], POP[que], POP[one]}); int sol = 0; if(POP[zer] == nim) { //0 for(int mask = zer; ; mask = (mask - 1) & zer) { sol += (POP[mask] & 1 ? -1 : 1) * HIP[mask | one]; if(mask == 0) break; } } else if(POP[one] == nim) { //1 for(int mask = one; ; mask = (mask - 1) & one) { sol += (POP[mask] & 1 ? -1 : 1) * SUB[que | (one ^ mask)]; if(mask == 0) break; } } else { //? for(int mask = que; ; mask = (mask - 1) & que) { sol += P[mask | one]; if(mask == 0) break; } } printf("%d\n", sol); } return 0; }

Compilation message (stderr)

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
snake_escaping.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf(" %c", &c);
      |   ~~~~~^~~~~~~~~~~
snake_escaping.cpp:48:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |    scanf(" %c", &c);
      |    ~~~~~^~~~~~~~~~~
#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...