Submission #896353

# Submission time Handle Problem Language Result Execution time Memory
896353 2024-01-01T09:57:40 Z Unforgettablepl Snake Escaping (JOI18_snake_escaping) C++17
75 / 100
2000 ms 37968 KB
#pragma GCC optimize "Ofast"
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
/*
ID: samikgo1
TASK:
LANG: C++
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef complex<ll> point;
#define X real()
#define Y imag()
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
//#define f first
//#define s second
//#define x first
//#define y second
const ll INF = 1e17;
const ll sqrtn = 440;
const ll modulo = 1e9+7;
const ll siz = 262144;
const ll hashp = 923981238;
const ll hashm = 932439994;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

//#define int ll

int memo[1594323];
char str[1048577];
char queries[1000001][21];
int ansq[1000001];

int get(char *s,int i){
    if(memo[i]!=-1)return memo[i];
    int p = 1;
    for(int x=0;x<13;x++) {
        if (s[x] == '?') {
            s[x] = '0';
            int ans = get(s, i + p);
            s[x] = '1';
            ans += get(s, i + 2 * p);
            s[x] = '?';
            return memo[i] = ans;
        }
        p*=3;
    }
}

int getidx(const char *s){
    int p = 1;
    int ans = 0;
    for(int a=0;a<13;a++){
        if(s[a]=='0')ans+=p;
        else if(s[a]=='1')ans+=p*2;
        p*=3;
    }
    return ans;
}

bool match(string a,const char *b){
    for(int i=0;i<7;i++)if(b[i]!='?' and a[i]!=b[i])return false;
    return true;
}

void solve() {
    int l,q;
    cin >> l >> q;
    for(int i=0;i<(1<<l);i++)cin >> str[i];
    for(int i=0;i<(1<<l);i++)str[i]-='0';
    for(int i=1;i<=q;i++){
        string s;cin>>s;
        for(int x=0;x<20-l;x++)s.insert(s.begin(),'0');
        for(int x=0;x<20;x++)queries[i][x] = s[x];
    }
    for(int modifier=0;modifier<(1<<7);modifier++){
        if((modifier<<13)>=(1<<l))break;
        string m = bitset<7>(modifier).to_string();
        for(int&i:memo)i=-1;
        for(int i=0;i<(1<<13);i++)memo[getidx(bitset<13>(i).to_string().c_str())]=str[(modifier<<13)+i];
        for(int i=1;i<=q;i++){
            if(!match(m,queries[i]))continue;
            ansq[i]+=get(queries[i]+7,getidx(queries[i]+7));
        }
    }
    for(int i=1;i<=q;i++)cout<<ansq[i]<<'\n';
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
//    freopen("cses.fi.txt","r",stdin);
//    freopen(".out","w",stdout);
//    int t;
//    cin >> t;
//    while(t--)
    solve();
}

Compilation message

snake_escaping.cpp: In function 'int get(char*, int)':
snake_escaping.cpp:55:1: warning: control reaches end of non-void function [-Wreturn-type]
   55 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11356 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 3 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 5 ms 11356 KB Output is correct
6 Correct 3 ms 11488 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11356 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 3 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 5 ms 11356 KB Output is correct
6 Correct 3 ms 11488 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
11 Correct 221 ms 36068 KB Output is correct
12 Correct 276 ms 36188 KB Output is correct
13 Correct 254 ms 35040 KB Output is correct
14 Correct 256 ms 35184 KB Output is correct
15 Correct 237 ms 36176 KB Output is correct
16 Correct 251 ms 35300 KB Output is correct
17 Correct 262 ms 35240 KB Output is correct
18 Correct 235 ms 37216 KB Output is correct
19 Correct 251 ms 34128 KB Output is correct
20 Correct 228 ms 35804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11356 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 3 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 5 ms 11356 KB Output is correct
6 Correct 3 ms 11488 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
11 Correct 221 ms 36068 KB Output is correct
12 Correct 276 ms 36188 KB Output is correct
13 Correct 254 ms 35040 KB Output is correct
14 Correct 256 ms 35184 KB Output is correct
15 Correct 237 ms 36176 KB Output is correct
16 Correct 251 ms 35300 KB Output is correct
17 Correct 262 ms 35240 KB Output is correct
18 Correct 235 ms 37216 KB Output is correct
19 Correct 251 ms 34128 KB Output is correct
20 Correct 228 ms 35804 KB Output is correct
21 Correct 205 ms 36304 KB Output is correct
22 Correct 267 ms 36220 KB Output is correct
23 Correct 274 ms 35292 KB Output is correct
24 Correct 285 ms 34948 KB Output is correct
25 Correct 235 ms 37100 KB Output is correct
26 Correct 282 ms 35608 KB Output is correct
27 Correct 268 ms 35412 KB Output is correct
28 Correct 206 ms 37968 KB Output is correct
29 Correct 246 ms 34004 KB Output is correct
30 Correct 213 ms 36176 KB Output is correct
31 Correct 255 ms 36176 KB Output is correct
32 Correct 280 ms 36048 KB Output is correct
33 Correct 245 ms 35048 KB Output is correct
34 Correct 266 ms 35152 KB Output is correct
35 Correct 284 ms 35432 KB Output is correct
36 Correct 209 ms 34128 KB Output is correct
37 Correct 265 ms 36052 KB Output is correct
38 Correct 257 ms 34000 KB Output is correct
39 Correct 246 ms 35236 KB Output is correct
40 Correct 247 ms 35040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11356 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 3 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 5 ms 11356 KB Output is correct
6 Correct 3 ms 11488 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
11 Correct 286 ms 16008 KB Output is correct
12 Correct 382 ms 16004 KB Output is correct
13 Correct 294 ms 15752 KB Output is correct
14 Correct 351 ms 15952 KB Output is correct
15 Correct 783 ms 16004 KB Output is correct
16 Correct 385 ms 15752 KB Output is correct
17 Correct 416 ms 15756 KB Output is correct
18 Correct 213 ms 16028 KB Output is correct
19 Correct 201 ms 15808 KB Output is correct
20 Correct 368 ms 16016 KB Output is correct
21 Correct 641 ms 16004 KB Output is correct
22 Correct 328 ms 15768 KB Output is correct
23 Correct 204 ms 15748 KB Output is correct
24 Correct 307 ms 15756 KB Output is correct
25 Correct 414 ms 15752 KB Output is correct
26 Correct 172 ms 15600 KB Output is correct
27 Correct 305 ms 16008 KB Output is correct
28 Correct 214 ms 15748 KB Output is correct
29 Correct 235 ms 15704 KB Output is correct
30 Correct 275 ms 15752 KB Output is correct
31 Correct 191 ms 15704 KB Output is correct
32 Correct 399 ms 15956 KB Output is correct
33 Correct 383 ms 15956 KB Output is correct
34 Correct 136 ms 15752 KB Output is correct
35 Correct 411 ms 15952 KB Output is correct
36 Correct 407 ms 15952 KB Output is correct
37 Correct 409 ms 15748 KB Output is correct
38 Correct 409 ms 15752 KB Output is correct
39 Correct 402 ms 15744 KB Output is correct
40 Correct 405 ms 15968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 11356 KB Output is correct
2 Correct 3 ms 11356 KB Output is correct
3 Correct 3 ms 11356 KB Output is correct
4 Correct 3 ms 11356 KB Output is correct
5 Correct 5 ms 11356 KB Output is correct
6 Correct 3 ms 11488 KB Output is correct
7 Correct 3 ms 11356 KB Output is correct
8 Correct 3 ms 11356 KB Output is correct
9 Correct 2 ms 11356 KB Output is correct
10 Correct 2 ms 11356 KB Output is correct
11 Correct 221 ms 36068 KB Output is correct
12 Correct 276 ms 36188 KB Output is correct
13 Correct 254 ms 35040 KB Output is correct
14 Correct 256 ms 35184 KB Output is correct
15 Correct 237 ms 36176 KB Output is correct
16 Correct 251 ms 35300 KB Output is correct
17 Correct 262 ms 35240 KB Output is correct
18 Correct 235 ms 37216 KB Output is correct
19 Correct 251 ms 34128 KB Output is correct
20 Correct 228 ms 35804 KB Output is correct
21 Correct 205 ms 36304 KB Output is correct
22 Correct 267 ms 36220 KB Output is correct
23 Correct 274 ms 35292 KB Output is correct
24 Correct 285 ms 34948 KB Output is correct
25 Correct 235 ms 37100 KB Output is correct
26 Correct 282 ms 35608 KB Output is correct
27 Correct 268 ms 35412 KB Output is correct
28 Correct 206 ms 37968 KB Output is correct
29 Correct 246 ms 34004 KB Output is correct
30 Correct 213 ms 36176 KB Output is correct
31 Correct 255 ms 36176 KB Output is correct
32 Correct 280 ms 36048 KB Output is correct
33 Correct 245 ms 35048 KB Output is correct
34 Correct 266 ms 35152 KB Output is correct
35 Correct 284 ms 35432 KB Output is correct
36 Correct 209 ms 34128 KB Output is correct
37 Correct 265 ms 36052 KB Output is correct
38 Correct 257 ms 34000 KB Output is correct
39 Correct 246 ms 35236 KB Output is correct
40 Correct 247 ms 35040 KB Output is correct
41 Correct 286 ms 16008 KB Output is correct
42 Correct 382 ms 16004 KB Output is correct
43 Correct 294 ms 15752 KB Output is correct
44 Correct 351 ms 15952 KB Output is correct
45 Correct 783 ms 16004 KB Output is correct
46 Correct 385 ms 15752 KB Output is correct
47 Correct 416 ms 15756 KB Output is correct
48 Correct 213 ms 16028 KB Output is correct
49 Correct 201 ms 15808 KB Output is correct
50 Correct 368 ms 16016 KB Output is correct
51 Correct 641 ms 16004 KB Output is correct
52 Correct 328 ms 15768 KB Output is correct
53 Correct 204 ms 15748 KB Output is correct
54 Correct 307 ms 15756 KB Output is correct
55 Correct 414 ms 15752 KB Output is correct
56 Correct 172 ms 15600 KB Output is correct
57 Correct 305 ms 16008 KB Output is correct
58 Correct 214 ms 15748 KB Output is correct
59 Correct 235 ms 15704 KB Output is correct
60 Correct 275 ms 15752 KB Output is correct
61 Correct 191 ms 15704 KB Output is correct
62 Correct 399 ms 15956 KB Output is correct
63 Correct 383 ms 15956 KB Output is correct
64 Correct 136 ms 15752 KB Output is correct
65 Correct 411 ms 15952 KB Output is correct
66 Correct 407 ms 15952 KB Output is correct
67 Correct 409 ms 15748 KB Output is correct
68 Correct 409 ms 15752 KB Output is correct
69 Correct 402 ms 15744 KB Output is correct
70 Correct 405 ms 15968 KB Output is correct
71 Execution timed out 2029 ms 32080 KB Time limit exceeded
72 Halted 0 ms 0 KB -