답안 #199750

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199750 2020-02-03T07:08:44 Z Mercenary Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 41496 KB
#include<bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define taskname "A"

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = (1 << 20);
string s;
int n , q;
int dp[2][maxn];
int res , f , nf , tmp;
int cnt[3] , a[maxn];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen(taskname".INP","r")){
		freopen(taskname".INP", "r",stdin);
		freopen(taskname".OUT", "w",stdout);
    }
    cin >> n >> q >> s;
    for(int i = 0 ; i < (1 << n) ; ++i){
        dp[0][i] = dp[1][(1 << n) - 1 - i] = a[i] = s[i] - '0';
    }
    for(int i = 0 ; i < n ; ++i){
        for(int j = (1 << n) - 1 ; j >= 0 ; --j){
            if(j & (1 << i))dp[0][j ^ (1 << i)] += dp[0][j]  , dp[1][j ^ (1 << i)] += dp[1][j] ;
        }
    }
//    cout << dp[1][7];
    while(q--){
        cnt[0] = cnt[1] = cnt[2] = res = f = nf = 0;
        cin >> s;
        for(int i = 0 ; i < n ; ++i){
            if(s[i] == '0')s[i] = 0;
            else if(s[i] == '1')s[i] = 1;
            else s[i] = 2;
            cnt[s[i]] |= (1 << (n - i - 1));
        }
        for(int i = 0 ; i < 3 ; ++i){
            if(__builtin_popcount(cnt[i]) <= n / 3){
                tmp = i;break;
            }
        }
        for(int i = cnt[tmp] ;; i = (i - 1) & cnt[tmp]){
            if(tmp < 2){
                if(__builtin_popcount(i) & 1)res += dp[tmp][i | cnt[!tmp]];
                else res -= dp[tmp][i | cnt[!tmp]];
            }else{
                res += a[i | cnt[1]];
            }
            if(i == 0)break;
        }
        cout << abs(res) << '\n';
    }
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:44:21: warning: array subscript has type 'char' [-Wchar-subscripts]
             cnt[s[i]] |= (1 << (n - i - 1));
                     ^
