답안 #667178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
667178 2022-11-30T16:06:41 Z Kahou Snake Escaping (JOI18_snake_escaping) C++14
22 / 100
346 ms 26264 KB
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define endl '\n'
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;

const int N = 15;
const int M = 2e6;
int n, q, dp[M], pw[N];
string s;

void solve() {
    cin >> n >> q;
    cin >> s;
    for (int i = 0; i < (1<<n); i++) {
        int nmask = 0;
        for (int j = 12; j >= 0; j--) {
            nmask *= 3;
            nmask += (i>>j&1);
        }
        dp[nmask] += (s[i]-'0');
    }
    pw[0] = 1;
    for (int i = 1; i <= n; i++) {
        pw[i] = pw[i-1]*3;
    }
    for (int i = 0; i < n; i++) {
        for (int mask = 0; mask < pw[n]; mask++) {
            if ((mask/pw[i])%3 == 2) {
                dp[mask] += dp[mask-pw[i]] + dp[mask-2*pw[i]];
            }
        }
    }

    while (q--) {
        string t;
        cin >> t;

        int mask = 0;
        for (int i = 0; i < n; i++) {
            mask *= 3;
            mask += (t[i]!='0') + (t[i] == '?');
        }
        cout << dp[mask] << endl;
    }
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 5 ms 580 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 5 ms 580 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
11 Correct 153 ms 15220 KB Output is correct
12 Correct 161 ms 15052 KB Output is correct
13 Correct 152 ms 14392 KB Output is correct
14 Correct 158 ms 14284 KB Output is correct
15 Correct 148 ms 15324 KB Output is correct
16 Correct 150 ms 14384 KB Output is correct
17 Correct 146 ms 14376 KB Output is correct
18 Correct 153 ms 16284 KB Output is correct
19 Correct 147 ms 13252 KB Output is correct
20 Correct 159 ms 14892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 5 ms 580 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
11 Correct 153 ms 15220 KB Output is correct
12 Correct 161 ms 15052 KB Output is correct
13 Correct 152 ms 14392 KB Output is correct
14 Correct 158 ms 14284 KB Output is correct
15 Correct 148 ms 15324 KB Output is correct
16 Correct 150 ms 14384 KB Output is correct
17 Correct 146 ms 14376 KB Output is correct
18 Correct 153 ms 16284 KB Output is correct
19 Correct 147 ms 13252 KB Output is correct
20 Correct 159 ms 14892 KB Output is correct
21 Correct 288 ms 24344 KB Output is correct
22 Correct 293 ms 24452 KB Output is correct
23 Correct 299 ms 23372 KB Output is correct
24 Correct 299 ms 23220 KB Output is correct
25 Correct 303 ms 25220 KB Output is correct
26 Correct 316 ms 23716 KB Output is correct
27 Correct 346 ms 23704 KB Output is correct
28 Correct 285 ms 26264 KB Output is correct
29 Correct 281 ms 22204 KB Output is correct
30 Correct 289 ms 24456 KB Output is correct
31 Correct 309 ms 24236 KB Output is correct
32 Correct 306 ms 24212 KB Output is correct
33 Correct 283 ms 23156 KB Output is correct
34 Correct 312 ms 23256 KB Output is correct
35 Correct 339 ms 23640 KB Output is correct
36 Correct 281 ms 22296 KB Output is correct
37 Correct 285 ms 24304 KB Output is correct
38 Correct 282 ms 22300 KB Output is correct
39 Correct 306 ms 23356 KB Output is correct
40 Correct 305 ms 23304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 5 ms 580 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
11 Runtime error 16 ms 5072 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 468 KB Output is correct
2 Correct 4 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 4 ms 468 KB Output is correct
5 Correct 4 ms 572 KB Output is correct
6 Correct 4 ms 468 KB Output is correct
7 Correct 4 ms 460 KB Output is correct
8 Correct 4 ms 596 KB Output is correct
9 Correct 5 ms 580 KB Output is correct
10 Correct 4 ms 576 KB Output is correct
11 Correct 153 ms 15220 KB Output is correct
12 Correct 161 ms 15052 KB Output is correct
13 Correct 152 ms 14392 KB Output is correct
14 Correct 158 ms 14284 KB Output is correct
15 Correct 148 ms 15324 KB Output is correct
16 Correct 150 ms 14384 KB Output is correct
17 Correct 146 ms 14376 KB Output is correct
18 Correct 153 ms 16284 KB Output is correct
19 Correct 147 ms 13252 KB Output is correct
20 Correct 159 ms 14892 KB Output is correct
21 Correct 288 ms 24344 KB Output is correct
22 Correct 293 ms 24452 KB Output is correct
23 Correct 299 ms 23372 KB Output is correct
24 Correct 299 ms 23220 KB Output is correct
25 Correct 303 ms 25220 KB Output is correct
26 Correct 316 ms 23716 KB Output is correct
27 Correct 346 ms 23704 KB Output is correct
28 Correct 285 ms 26264 KB Output is correct
29 Correct 281 ms 22204 KB Output is correct
30 Correct 289 ms 24456 KB Output is correct
31 Correct 309 ms 24236 KB Output is correct
32 Correct 306 ms 24212 KB Output is correct
33 Correct 283 ms 23156 KB Output is correct
34 Correct 312 ms 23256 KB Output is correct
35 Correct 339 ms 23640 KB Output is correct
36 Correct 281 ms 22296 KB Output is correct
37 Correct 285 ms 24304 KB Output is correct
38 Correct 282 ms 22300 KB Output is correct
39 Correct 306 ms 23356 KB Output is correct
40 Correct 305 ms 23304 KB Output is correct
41 Runtime error 16 ms 5072 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -