답안 #853174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
853174 2023-09-23T15:28:45 Z Ahmed57 Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
1717 ms 27144 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n,m;
    cin>>n>>m;
    int arr[(1<<n)];
    int sup[(1<<n)] = {0},super[(1<<n)] = {0};
    string s;cin>>s;
    for(int i = 0;i<(1<<n);i++){
        sup[i] = super[i] = arr[i] = (s[i]-'0');
    }
    for(int i = 0;i<n;i++){
        for(int mask = 0;mask<(1<<n);mask++){
            if(mask&(1<<i)){
                super[mask^(1<<i)]+=super[mask];
                sup[mask]+=sup[mask^(1<<i)];
            }
        }
    }
    while(m--){
        string s;cin>>s;
        int zero = 0 , one = 0 , qu = 0;
        for(int i = 0;i<n;i++){
            if(s[i]=='0')zero+=(1<<(n-i-1));
            else if(s[i]=='1')one+=(1<<(n-i-1));
            else qu+=(1<<(n-i-1));
        }
        long long all = 0;
        if(__builtin_popcount(qu)<=0){
            for(int mask = qu;;mask=(qu&(mask-1))){
                all+=arr[mask|one];
                //cout<<mask<<endl;
                if(mask==0)break;
            }
        }else if(__builtin_popcount(zero)<=6){
            for(int mask = zero;;mask=(zero&(mask-1))){
                if(__builtin_popcount(mask)&1)all-=super[mask|one];
                else all+=super[mask|one];
                if(mask==0)break;
            }
        }else if(__builtin_popcount(one)<=6){
            for(int mask = one;;mask=(one&(mask-1))){
                if(__builtin_popcount(mask)&1)all-=sup[mask^one^qu];
                else all+=sup[mask^one^qu];
                if(mask==0)break;
            }
        }
        cout<<all<<endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1532 ms 4492 KB Output is correct
12 Correct 1544 ms 4176 KB Output is correct
13 Correct 1567 ms 3288 KB Output is correct
14 Correct 1514 ms 3304 KB Output is correct
15 Correct 1480 ms 4544 KB Output is correct
16 Correct 1527 ms 3436 KB Output is correct
17 Correct 1552 ms 4016 KB Output is correct
18 Correct 1454 ms 5424 KB Output is correct
19 Correct 1443 ms 2384 KB Output is correct
20 Correct 1509 ms 4288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1532 ms 4492 KB Output is correct
12 Correct 1544 ms 4176 KB Output is correct
13 Correct 1567 ms 3288 KB Output is correct
14 Correct 1514 ms 3304 KB Output is correct
15 Correct 1480 ms 4544 KB Output is correct
16 Correct 1527 ms 3436 KB Output is correct
17 Correct 1552 ms 4016 KB Output is correct
18 Correct 1454 ms 5424 KB Output is correct
19 Correct 1443 ms 2384 KB Output is correct
20 Correct 1509 ms 4288 KB Output is correct
21 Correct 1652 ms 4460 KB Output is correct
22 Correct 1561 ms 5000 KB Output is correct
23 Correct 1717 ms 3708 KB Output is correct
24 Correct 1639 ms 3792 KB Output is correct
25 Correct 1586 ms 5596 KB Output is correct
26 Correct 1630 ms 4424 KB Output is correct
27 Correct 1627 ms 3856 KB Output is correct
28 Correct 1523 ms 6480 KB Output is correct
29 Correct 1540 ms 2616 KB Output is correct
30 Correct 1536 ms 4972 KB Output is correct
31 Correct 1665 ms 4792 KB Output is correct
32 Correct 1582 ms 4504 KB Output is correct
33 Correct 1573 ms 3476 KB Output is correct
34 Correct 1642 ms 3564 KB Output is correct
35 Correct 1633 ms 3920 KB Output is correct
36 Correct 1498 ms 2636 KB Output is correct
37 Correct 1503 ms 4832 KB Output is correct
38 Correct 1519 ms 2484 KB Output is correct
39 Correct 1575 ms 3600 KB Output is correct
40 Correct 1594 ms 3492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 148 ms 26888 KB Output is correct
12 Correct 136 ms 27144 KB Output is correct
13 Incorrect 139 ms 26892 KB Output isn't correct
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 544 KB Output is correct
3 Correct 2 ms 344 KB Output is correct
4 Correct 3 ms 344 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 348 KB Output is correct
7 Correct 2 ms 344 KB Output is correct
8 Correct 2 ms 344 KB Output is correct
9 Correct 2 ms 344 KB Output is correct
10 Correct 2 ms 344 KB Output is correct
11 Correct 1532 ms 4492 KB Output is correct
12 Correct 1544 ms 4176 KB Output is correct
13 Correct 1567 ms 3288 KB Output is correct
14 Correct 1514 ms 3304 KB Output is correct
15 Correct 1480 ms 4544 KB Output is correct
16 Correct 1527 ms 3436 KB Output is correct
17 Correct 1552 ms 4016 KB Output is correct
18 Correct 1454 ms 5424 KB Output is correct
19 Correct 1443 ms 2384 KB Output is correct
20 Correct 1509 ms 4288 KB Output is correct
21 Correct 1652 ms 4460 KB Output is correct
22 Correct 1561 ms 5000 KB Output is correct
23 Correct 1717 ms 3708 KB Output is correct
24 Correct 1639 ms 3792 KB Output is correct
25 Correct 1586 ms 5596 KB Output is correct
26 Correct 1630 ms 4424 KB Output is correct
27 Correct 1627 ms 3856 KB Output is correct
28 Correct 1523 ms 6480 KB Output is correct
29 Correct 1540 ms 2616 KB Output is correct
30 Correct 1536 ms 4972 KB Output is correct
31 Correct 1665 ms 4792 KB Output is correct
32 Correct 1582 ms 4504 KB Output is correct
33 Correct 1573 ms 3476 KB Output is correct
34 Correct 1642 ms 3564 KB Output is correct
35 Correct 1633 ms 3920 KB Output is correct
36 Correct 1498 ms 2636 KB Output is correct
37 Correct 1503 ms 4832 KB Output is correct
38 Correct 1519 ms 2484 KB Output is correct
39 Correct 1575 ms 3600 KB Output is correct
40 Correct 1594 ms 3492 KB Output is correct
41 Correct 148 ms 26888 KB Output is correct
42 Correct 136 ms 27144 KB Output is correct
43 Incorrect 139 ms 26892 KB Output isn't correct
44 Halted 0 ms 0 KB -