Submission #957815

# Submission time Handle Problem Language Result Execution time Memory
957815 2024-04-04T11:10:15 Z BhavayGoyal Snake Escaping (JOI18_snake_escaping) C++14
12 / 100
1002 ms 65536 KB
#include <bits/stdc++.h>
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using oset = 
            tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define ll long long
#define ld long double
#define ar array
#define vi vector<int>
#define vii vector<vector<int>>
#define pii pair<int, int>
#define pb push_back
#define all(x) x.begin(), x.end()
#define f first
#define s second
#define endl "\n"

const int MOD = 1e9+7;
const int inf = 1e9;
const ll linf = 1e18;

const int d4i[4]={-1, 0, 1, 0}, d4j[4]={0, 1, 0, -1};
const int d8i[8]={-1, -1, 0, 1, 1, 1, 0, -1}, d8j[8]={0, 1, 1, 1, 0, -1, -1, -1};

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());


// -------------------------------------------------- Main Code --------------------------------------------------

const int N = (1<<20)+5;
int n, q, arr[N];
unordered_map<string, int> mp;

int sol(string &s) {
    if (mp.find(s) != mp.end()) {
        return mp[s];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (s[i] == '?') {
            s[i] = '0';
            ans = (ans + sol(s));
            s[i] = '1';
            ans = (ans + sol(s));
            s[i] = '?';
            break;
        }
    }
    return mp[s] = ans;
}

void sol() {
    cin >> n >> q;
    for (int i = 0; i < (1<<n); i++) {char x; cin >> x; arr[i] = x-'0';}

    for (int i = 0; i < (1<<n); i++) {
        string s(n,'0');
        for (int j = 0; j < n; j++) {
            if (i&(1<<j)) s[j] = '1';
        }
        reverse(all(s));
        mp[s] = arr[i];
    }

    string s(n, '?');
    sol(s);

    while (q--) {
        string s; cin >> s;
        cout << sol(s) << endl;
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t; 
    while (t--) {
        sol();
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 169 ms 4528 KB Output is correct
12 Correct 177 ms 4588 KB Output is correct
13 Correct 191 ms 4328 KB Output is correct
14 Correct 212 ms 4152 KB Output is correct
15 Correct 200 ms 6064 KB Output is correct
16 Correct 207 ms 5548 KB Output is correct
17 Correct 223 ms 7776 KB Output is correct
18 Correct 154 ms 5460 KB Output is correct
19 Correct 185 ms 2480 KB Output is correct
20 Correct 176 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 169 ms 4528 KB Output is correct
12 Correct 177 ms 4588 KB Output is correct
13 Correct 191 ms 4328 KB Output is correct
14 Correct 212 ms 4152 KB Output is correct
15 Correct 200 ms 6064 KB Output is correct
16 Correct 207 ms 5548 KB Output is correct
17 Correct 223 ms 7776 KB Output is correct
18 Correct 154 ms 5460 KB Output is correct
19 Correct 185 ms 2480 KB Output is correct
20 Correct 176 ms 4432 KB Output is correct
21 Correct 204 ms 7428 KB Output is correct
22 Correct 220 ms 9132 KB Output is correct
23 Correct 578 ms 27344 KB Output is correct
24 Correct 465 ms 23320 KB Output is correct
25 Correct 605 ms 36932 KB Output is correct
26 Correct 1002 ms 52284 KB Output is correct
27 Runtime error 880 ms 65536 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Runtime error 304 ms 65536 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 2 ms 860 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 3 ms 972 KB Output is correct
7 Correct 3 ms 860 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 860 KB Output is correct
11 Correct 169 ms 4528 KB Output is correct
12 Correct 177 ms 4588 KB Output is correct
13 Correct 191 ms 4328 KB Output is correct
14 Correct 212 ms 4152 KB Output is correct
15 Correct 200 ms 6064 KB Output is correct
16 Correct 207 ms 5548 KB Output is correct
17 Correct 223 ms 7776 KB Output is correct
18 Correct 154 ms 5460 KB Output is correct
19 Correct 185 ms 2480 KB Output is correct
20 Correct 176 ms 4432 KB Output is correct
21 Correct 204 ms 7428 KB Output is correct
22 Correct 220 ms 9132 KB Output is correct
23 Correct 578 ms 27344 KB Output is correct
24 Correct 465 ms 23320 KB Output is correct
25 Correct 605 ms 36932 KB Output is correct
26 Correct 1002 ms 52284 KB Output is correct
27 Runtime error 880 ms 65536 KB Execution killed with signal 9
28 Halted 0 ms 0 KB -