Submission #199751

# Submission time Handle Problem Language Result Execution time Memory
199751 2020-02-03T07:10:47 Z Mercenary Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 19124 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));
        }
        tmp = min_element(cnt,cnt+3)-cnt;
        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);
   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 268 ms 4344 KB Output is correct
12 Correct 291 ms 4088 KB Output is correct
13 Correct 327 ms 3320 KB Output is correct
14 Correct 331 ms 3424 KB Output is correct
15 Correct 315 ms 4416 KB Output is correct
16 Correct 344 ms 3576 KB Output is correct
17 Correct 349 ms 3580 KB Output is correct
18 Correct 258 ms 5624 KB Output is correct
19 Correct 274 ms 2424 KB Output is correct
20 Correct 264 ms 4088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 268 ms 4344 KB Output is correct
12 Correct 291 ms 4088 KB Output is correct
13 Correct 327 ms 3320 KB Output is correct
14 Correct 331 ms 3424 KB Output is correct
15 Correct 315 ms 4416 KB Output is correct
16 Correct 344 ms 3576 KB Output is correct
17 Correct 349 ms 3580 KB Output is correct
18 Correct 258 ms 5624 KB Output is correct
19 Correct 274 ms 2424 KB Output is correct
20 Correct 264 ms 4088 KB Output is correct
21 Correct 293 ms 4472 KB Output is correct
22 Correct 338 ms 4904 KB Output is correct
23 Correct 428 ms 3960 KB Output is correct
24 Correct 408 ms 3448 KB Output is correct
25 Correct 360 ms 5496 KB Output is correct
26 Correct 421 ms 4216 KB Output is correct
27 Correct 433 ms 4068 KB Output is correct
28 Correct 288 ms 6520 KB Output is correct
29 Correct 322 ms 2424 KB Output is correct
30 Correct 300 ms 4856 KB Output is correct
31 Correct 393 ms 4592 KB Output is correct
32 Correct 408 ms 4472 KB Output is correct
33 Correct 399 ms 3576 KB Output is correct
34 Correct 403 ms 3576 KB Output is correct
35 Correct 416 ms 3960 KB Output is correct
36 Correct 274 ms 2552 KB Output is correct
37 Correct 318 ms 4600 KB Output is correct
38 Correct 317 ms 2424 KB Output is correct
39 Correct 397 ms 3728 KB Output is correct
40 Correct 397 ms 3540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 67 ms 14104 KB Output is correct
12 Correct 68 ms 14116 KB Output is correct
13 Correct 138 ms 14104 KB Output is correct
14 Correct 144 ms 13976 KB Output is correct
15 Correct 115 ms 14104 KB Output is correct
16 Correct 161 ms 14104 KB Output is correct
17 Correct 169 ms 14108 KB Output is correct
18 Correct 65 ms 14236 KB Output is correct
19 Correct 65 ms 13848 KB Output is correct
20 Correct 67 ms 14104 KB Output is correct
21 Correct 125 ms 13992 KB Output is correct
22 Correct 142 ms 13984 KB Output is correct
23 Correct 211 ms 13980 KB Output is correct
24 Correct 165 ms 13980 KB Output is correct
25 Correct 170 ms 13976 KB Output is correct
26 Correct 58 ms 13848 KB Output is correct
27 Correct 68 ms 14104 KB Output is correct
28 Correct 69 ms 13848 KB Output is correct
29 Correct 153 ms 13976 KB Output is correct
30 Correct 144 ms 13976 KB Output is correct
31 Correct 200 ms 13972 KB Output is correct
32 Correct 155 ms 13976 KB Output is correct
33 Correct 156 ms 13976 KB Output is correct
34 Correct 57 ms 13848 KB Output is correct
35 Correct 135 ms 13976 KB Output is correct
36 Correct 143 ms 14080 KB Output is correct
37 Correct 130 ms 13976 KB Output is correct
38 Correct 145 ms 13976 KB Output is correct
39 Correct 127 ms 13976 KB Output is correct
40 Correct 133 ms 14116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 6 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 268 ms 4344 KB Output is correct
12 Correct 291 ms 4088 KB Output is correct
13 Correct 327 ms 3320 KB Output is correct
14 Correct 331 ms 3424 KB Output is correct
15 Correct 315 ms 4416 KB Output is correct
16 Correct 344 ms 3576 KB Output is correct
17 Correct 349 ms 3580 KB Output is correct
18 Correct 258 ms 5624 KB Output is correct
19 Correct 274 ms 2424 KB Output is correct
20 Correct 264 ms 4088 KB Output is correct
21 Correct 293 ms 4472 KB Output is correct
22 Correct 338 ms 4904 KB Output is correct
23 Correct 428 ms 3960 KB Output is correct
24 Correct 408 ms 3448 KB Output is correct
25 Correct 360 ms 5496 KB Output is correct
26 Correct 421 ms 4216 KB Output is correct
27 Correct 433 ms 4068 KB Output is correct
28 Correct 288 ms 6520 KB Output is correct
29 Correct 322 ms 2424 KB Output is correct
30 Correct 300 ms 4856 KB Output is correct
31 Correct 393 ms 4592 KB Output is correct
32 Correct 408 ms 4472 KB Output is correct
33 Correct 399 ms 3576 KB Output is correct
34 Correct 403 ms 3576 KB Output is correct
35 Correct 416 ms 3960 KB Output is correct
36 Correct 274 ms 2552 KB Output is correct
37 Correct 318 ms 4600 KB Output is correct
38 Correct 317 ms 2424 KB Output is correct
39 Correct 397 ms 3728 KB Output is correct
40 Correct 397 ms 3540 KB Output is correct
41 Correct 67 ms 14104 KB Output is correct
42 Correct 68 ms 14116 KB Output is correct
43 Correct 138 ms 14104 KB Output is correct
44 Correct 144 ms 13976 KB Output is correct
45 Correct 115 ms 14104 KB Output is correct
46 Correct 161 ms 14104 KB Output is correct
47 Correct 169 ms 14108 KB Output is correct
48 Correct 65 ms 14236 KB Output is correct
49 Correct 65 ms 13848 KB Output is correct
50 Correct 67 ms 14104 KB Output is correct
51 Correct 125 ms 13992 KB Output is correct
52 Correct 142 ms 13984 KB Output is correct
53 Correct 211 ms 13980 KB Output is correct
54 Correct 165 ms 13980 KB Output is correct
55 Correct 170 ms 13976 KB Output is correct
56 Correct 58 ms 13848 KB Output is correct
57 Correct 68 ms 14104 KB Output is correct
58 Correct 69 ms 13848 KB Output is correct
59 Correct 153 ms 13976 KB Output is correct
60 Correct 144 ms 13976 KB Output is correct
61 Correct 200 ms 13972 KB Output is correct
62 Correct 155 ms 13976 KB Output is correct
63 Correct 156 ms 13976 KB Output is correct
64 Correct 57 ms 13848 KB Output is correct
65 Correct 135 ms 13976 KB Output is correct
66 Correct 143 ms 14080 KB Output is correct
67 Correct 130 ms 13976 KB Output is correct
68 Correct 145 ms 13976 KB Output is correct
69 Correct 127 ms 13976 KB Output is correct
70 Correct 133 ms 14116 KB Output is correct
71 Correct 494 ms 18844 KB Output is correct
72 Correct 544 ms 19124 KB Output is correct
73 Execution timed out 2081 ms 17272 KB Time limit exceeded
74 Halted 0 ms 0 KB -