답안 #1095733

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095733 2024-10-03T04:03:21 Z doducanh Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
2000 ms 36432 KB
///breaker
///every second counts
#pragma GCC optimize("O2")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define ii pair<int,int>
#define mp make_pair
#define in(x) freopen(x,"r",stdin)
#define out(x) freopen(x,"w",stdout)
#define bit(x,i) ((x>>i)&1)
#define lc (id<<1)
#define rc ((id<<1)^1)
int l,q;
string s;
ll f0[(1<<20)];
ll f1[(1<<20)];
void sol(void){
    cin>>l>>q;
    cin>>s;
    for(int i=0;i<s.size();i++){
        f0[i]+=s[i]-'0';
        f1[i]+=s[i]-'0';
    }
    for(int i=0;i<20;i++){
        for(int j=0;j<(1<<20);j++)if(bit(j,i)){
            f0[j]+=f0[(j^(1<<i))];
            f1[(j^(1<<i))]+=f1[j];
        }
    }
    while(q--){
        string tmp;
        cin>>tmp;
        reverse(tmp.begin(),tmp.end());
        int a=0,b=0,c=0;
        for(int i=0;i<l;i++){
            if(tmp[i]=='0'){
                a|=(1<<i);
            }
            else if(tmp[i]=='1'){
                b|=(1<<i);
            }
            else c|=(1<<i);
        }
        ll res=0;
        if(__builtin_popcount(c)<=l/3){
            for(int i=c;i>=0;i--){
                i&=c;
                res+=(s[i|b]-'0');
            }
        }
        else if(__builtin_popcount(c)<=l/3){
            for(int i=a;i>=0;i--){
                i&=a;
                if(__builtin_popcount(i)&1){
                    res-=f1[i|b];
                }
                else res+=f1[i|b];
            }
        }
        else{
            for(int i=b;i>=0;i--){
                i&=b;
                if((__builtin_popcount(b)-__builtin_popcount(i))&1)res-=f0[i|c];
                else res+=f0[i|c];
            }
        }
        cout<<res<<"\n";
    }
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
    while(t--){
        sol();
    }
    // you should actually read the stuff at the bottom
    return 0;
}
/* stuff you should look for
 * int overflow, array bounds
 * special cases (n=1?)
 * do smth instead of nothing and stay organized
 * WRITE STUFF DOWN
 * DON'T GET STUCK ON ONE APPROACH
 */

Compilation message

snake_escaping.cpp: In function 'void sol()':
snake_escaping.cpp:23:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |     for(int i=0;i<s.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16728 KB Output is correct
2 Correct 28 ms 16884 KB Output is correct
3 Correct 27 ms 16732 KB Output is correct
4 Correct 26 ms 16852 KB Output is correct
5 Correct 26 ms 16728 KB Output is correct
6 Correct 39 ms 16852 KB Output is correct
7 Correct 27 ms 16732 KB Output is correct
8 Correct 31 ms 16728 KB Output is correct
9 Correct 29 ms 16728 KB Output is correct
10 Correct 27 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16728 KB Output is correct
2 Correct 28 ms 16884 KB Output is correct
3 Correct 27 ms 16732 KB Output is correct
4 Correct 26 ms 16852 KB Output is correct
5 Correct 26 ms 16728 KB Output is correct
6 Correct 39 ms 16852 KB Output is correct
7 Correct 27 ms 16732 KB Output is correct
8 Correct 31 ms 16728 KB Output is correct
9 Correct 29 ms 16728 KB Output is correct
10 Correct 27 ms 16732 KB Output is correct
11 Correct 261 ms 31584 KB Output is correct
12 Correct 185 ms 31280 KB Output is correct
13 Correct 191 ms 30444 KB Output is correct
14 Correct 191 ms 30548 KB Output is correct
15 Correct 193 ms 31468 KB Output is correct
16 Correct 215 ms 30560 KB Output is correct
17 Correct 218 ms 30692 KB Output is correct
18 Correct 136 ms 32592 KB Output is correct
19 Correct 158 ms 29524 KB Output is correct
20 Correct 248 ms 31056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16728 KB Output is correct
2 Correct 28 ms 16884 KB Output is correct
3 Correct 27 ms 16732 KB Output is correct
4 Correct 26 ms 16852 KB Output is correct
5 Correct 26 ms 16728 KB Output is correct
6 Correct 39 ms 16852 KB Output is correct
7 Correct 27 ms 16732 KB Output is correct
8 Correct 31 ms 16728 KB Output is correct
9 Correct 29 ms 16728 KB Output is correct
10 Correct 27 ms 16732 KB Output is correct
11 Correct 261 ms 31584 KB Output is correct
12 Correct 185 ms 31280 KB Output is correct
13 Correct 191 ms 30444 KB Output is correct
14 Correct 191 ms 30548 KB Output is correct
15 Correct 193 ms 31468 KB Output is correct
16 Correct 215 ms 30560 KB Output is correct
17 Correct 218 ms 30692 KB Output is correct
18 Correct 136 ms 32592 KB Output is correct
19 Correct 158 ms 29524 KB Output is correct
20 Correct 248 ms 31056 KB Output is correct
21 Correct 401 ms 34388 KB Output is correct
22 Correct 202 ms 34604 KB Output is correct
23 Correct 227 ms 33616 KB Output is correct
24 Correct 228 ms 33364 KB Output is correct
25 Correct 233 ms 35400 KB Output is correct
26 Correct 262 ms 33872 KB Output is correct
27 Correct 255 ms 33876 KB Output is correct
28 Correct 137 ms 36432 KB Output is correct
29 Correct 191 ms 32548 KB Output is correct
30 Correct 475 ms 34708 KB Output is correct
31 Correct 278 ms 34480 KB Output is correct
32 Correct 298 ms 34456 KB Output is correct
33 Correct 238 ms 33364 KB Output is correct
34 Correct 223 ms 33364 KB Output is correct
35 Correct 242 ms 33876 KB Output is correct
36 Correct 174 ms 32340 KB Output is correct
37 Correct 172 ms 34384 KB Output is correct
38 Correct 194 ms 32504 KB Output is correct
39 Correct 246 ms 33624 KB Output is correct
40 Correct 216 ms 33360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16728 KB Output is correct
2 Correct 28 ms 16884 KB Output is correct
3 Correct 27 ms 16732 KB Output is correct
4 Correct 26 ms 16852 KB Output is correct
5 Correct 26 ms 16728 KB Output is correct
6 Correct 39 ms 16852 KB Output is correct
7 Correct 27 ms 16732 KB Output is correct
8 Correct 31 ms 16728 KB Output is correct
9 Correct 29 ms 16728 KB Output is correct
10 Correct 27 ms 16732 KB Output is correct
11 Correct 233 ms 20208 KB Output is correct
12 Correct 40 ms 20212 KB Output is correct
13 Correct 43 ms 20008 KB Output is correct
14 Correct 57 ms 20232 KB Output is correct
15 Correct 42 ms 20276 KB Output is correct
16 Correct 57 ms 20212 KB Output is correct
17 Correct 57 ms 20220 KB Output is correct
18 Correct 38 ms 20576 KB Output is correct
19 Correct 38 ms 20108 KB Output is correct
20 Correct 353 ms 20208 KB Output is correct
21 Correct 58 ms 20208 KB Output is correct
22 Correct 73 ms 20204 KB Output is correct
23 Correct 53 ms 20212 KB Output is correct
24 Correct 46 ms 20212 KB Output is correct
25 Correct 59 ms 20160 KB Output is correct
26 Correct 36 ms 19956 KB Output is correct
27 Correct 38 ms 20216 KB Output is correct
28 Correct 44 ms 20148 KB Output is correct
29 Correct 82 ms 20004 KB Output is correct
30 Correct 47 ms 20208 KB Output is correct
31 Correct 42 ms 19984 KB Output is correct
32 Correct 54 ms 20216 KB Output is correct
33 Correct 62 ms 20208 KB Output is correct
34 Correct 35 ms 19952 KB Output is correct
35 Correct 76 ms 20056 KB Output is correct
36 Correct 77 ms 20092 KB Output is correct
37 Correct 73 ms 20064 KB Output is correct
38 Correct 74 ms 20208 KB Output is correct
39 Correct 76 ms 20208 KB Output is correct
40 Correct 100 ms 20224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 16728 KB Output is correct
2 Correct 28 ms 16884 KB Output is correct
3 Correct 27 ms 16732 KB Output is correct
4 Correct 26 ms 16852 KB Output is correct
5 Correct 26 ms 16728 KB Output is correct
6 Correct 39 ms 16852 KB Output is correct
7 Correct 27 ms 16732 KB Output is correct
8 Correct 31 ms 16728 KB Output is correct
9 Correct 29 ms 16728 KB Output is correct
10 Correct 27 ms 16732 KB Output is correct
11 Correct 261 ms 31584 KB Output is correct
12 Correct 185 ms 31280 KB Output is correct
13 Correct 191 ms 30444 KB Output is correct
14 Correct 191 ms 30548 KB Output is correct
15 Correct 193 ms 31468 KB Output is correct
16 Correct 215 ms 30560 KB Output is correct
17 Correct 218 ms 30692 KB Output is correct
18 Correct 136 ms 32592 KB Output is correct
19 Correct 158 ms 29524 KB Output is correct
20 Correct 248 ms 31056 KB Output is correct
21 Correct 401 ms 34388 KB Output is correct
22 Correct 202 ms 34604 KB Output is correct
23 Correct 227 ms 33616 KB Output is correct
24 Correct 228 ms 33364 KB Output is correct
25 Correct 233 ms 35400 KB Output is correct
26 Correct 262 ms 33872 KB Output is correct
27 Correct 255 ms 33876 KB Output is correct
28 Correct 137 ms 36432 KB Output is correct
29 Correct 191 ms 32548 KB Output is correct
30 Correct 475 ms 34708 KB Output is correct
31 Correct 278 ms 34480 KB Output is correct
32 Correct 298 ms 34456 KB Output is correct
33 Correct 238 ms 33364 KB Output is correct
34 Correct 223 ms 33364 KB Output is correct
35 Correct 242 ms 33876 KB Output is correct
36 Correct 174 ms 32340 KB Output is correct
37 Correct 172 ms 34384 KB Output is correct
38 Correct 194 ms 32504 KB Output is correct
39 Correct 246 ms 33624 KB Output is correct
40 Correct 216 ms 33360 KB Output is correct
41 Correct 233 ms 20208 KB Output is correct
42 Correct 40 ms 20212 KB Output is correct
43 Correct 43 ms 20008 KB Output is correct
44 Correct 57 ms 20232 KB Output is correct
45 Correct 42 ms 20276 KB Output is correct
46 Correct 57 ms 20212 KB Output is correct
47 Correct 57 ms 20220 KB Output is correct
48 Correct 38 ms 20576 KB Output is correct
49 Correct 38 ms 20108 KB Output is correct
50 Correct 353 ms 20208 KB Output is correct
51 Correct 58 ms 20208 KB Output is correct
52 Correct 73 ms 20204 KB Output is correct
53 Correct 53 ms 20212 KB Output is correct
54 Correct 46 ms 20212 KB Output is correct
55 Correct 59 ms 20160 KB Output is correct
56 Correct 36 ms 19956 KB Output is correct
57 Correct 38 ms 20216 KB Output is correct
58 Correct 44 ms 20148 KB Output is correct
59 Correct 82 ms 20004 KB Output is correct
60 Correct 47 ms 20208 KB Output is correct
61 Correct 42 ms 19984 KB Output is correct
62 Correct 54 ms 20216 KB Output is correct
63 Correct 62 ms 20208 KB Output is correct
64 Correct 35 ms 19952 KB Output is correct
65 Correct 76 ms 20056 KB Output is correct
66 Correct 77 ms 20092 KB Output is correct
67 Correct 73 ms 20064 KB Output is correct
68 Correct 74 ms 20208 KB Output is correct
69 Correct 76 ms 20208 KB Output is correct
70 Correct 100 ms 20224 KB Output is correct
71 Execution timed out 2060 ms 31096 KB Time limit exceeded
72 Halted 0 ms 0 KB -