답안 #1113342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1113342 2024-11-16T12:05:40 Z emad234 Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
1112 ms 65536 KB
#include "bits/stdc++.h"
#define F first
#define S second
#define ll long long
#define pii pair<ll,int>
const int mxN = (1 << 20) + 5;
const int mod = 1e9 + 7;
using namespace std;
int sos[mxN][23][2];
signed main(){
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
  int n,q;
  cin >>n>>q;
  string s;
  cin>>s;
  for(int i = 0;i < n;i++){
    for(int mask = 0;mask < (1 << n);mask++){
      sos[mask][0][0] = s[mask] - '0';
  if(mask % 2) sos[mask][0][0] += s[mask - 1] - '0';
      sos[mask][0][1] = s[mask] - '0';
  if(mask % 2 == 0) sos[mask][0][1] += s[mask + 1] - '0';
      if(!i) continue;
      sos[mask][i][0] = sos[mask][i - 1][0];
      sos[mask][i][1] = sos[mask][i - 1][1];
      if(mask >> i & 1) sos[mask][i][0] += sos[mask - (1 << i)][i - 1][0];
      else sos[mask][i][1] += sos[mask + (1 << i)][i - 1][1];
    }
  }
  while(q--){
    string a;
    cin >>a;
    reverse(a.begin(),a.end());
    int Qcnt = 0, Ocnt = 0, Icnt = 0;
    for(auto x : a){
      if(x == '?') Qcnt++;
      else if(x == '1') Icnt++;
      else Ocnt++;
    }
    int ans = 0;
    if(min({Qcnt,Ocnt,Icnt}) == Qcnt){
      // printf("? small\n");
      for(int mask = 0;mask < (1 << Qcnt);mask++){
        int cnt = 0;
        int num = 0;
        int i = 0;
        for(auto x : a){
          if(x == '?') {
            if(mask >> cnt & 1) num += (1 << i);
              cnt++;
          }
          if(x == '1') num += (1 << i);
          i++;
        }
        ans += s[num] - '0';
      }
    }else if(min({Qcnt,Ocnt,Icnt}) == Icnt){
      // printf("1 small\n");
      for(int mask = 0; mask < (1 << Icnt);mask++){
        int cnt = 0;
        int num = 0;
        int i = 0;
        for(auto x : a){
          if(x == '1') {
            if(mask >> cnt & 1) num += (1 << i);
              cnt++;
          }
          if(x == '?') num += (1 << i);
          i++;
        }
        if(Icnt % 2 == __builtin_popcount(mask) % 2) ans += sos[num][n - 1][0];
        else ans -= sos[num][n - 1][0];
      }
    }else{
      for(int mask = 0; mask < (1 << Ocnt);mask++){
        // printf("0 small\n");
        int cnt = 0;
        int num = 0;
        int i = 0;
        for(auto x : a){
          if(x == '0') {
            if(mask >> cnt & 1) num += (1 << i);
              cnt++;
          }
          if(x == '1') num += (1 << i);
          // if(x == '?') num += (1 << i);
          i++;
        }
        if(0 == __builtin_popcount(mask) % 2) ans += sos[num][n - 1][1];
        else ans -= sos[num][n - 1][1];
      }
    }
    cout<<ans<<'\n';
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 162 ms 4664 KB Output is correct
12 Correct 161 ms 4268 KB Output is correct
13 Correct 200 ms 3400 KB Output is correct
14 Correct 257 ms 3656 KB Output is correct
15 Correct 199 ms 4424 KB Output is correct
16 Correct 317 ms 3652 KB Output is correct
17 Correct 280 ms 3660 KB Output is correct
18 Correct 124 ms 5464 KB Output is correct
19 Correct 144 ms 2632 KB Output is correct
20 Correct 167 ms 4168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 162 ms 4664 KB Output is correct
12 Correct 161 ms 4268 KB Output is correct
13 Correct 200 ms 3400 KB Output is correct
14 Correct 257 ms 3656 KB Output is correct
15 Correct 199 ms 4424 KB Output is correct
16 Correct 317 ms 3652 KB Output is correct
17 Correct 280 ms 3660 KB Output is correct
18 Correct 124 ms 5464 KB Output is correct
19 Correct 144 ms 2632 KB Output is correct
20 Correct 167 ms 4168 KB Output is correct
21 Correct 179 ms 5744 KB Output is correct
22 Correct 196 ms 6220 KB Output is correct
23 Correct 457 ms 4936 KB Output is correct
24 Correct 958 ms 18456 KB Output is correct
25 Correct 292 ms 20600 KB Output is correct
26 Correct 794 ms 19076 KB Output is correct
27 Correct 608 ms 19012 KB Output is correct
28 Correct 141 ms 21576 KB Output is correct
29 Correct 191 ms 17480 KB Output is correct
30 Correct 232 ms 19424 KB Output is correct
31 Correct 524 ms 19528 KB Output is correct
32 Correct 1112 ms 19504 KB Output is correct
33 Correct 242 ms 18352 KB Output is correct
34 Correct 751 ms 18504 KB Output is correct
35 Correct 619 ms 19020 KB Output is correct
36 Correct 164 ms 17484 KB Output is correct
37 Correct 192 ms 19528 KB Output is correct
38 Correct 197 ms 17616 KB Output is correct
39 Correct 521 ms 18720 KB Output is correct
40 Correct 985 ms 18440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Runtime error 46 ms 65536 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 592 KB Output is correct
2 Correct 2 ms 592 KB Output is correct
3 Correct 1 ms 592 KB Output is correct
4 Correct 2 ms 760 KB Output is correct
5 Correct 1 ms 592 KB Output is correct
6 Correct 2 ms 760 KB Output is correct
7 Correct 1 ms 592 KB Output is correct
8 Correct 1 ms 592 KB Output is correct
9 Correct 1 ms 592 KB Output is correct
10 Correct 1 ms 592 KB Output is correct
11 Correct 162 ms 4664 KB Output is correct
12 Correct 161 ms 4268 KB Output is correct
13 Correct 200 ms 3400 KB Output is correct
14 Correct 257 ms 3656 KB Output is correct
15 Correct 199 ms 4424 KB Output is correct
16 Correct 317 ms 3652 KB Output is correct
17 Correct 280 ms 3660 KB Output is correct
18 Correct 124 ms 5464 KB Output is correct
19 Correct 144 ms 2632 KB Output is correct
20 Correct 167 ms 4168 KB Output is correct
21 Correct 179 ms 5744 KB Output is correct
22 Correct 196 ms 6220 KB Output is correct
23 Correct 457 ms 4936 KB Output is correct
24 Correct 958 ms 18456 KB Output is correct
25 Correct 292 ms 20600 KB Output is correct
26 Correct 794 ms 19076 KB Output is correct
27 Correct 608 ms 19012 KB Output is correct
28 Correct 141 ms 21576 KB Output is correct
29 Correct 191 ms 17480 KB Output is correct
30 Correct 232 ms 19424 KB Output is correct
31 Correct 524 ms 19528 KB Output is correct
32 Correct 1112 ms 19504 KB Output is correct
33 Correct 242 ms 18352 KB Output is correct
34 Correct 751 ms 18504 KB Output is correct
35 Correct 619 ms 19020 KB Output is correct
36 Correct 164 ms 17484 KB Output is correct
37 Correct 192 ms 19528 KB Output is correct
38 Correct 197 ms 17616 KB Output is correct
39 Correct 521 ms 18720 KB Output is correct
40 Correct 985 ms 18440 KB Output is correct
41 Runtime error 46 ms 65536 KB Execution killed with signal 9
42 Halted 0 ms 0 KB -