Submission #755151

# Submission time Handle Problem Language Result Execution time Memory
755151 2023-06-09T12:50:06 Z Stickfish Brperm (RMI20_brperm) C++17
0 / 100
3000 ms 216780 KB
#include "brperm.h"
#include <map>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int rvs_pos(int i, int k) {
    int ans = 0;
    for (int bt = 0; bt < k; ++bt) if (i & (1 << bt)) {
        ans += 1 << (k - bt - 1);
    }
    return ans;
}

int n;
string s;

vector<int> blocks[20];

struct segment {
    int layer;
    int mod;
    int l;

    segment() {}

    segment(int layer_, int mod_, int l_): layer(layer_), mod(mod_), l(l_) {}

    int to_int() {
        return blocks[layer][mod] + l;
    }

    segment operator+(const int& x) const {
        return {layer, mod, l + x};
    }

    segment sub_even() {
        if (l % 2) {
            return {
                layer + 1,
                mod + (1 << layer),
                l / 2
            };
        } else {
            return {
                layer + 1,
                mod,
                l / 2
            };
        }
    }

    segment sub_odd() {
        if (l % 2) {
            return {
                layer + 1,
                mod,
                l / 2 + 1
            };
        } else {
            return {
                layer + 1,
                mod + (1 << layer),
                l / 2
            };
        }
    }
};

void init(int n0, const char s0[]) {
    n = n0;
    s = "";
    for (int bl = 0; (1 << bl) <= n; ++bl) {
        for (int mod = 0; mod < (1 << bl); ++mod) {
            blocks[bl].push_back(s.size());
            for (int i = mod; i < n; i += (1 << bl))
                s.push_back(s0[i]);
        }
    }
}

map<ll, bool> mp;

bool get_ans(segment a, segment b, int k) {
    if (k == 0)
        return s[a.to_int()] == s[b.to_int()];
    ll hsh = 1ll * a.to_int() * n + b.to_int();
    if (mp.find(hsh) != mp.end())
        return mp[hsh];
    bool even = get_ans(a.sub_even(), b, k - 1);
    bool odd = get_ans(a.sub_odd(), b + (1 << (k - 1)), k - 1);
    return mp[hsh] = (even & odd);
}

int query(int l, int k) {
    if (l + (1 << k) > n)
        return 0;
    return get_ans({0, 0, l}, {0, 0, l}, k);
    for (int i = 0; i < (1 << k); ++i) {
        if (s[l + i] != s[l + rvs_pos(i, k)]) {
            return 0;
        }
    }
    return 1;

}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3052 ms 216780 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 980 KB Output isn't correct
2 Halted 0 ms 0 KB -