Submission #957768

# Submission time Handle Problem Language Result Execution time Memory
957768 2024-04-04T09:50:37 Z BhavayGoyal Snake Escaping (JOI18_snake_escaping) C++14
5 / 100
2000 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 arr[N];
map<string, int> mp;

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

    vector<string> nums;
    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));
        nums.pb(s);
        mp[s] = arr[i];
    }

    while (q--) {
        string s; cin >> s;
        if (mp[s]) {cout << mp[s] << endl; continue;}

        int ans = 0;
        for (auto curr : nums) {
            bool f = true;
            for (int j = 0; j < n; j++) {
                if (s[j] == curr[j] || s[j] == '?') continue;
                else {f = false; break;}
            }
            if (f) ans += mp[curr];
        }
        cout << ans << 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 17 ms 624 KB Output is correct
2 Correct 17 ms 600 KB Output is correct
3 Correct 13 ms 676 KB Output is correct
4 Correct 12 ms 604 KB Output is correct
5 Correct 19 ms 604 KB Output is correct
6 Correct 13 ms 600 KB Output is correct
7 Correct 13 ms 604 KB Output is correct
8 Correct 102 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 18 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 624 KB Output is correct
2 Correct 17 ms 600 KB Output is correct
3 Correct 13 ms 676 KB Output is correct
4 Correct 12 ms 604 KB Output is correct
5 Correct 19 ms 604 KB Output is correct
6 Correct 13 ms 600 KB Output is correct
7 Correct 13 ms 604 KB Output is correct
8 Correct 102 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 18 ms 620 KB Output is correct
11 Execution timed out 2054 ms 2948 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 624 KB Output is correct
2 Correct 17 ms 600 KB Output is correct
3 Correct 13 ms 676 KB Output is correct
4 Correct 12 ms 604 KB Output is correct
5 Correct 19 ms 604 KB Output is correct
6 Correct 13 ms 600 KB Output is correct
7 Correct 13 ms 604 KB Output is correct
8 Correct 102 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 18 ms 620 KB Output is correct
11 Execution timed out 2054 ms 2948 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 624 KB Output is correct
2 Correct 17 ms 600 KB Output is correct
3 Correct 13 ms 676 KB Output is correct
4 Correct 12 ms 604 KB Output is correct
5 Correct 19 ms 604 KB Output is correct
6 Correct 13 ms 600 KB Output is correct
7 Correct 13 ms 604 KB Output is correct
8 Correct 102 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 18 ms 620 KB Output is correct
11 Runtime error 166 ms 65536 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 624 KB Output is correct
2 Correct 17 ms 600 KB Output is correct
3 Correct 13 ms 676 KB Output is correct
4 Correct 12 ms 604 KB Output is correct
5 Correct 19 ms 604 KB Output is correct
6 Correct 13 ms 600 KB Output is correct
7 Correct 13 ms 604 KB Output is correct
8 Correct 102 ms 348 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 18 ms 620 KB Output is correct
11 Execution timed out 2054 ms 2948 KB Time limit exceeded
12 Halted 0 ms 0 KB -