답안 #817596

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817596 2023-08-09T13:50:23 Z kwongweng Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 19152 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
 
int main(){
  ios::sync_with_stdio(false);
  if (fopen("input.txt", "r")){
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  }
  int L, Q; cin>>L>>Q;
  string s; cin >> s;
  int A[1<<L];
  int dp[1<<L]; FOR(i,0,(1<<L)) A[i]=dp[i]=s[i]-'0';
  int dp2[1<<L]; FOR(i,0,(1<<L)) dp2[i]=dp[(1<<L)-1-i];
  FOR(i,0,L){
    FOR(mask,0,(1<<L)){
      if (mask & (1<<i)) {dp[mask] += dp[mask-(1<<i)]; dp2[mask] += dp2[mask-(1<<i)];}
    }
  }
  FOR(i,0,Q){
    string t; cin >> t; reverse(t.begin(), t.end());
    int cnt1=0, cnt2=0; FOR(j,0,L) {cnt1 += (t[j]=='?'); cnt2 += (t[j]=='1');}
    int cnt3=L-cnt1-cnt2;
    if (cnt1 <= min(cnt2, cnt3)){
      int ans = 0;
      vi a; int cur = 0;
      FOR(j,0,L){
        if (t[j]=='?') a.pb(j);
        else cur += (1<<j)*(t[j]-'0');
      }
      FOR(j,0,(1<<cnt1)){
        int val=0; FOR(k,0,cnt1){
          if (j & (1<<k)) val ^= (1<<a[k]);
        }
        //cout<<cur+val<<" ";
        ans+=A[cur^val];
      }
      cout<<ans<<'\n'; continue;
    }
    if (cnt2 <= cnt3){
      vi a; int cur=0;
      FOR(j,0,L){
        if (t[j]=='1') {a.pb(j); cur ^= (1<<j);}
        if (t[j]=='?') cur ^= (1<<j);
      }
      int ans = 0;
      FOR(j,0,(1<<cnt2)){
        int val=0; FOR(k,0,cnt2){
          if (j & (1<<k)) {val ^= (1<<a[k]);}
        }
        //PIE
        if (__builtin_popcount(val)%2==1) ans -= dp[cur^val];
        else ans += dp[cur^val];
      }
      cout<<ans<<'\n'; continue;
    }
    vi a; int cur=0;
    FOR(j,0,L){
      if (t[j] != '1') cur ^= (1<<j);
      if (t[j] == '0') a.pb(j);
    }
    int ans=0;
    FOR(j,0,(1<<cnt3)){
      int val=0; FOR(k,0,cnt3){
        if (j & (1<<k)) {val ^= (1<<a[k]);}
      }
      //PIE
      if (__builtin_popcount(val)%2==1) ans-=dp2[cur^val];
      else ans+=dp2[cur^val];
    }
    cout<<ans<<'\n';
  }
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:20:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 1192 ms 4500 KB Output is correct
12 Correct 1192 ms 4240 KB Output is correct
13 Correct 1260 ms 3432 KB Output is correct
14 Correct 1347 ms 3512 KB Output is correct
15 Correct 1379 ms 4512 KB Output is correct
16 Correct 1433 ms 3720 KB Output is correct
17 Correct 1371 ms 3680 KB Output is correct
18 Correct 1268 ms 5464 KB Output is correct
19 Correct 1224 ms 2524 KB Output is correct
20 Correct 1322 ms 4188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 1192 ms 4500 KB Output is correct
12 Correct 1192 ms 4240 KB Output is correct
13 Correct 1260 ms 3432 KB Output is correct
14 Correct 1347 ms 3512 KB Output is correct
15 Correct 1379 ms 4512 KB Output is correct
16 Correct 1433 ms 3720 KB Output is correct
17 Correct 1371 ms 3680 KB Output is correct
18 Correct 1268 ms 5464 KB Output is correct
19 Correct 1224 ms 2524 KB Output is correct
20 Correct 1322 ms 4188 KB Output is correct
21 Correct 1204 ms 4676 KB Output is correct
22 Correct 1231 ms 4832 KB Output is correct
23 Correct 1342 ms 3780 KB Output is correct
24 Correct 1418 ms 3584 KB Output is correct
25 Correct 1327 ms 5660 KB Output is correct
26 Correct 1405 ms 4216 KB Output is correct
27 Correct 1413 ms 4036 KB Output is correct
28 Correct 1153 ms 6712 KB Output is correct
29 Correct 1146 ms 2664 KB Output is correct
30 Correct 1288 ms 4820 KB Output is correct
31 Correct 1451 ms 4628 KB Output is correct
32 Correct 1680 ms 4568 KB Output is correct
33 Correct 1450 ms 3716 KB Output is correct
34 Correct 1545 ms 3924 KB Output is correct
35 Correct 1533 ms 4364 KB Output is correct
36 Correct 1180 ms 2900 KB Output is correct
37 Correct 1226 ms 5072 KB Output is correct
38 Correct 1131 ms 3040 KB Output is correct
39 Correct 1356 ms 4136 KB Output is correct
40 Correct 1378 ms 3960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 100 ms 14484 KB Output is correct
12 Correct 100 ms 14472 KB Output is correct
13 Correct 111 ms 14404 KB Output is correct
14 Correct 137 ms 14456 KB Output is correct
15 Correct 104 ms 14536 KB Output is correct
16 Correct 135 ms 14480 KB Output is correct
17 Correct 136 ms 14404 KB Output is correct
18 Correct 94 ms 14644 KB Output is correct
19 Correct 108 ms 14284 KB Output is correct
20 Correct 111 ms 14444 KB Output is correct
21 Correct 116 ms 14528 KB Output is correct
22 Correct 156 ms 14444 KB Output is correct
23 Correct 102 ms 14356 KB Output is correct
24 Correct 132 ms 14488 KB Output is correct
25 Correct 128 ms 14464 KB Output is correct
26 Correct 91 ms 14472 KB Output is correct
27 Correct 100 ms 14440 KB Output is correct
28 Correct 97 ms 14356 KB Output is correct
29 Correct 139 ms 14376 KB Output is correct
30 Correct 128 ms 14388 KB Output is correct
31 Correct 102 ms 14420 KB Output is correct
32 Correct 149 ms 14452 KB Output is correct
33 Correct 138 ms 14392 KB Output is correct
34 Correct 92 ms 14364 KB Output is correct
35 Correct 125 ms 14468 KB Output is correct
36 Correct 131 ms 14492 KB Output is correct
37 Correct 129 ms 14384 KB Output is correct
38 Correct 126 ms 14476 KB Output is correct
39 Correct 124 ms 14444 KB Output is correct
40 Correct 147 ms 14596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 328 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 2 ms 324 KB Output is correct
11 Correct 1192 ms 4500 KB Output is correct
12 Correct 1192 ms 4240 KB Output is correct
13 Correct 1260 ms 3432 KB Output is correct
14 Correct 1347 ms 3512 KB Output is correct
15 Correct 1379 ms 4512 KB Output is correct
16 Correct 1433 ms 3720 KB Output is correct
17 Correct 1371 ms 3680 KB Output is correct
18 Correct 1268 ms 5464 KB Output is correct
19 Correct 1224 ms 2524 KB Output is correct
20 Correct 1322 ms 4188 KB Output is correct
21 Correct 1204 ms 4676 KB Output is correct
22 Correct 1231 ms 4832 KB Output is correct
23 Correct 1342 ms 3780 KB Output is correct
24 Correct 1418 ms 3584 KB Output is correct
25 Correct 1327 ms 5660 KB Output is correct
26 Correct 1405 ms 4216 KB Output is correct
27 Correct 1413 ms 4036 KB Output is correct
28 Correct 1153 ms 6712 KB Output is correct
29 Correct 1146 ms 2664 KB Output is correct
30 Correct 1288 ms 4820 KB Output is correct
31 Correct 1451 ms 4628 KB Output is correct
32 Correct 1680 ms 4568 KB Output is correct
33 Correct 1450 ms 3716 KB Output is correct
34 Correct 1545 ms 3924 KB Output is correct
35 Correct 1533 ms 4364 KB Output is correct
36 Correct 1180 ms 2900 KB Output is correct
37 Correct 1226 ms 5072 KB Output is correct
38 Correct 1131 ms 3040 KB Output is correct
39 Correct 1356 ms 4136 KB Output is correct
40 Correct 1378 ms 3960 KB Output is correct
41 Correct 100 ms 14484 KB Output is correct
42 Correct 100 ms 14472 KB Output is correct
43 Correct 111 ms 14404 KB Output is correct
44 Correct 137 ms 14456 KB Output is correct
45 Correct 104 ms 14536 KB Output is correct
46 Correct 135 ms 14480 KB Output is correct
47 Correct 136 ms 14404 KB Output is correct
48 Correct 94 ms 14644 KB Output is correct
49 Correct 108 ms 14284 KB Output is correct
50 Correct 111 ms 14444 KB Output is correct
51 Correct 116 ms 14528 KB Output is correct
52 Correct 156 ms 14444 KB Output is correct
53 Correct 102 ms 14356 KB Output is correct
54 Correct 132 ms 14488 KB Output is correct
55 Correct 128 ms 14464 KB Output is correct
56 Correct 91 ms 14472 KB Output is correct
57 Correct 100 ms 14440 KB Output is correct
58 Correct 97 ms 14356 KB Output is correct
59 Correct 139 ms 14376 KB Output is correct
60 Correct 128 ms 14388 KB Output is correct
61 Correct 102 ms 14420 KB Output is correct
62 Correct 149 ms 14452 KB Output is correct
63 Correct 138 ms 14392 KB Output is correct
64 Correct 92 ms 14364 KB Output is correct
65 Correct 125 ms 14468 KB Output is correct
66 Correct 131 ms 14492 KB Output is correct
67 Correct 129 ms 14384 KB Output is correct
68 Correct 126 ms 14476 KB Output is correct
69 Correct 124 ms 14444 KB Output is correct
70 Correct 147 ms 14596 KB Output is correct
71 Correct 1524 ms 18972 KB Output is correct
72 Correct 1497 ms 19152 KB Output is correct
73 Correct 1878 ms 17612 KB Output is correct
74 Execution timed out 2057 ms 17524 KB Time limit exceeded
75 Halted 0 ms 0 KB -