snake_escaping.cpp:24:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".INP", "r",stdin);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   freopen(taskname".OUT", "w",stdout);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
11 Correct 276 ms 15260 KB Output is correct
12 Correct 315 ms 14968 KB Output is correct
13 Correct 325 ms 14200 KB Output is correct
14 Correct 334 ms 14200 KB Output is correct
15 Correct 290 ms 15224 KB Output is correct
16 Correct 315 ms 14328 KB Output is correct
17 Correct 328 ms 14328 KB Output is correct
18 Correct 309 ms 16248 KB Output is correct
19 Correct 283 ms 13176 KB Output is correct
20 Correct 273 ms 14968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
11 Correct 276 ms 15260 KB Output is correct
12 Correct 315 ms 14968 KB Output is correct
13 Correct 325 ms 14200 KB Output is correct
14 Correct 334 ms 14200 KB Output is correct
15 Correct 290 ms 15224 KB Output is correct
16 Correct 315 ms 14328 KB Output is correct
17 Correct 328 ms 14328 KB Output is correct
18 Correct 309 ms 16248 KB Output is correct
19 Correct 283 ms 13176 KB Output is correct
20 Correct 273 ms 14968 KB Output is correct
21 Correct 320 ms 18296 KB Output is correct
22 Correct 370 ms 18424 KB Output is correct
23 Correct 396 ms 17400 KB Output is correct
24 Correct 427 ms 17272 KB Output is correct
25 Correct 362 ms 19192 KB Output is correct
26 Correct 424 ms 17656 KB Output is correct
27 Correct 383 ms 17656 KB Output is correct
28 Correct 305 ms 20216 KB Output is correct
29 Correct 334 ms 16248 KB Output is correct
30 Correct 306 ms 18424 KB Output is correct
31 Correct 383 ms 18168 KB Output is correct
32 Correct 405 ms 18172 KB Output is correct
33 Correct 355 ms 17144 KB Output is correct
34 Correct 402 ms 17272 KB Output is correct
35 Correct 405 ms 17688 KB Output is correct
36 Correct 280 ms 16244 KB Output is correct
37 Correct 323 ms 18376 KB Output is correct
38 Correct 366 ms 16248 KB Output is correct
39 Correct 364 ms 17400 KB Output is correct
40 Correct 396 ms 17272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
11 Correct 74 ms 16156 KB Output is correct
12 Correct 83 ms 16156 KB Output is correct
13 Correct 95 ms 16024 KB Output is correct
14 Correct 123 ms 16140 KB Output is correct
15 Correct 69 ms 16152 KB Output is correct
16 Correct 105 ms 16088 KB Output is correct
17 Correct 120 ms 16024 KB Output is correct
18 Correct 62 ms 16280 KB Output is correct
19 Correct 68 ms 16036 KB Output is correct
20 Correct 71 ms 16152 KB Output is correct
21 Correct 81 ms 16152 KB Output is correct
22 Correct 87 ms 16032 KB Output is correct
23 Correct 75 ms 16024 KB Output is correct
24 Correct 112 ms 16024 KB Output is correct
25 Correct 109 ms 16152 KB Output is correct
26 Correct 62 ms 16024 KB Output is correct
27 Correct 72 ms 16280 KB Output is correct
28 Correct 74 ms 16024 KB Output is correct
29 Correct 90 ms 16024 KB Output is correct
30 Correct 84 ms 16024 KB Output is correct
31 Correct 70 ms 16000 KB Output is correct
32 Correct 127 ms 16148 KB Output is correct
33 Correct 111 ms 16280 KB Output is correct
34 Correct 57 ms 16024 KB Output is correct
35 Correct 96 ms 16064 KB Output is correct
36 Correct 127 ms 16028 KB Output is correct
37 Correct 105 ms 16132 KB Output is correct
38 Correct 99 ms 16152 KB Output is correct
39 Correct 108 ms 16024 KB Output is correct
40 Correct 110 ms 16016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 6 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 6 ms 376 KB Output is correct
8 Correct 6 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 6 ms 380 KB Output is correct
11 Correct 276 ms 15260 KB Output is correct
12 Correct 315 ms 14968 KB Output is correct
13 Correct 325 ms 14200 KB Output is correct
14 Correct 334 ms 14200 KB Output is correct
15 Correct 290 ms 15224 KB Output is correct
16 Correct 315 ms 14328 KB Output is correct
17 Correct 328 ms 14328 KB Output is correct
18 Correct 309 ms 16248 KB Output is correct
19 Correct 283 ms 13176 KB Output is correct
20 Correct 273 ms 14968 KB Output is correct
21 Correct 320 ms 18296 KB Output is correct
22 Correct 370 ms 18424 KB Output is correct
23 Correct 396 ms 17400 KB Output is correct
24 Correct 427 ms 17272 KB Output is correct
25 Correct 362 ms 19192 KB Output is correct
26 Correct 424 ms 17656 KB Output is correct
27 Correct 383 ms 17656 KB Output is correct
28 Correct 305 ms 20216 KB Output is correct
29 Correct 334 ms 16248 KB Output is correct
30 Correct 306 ms 18424 KB Output is correct
31 Correct 383 ms 18168 KB Output is correct
32 Correct 405 ms 18172 KB Output is correct
33 Correct 355 ms 17144 KB Output is correct
34 Correct 402 ms 17272 KB Output is correct
35 Correct 405 ms 17688 KB Output is correct
36 Correct 280 ms 16244 KB Output is correct
37 Correct 323 ms 18376 KB Output is correct
38 Correct 366 ms 16248 KB Output is correct
39 Correct 364 ms 17400 KB Output is correct
40 Correct 396 ms 17272 KB Output is correct
41 Correct 74 ms 16156 KB Output is correct
42 Correct 83 ms 16156 KB Output is correct
43 Correct 95 ms 16024 KB Output is correct
44 Correct 123 ms 16140 KB Output is correct
45 Correct 69 ms 16152 KB Output is correct
46 Correct 105 ms 16088 KB Output is correct
47 Correct 120 ms 16024 KB Output is correct
48 Correct 62 ms 16280 KB Output is correct
49 Correct 68 ms 16036 KB Output is correct
50 Correct 71 ms 16152 KB Output is correct
51 Correct 81 ms 16152 KB Output is correct
52 Correct 87 ms 16032 KB Output is correct
53 Correct 75 ms 16024 KB Output is correct
54 Correct 112 ms 16024 KB Output is correct
55 Correct 109 ms 16152 KB Output is correct
56 Correct 62 ms 16024 KB Output is correct
57 Correct 72 ms 16280 KB Output is correct
58 Correct 74 ms 16024 KB Output is correct
59 Correct 90 ms 16024 KB Output is correct
60 Correct 84 ms 16024 KB Output is correct
61 Correct 70 ms 16000 KB Output is correct
62 Correct 127 ms 16148 KB Output is correct
63 Correct 111 ms 16280 KB Output is correct
64 Correct 57 ms 16024 KB Output is correct
65 Correct 96 ms 16064 KB Output is correct
66 Correct 127 ms 16028 KB Output is correct
67 Correct 105 ms 16132 KB Output is correct
68 Correct 99 ms 16152 KB Output is correct
69 Correct 108 ms 16024 KB Output is correct
70 Correct 110 ms 16016 KB Output is correct
71 Correct 494 ms 40472 KB Output is correct
72 Correct 608 ms 40604 KB Output is correct
73 Correct 889 ms 39192 KB Output is correct
74 Correct 1093 ms 39576 KB Output is correct
75 Correct 545 ms 41496 KB Output is correct
76 Correct 1184 ms 39960 KB Output is correct
77 Execution timed out 2102 ms 36120 KB Time limit exceeded
78 Halted 0 ms 0 KB -