답안 #970550

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970550 2024-04-26T17:15:23 Z mychecksedad Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
302 ms 15700 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 2e6+100, M = 1e5+10, K = 13, MX = 30;

int n, q, dp[N], dp2[N];
string s;
void solve(){
  cin >> n >> q >> s;
  for(int i = 0; i < (1<<n); ++i) dp[i] = dp2[i] = s[i] - '0';
  for(int i = 0; i < n; ++i){
    for(int mask = 0; mask < (1<<n); ++mask){
      if(((1<<i)&mask) == 0) dp[mask] += dp[(1<<i) ^ mask];
      if(((1<<i)&mask)) dp2[mask] += dp2[(1<<i) ^ mask];
    }
  }
  for(int i = 0; i < q; ++i){
    string t; cin >> t;
    int A = 0, B = 0, C = 0;
    for(int j = 0; j < n; ++j){
      if(t[n-j-1] == '0') A += (1<<j);
      if(t[n-j-1] == '1') B += (1<<j);
      if(t[n-j-1] == '?') C += (1<<j);
    }
    if(__builtin_popcount(C) <= 6){
      int ans = 0;
      for(int S = C; S > 0; S = (S-1)&C){
        ans += s[S | B] - '0';
      }
      ans += s[B] - '0';
      cout << ans << '\n';
    }else if(__builtin_popcount(A) <= 6){
      int ans = 0;
      for(int S = A; S > 0; S = (S-1)&A){
        ans += dp[B | S] * (__builtin_popcount(S) % 2 == 0 ? 1 : -1);
      }
      ans += dp[B];
      cout << ans << '\n';
    }else{
      int ans = 0;
      for(int S = B; S > 0; S = (S-1)&B){
        ans += dp[S | C] * ((__builtin_popcount(B) - (int)__builtin_popcount(S)) % 2 == 0 ? 1 : -1);
      }
      ans += dp[C] * ((__builtin_popcount(B)) % 2 == 0 ? 1 : -1);
      cout << ans << '\n';
    }
  }

}



int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  // cin >> tt;
  while(tt--){
    solve();
    // en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:61:15: warning: unused variable 'aa' [-Wunused-variable]
   61 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2532 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2520 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2520 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2532 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2520 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2520 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 197 ms 12752 KB Output is correct
12 Correct 204 ms 11992 KB Output is correct
13 Correct 210 ms 11720 KB Output is correct
14 Correct 192 ms 11604 KB Output is correct
15 Correct 244 ms 12328 KB Output is correct
16 Correct 212 ms 11540 KB Output is correct
17 Correct 217 ms 11640 KB Output is correct
18 Correct 126 ms 13556 KB Output is correct
19 Correct 159 ms 10576 KB Output is correct
20 Correct 200 ms 12024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2532 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2520 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2520 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 197 ms 12752 KB Output is correct
12 Correct 204 ms 11992 KB Output is correct
13 Correct 210 ms 11720 KB Output is correct
14 Correct 192 ms 11604 KB Output is correct
15 Correct 244 ms 12328 KB Output is correct
16 Correct 212 ms 11540 KB Output is correct
17 Correct 217 ms 11640 KB Output is correct
18 Correct 126 ms 13556 KB Output is correct
19 Correct 159 ms 10576 KB Output is correct
20 Correct 200 ms 12024 KB Output is correct
21 Correct 184 ms 14036 KB Output is correct
22 Correct 302 ms 14108 KB Output is correct
23 Correct 243 ms 13220 KB Output is correct
24 Correct 228 ms 13136 KB Output is correct
25 Correct 208 ms 14960 KB Output is correct
26 Correct 249 ms 13528 KB Output is correct
27 Correct 256 ms 13684 KB Output is correct
28 Correct 152 ms 15700 KB Output is correct
29 Correct 185 ms 11844 KB Output is correct
30 Correct 229 ms 13652 KB Output is correct
31 Correct 283 ms 13904 KB Output is correct
32 Correct 241 ms 13908 KB Output is correct
33 Correct 204 ms 12884 KB Output is correct
34 Correct 223 ms 12884 KB Output is correct
35 Correct 251 ms 13396 KB Output is correct
36 Correct 149 ms 11852 KB Output is correct
37 Correct 268 ms 13772 KB Output is correct
38 Correct 186 ms 11860 KB Output is correct
39 Correct 259 ms 12820 KB Output is correct
40 Correct 225 ms 12884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2532 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2520 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2520 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 37 ms 13832 KB Output is correct
12 Incorrect 34 ms 13552 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2532 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2520 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2520 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 197 ms 12752 KB Output is correct
12 Correct 204 ms 11992 KB Output is correct
13 Correct 210 ms 11720 KB Output is correct
14 Correct 192 ms 11604 KB Output is correct
15 Correct 244 ms 12328 KB Output is correct
16 Correct 212 ms 11540 KB Output is correct
17 Correct 217 ms 11640 KB Output is correct
18 Correct 126 ms 13556 KB Output is correct
19 Correct 159 ms 10576 KB Output is correct
20 Correct 200 ms 12024 KB Output is correct
21 Correct 184 ms 14036 KB Output is correct
22 Correct 302 ms 14108 KB Output is correct
23 Correct 243 ms 13220 KB Output is correct
24 Correct 228 ms 13136 KB Output is correct
25 Correct 208 ms 14960 KB Output is correct
26 Correct 249 ms 13528 KB Output is correct
27 Correct 256 ms 13684 KB Output is correct
28 Correct 152 ms 15700 KB Output is correct
29 Correct 185 ms 11844 KB Output is correct
30 Correct 229 ms 13652 KB Output is correct
31 Correct 283 ms 13904 KB Output is correct
32 Correct 241 ms 13908 KB Output is correct
33 Correct 204 ms 12884 KB Output is correct
34 Correct 223 ms 12884 KB Output is correct
35 Correct 251 ms 13396 KB Output is correct
36 Correct 149 ms 11852 KB Output is correct
37 Correct 268 ms 13772 KB Output is correct
38 Correct 186 ms 11860 KB Output is correct
39 Correct 259 ms 12820 KB Output is correct
40 Correct 225 ms 12884 KB Output is correct
41 Correct 37 ms 13832 KB Output is correct
42 Incorrect 34 ms 13552 KB Output isn't correct
43 Halted 0 ms 0 KB -