답안 #895694

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
895694 2023-12-30T14:40:57 Z Unforgettablepl Snake Escaping (JOI18_snake_escaping) C++17
22 / 100
251 ms 28844 KB
//#pragma GCC optimize("O3,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[1048576];
char queries[1000000][20];
int ans[1000000];

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

int getidx(string s){
    int p = 1;
    int ans = 0;
    for(char&a:s){
        if(a=='0')ans+=p;
        else if(a=='1')ans+=p*2;
        p*=3;
    }
    return ans;
}

void solve() {
    for(int&i:memo)i=-1;
    int l,q;
    cin >> l >> q;
    for(int i=0;i<(1<<l);i++){
        char a;cin>>a;
        a-='0';
        memo[getidx(bitset<13>(i).to_string())] = a;
    }
    for(int i=1;i<=q;i++){
        string s;cin>>s;
        for(int x=0;x<13-l;x++)s.insert(s.begin(),'0');
        cout << get(s,getidx(s)) << '\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 'll get(std::string&, ll)':
snake_escaping.cpp:54:1: warning: control reaches end of non-void function [-Wreturn-type]
   54 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14424 KB Output is correct
2 Correct 3 ms 14424 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 3 ms 14428 KB Output is correct
5 Correct 4 ms 14520 KB Output is correct
6 Correct 3 ms 14428 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 3 ms 14424 KB Output is correct
10 Correct 3 ms 14428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14424 KB Output is correct
2 Correct 3 ms 14424 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 3 ms 14428 KB Output is correct
5 Correct 4 ms 14520 KB Output is correct
6 Correct 3 ms 14428 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 3 ms 14424 KB Output is correct
10 Correct 3 ms 14428 KB Output is correct
11 Correct 156 ms 18516 KB Output is correct
12 Correct 194 ms 17988 KB Output is correct
13 Correct 195 ms 17220 KB Output is correct
14 Correct 186 ms 17448 KB Output is correct
15 Correct 177 ms 18300 KB Output is correct
16 Correct 199 ms 17492 KB Output is correct
17 Correct 186 ms 17592 KB Output is correct
18 Correct 156 ms 19284 KB Output is correct
19 Correct 180 ms 16492 KB Output is correct
20 Correct 156 ms 18000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14424 KB Output is correct
2 Correct 3 ms 14424 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 3 ms 14428 KB Output is correct
5 Correct 4 ms 14520 KB Output is correct
6 Correct 3 ms 14428 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 3 ms 14424 KB Output is correct
10 Correct 3 ms 14428 KB Output is correct
11 Correct 156 ms 18516 KB Output is correct
12 Correct 194 ms 17988 KB Output is correct
13 Correct 195 ms 17220 KB Output is correct
14 Correct 186 ms 17448 KB Output is correct
15 Correct 177 ms 18300 KB Output is correct
16 Correct 199 ms 17492 KB Output is correct
17 Correct 186 ms 17592 KB Output is correct
18 Correct 156 ms 19284 KB Output is correct
19 Correct 180 ms 16492 KB Output is correct
20 Correct 156 ms 18000 KB Output is correct
21 Correct 135 ms 18504 KB Output is correct
22 Correct 197 ms 18712 KB Output is correct
23 Correct 187 ms 17496 KB Output is correct
24 Correct 186 ms 17492 KB Output is correct
25 Correct 166 ms 19284 KB Output is correct
26 Correct 212 ms 18000 KB Output is correct
27 Correct 235 ms 17744 KB Output is correct
28 Correct 146 ms 20452 KB Output is correct
29 Correct 184 ms 16496 KB Output is correct
30 Correct 138 ms 18608 KB Output is correct
31 Correct 215 ms 18608 KB Output is correct
32 Correct 196 ms 18480 KB Output is correct
33 Correct 186 ms 17212 KB Output is correct
34 Correct 234 ms 17488 KB Output is correct
35 Correct 251 ms 17788 KB Output is correct
36 Correct 142 ms 16272 KB Output is correct
37 Correct 182 ms 18516 KB Output is correct
38 Correct 186 ms 16356 KB Output is correct
39 Correct 196 ms 17592 KB Output is correct
40 Correct 182 ms 17376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14424 KB Output is correct
2 Correct 3 ms 14424 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 3 ms 14428 KB Output is correct
5 Correct 4 ms 14520 KB Output is correct
6 Correct 3 ms 14428 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 3 ms 14424 KB Output is correct
10 Correct 3 ms 14428 KB Output is correct
11 Runtime error 102 ms 28844 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 14424 KB Output is correct
2 Correct 3 ms 14424 KB Output is correct
3 Correct 3 ms 14428 KB Output is correct
4 Correct 3 ms 14428 KB Output is correct
5 Correct 4 ms 14520 KB Output is correct
6 Correct 3 ms 14428 KB Output is correct
7 Correct 3 ms 14428 KB Output is correct
8 Correct 3 ms 14428 KB Output is correct
9 Correct 3 ms 14424 KB Output is correct
10 Correct 3 ms 14428 KB Output is correct
11 Correct 156 ms 18516 KB Output is correct
12 Correct 194 ms 17988 KB Output is correct
13 Correct 195 ms 17220 KB Output is correct
14 Correct 186 ms 17448 KB Output is correct
15 Correct 177 ms 18300 KB Output is correct
16 Correct 199 ms 17492 KB Output is correct
17 Correct 186 ms 17592 KB Output is correct
18 Correct 156 ms 19284 KB Output is correct
19 Correct 180 ms 16492 KB Output is correct
20 Correct 156 ms 18000 KB Output is correct
21 Correct 135 ms 18504 KB Output is correct
22 Correct 197 ms 18712 KB Output is correct
23 Correct 187 ms 17496 KB Output is correct
24 Correct 186 ms 17492 KB Output is correct
25 Correct 166 ms 19284 KB Output is correct
26 Correct 212 ms 18000 KB Output is correct
27 Correct 235 ms 17744 KB Output is correct
28 Correct 146 ms 20452 KB Output is correct
29 Correct 184 ms 16496 KB Output is correct
30 Correct 138 ms 18608 KB Output is correct
31 Correct 215 ms 18608 KB Output is correct
32 Correct 196 ms 18480 KB Output is correct
33 Correct 186 ms 17212 KB Output is correct
34 Correct 234 ms 17488 KB Output is correct
35 Correct 251 ms 17788 KB Output is correct
36 Correct 142 ms 16272 KB Output is correct
37 Correct 182 ms 18516 KB Output is correct
38 Correct 186 ms 16356 KB Output is correct
39 Correct 196 ms 17592 KB Output is correct
40 Correct 182 ms 17376 KB Output is correct
41 Runtime error 102 ms 28844 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -