Submission #755157

# Submission time Handle Problem Language Result Execution time Memory
755157 2023-06-09T12:59:39 Z Stickfish Brperm (RMI20_brperm) C++17
13 / 100
2779 ms 262144 KB
#include "brperm.h"
#include <map>
#include <cassert>
#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[23];

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[23];

bool get_ans(segment a, segment b, int k) {
    assert(a.to_int() < s.size());
    assert(b.to_int() < s.size());
    if (k == 0)
        return s[a.to_int()] == s[b.to_int()];
    ll hsh = 1ll * a.to_int() * n + b.to_int();
    if (mp[k].find(hsh) != mp[k].end())
        return mp[k][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[k][hsh] = (even & odd);
}

int query(int l, int k) {
    if (k > 20 || 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;

}

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from brperm.cpp:3:
brperm.cpp: In function 'bool get_ans(segment, segment, int)':
brperm.cpp:87:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     assert(a.to_int() < s.size());
      |            ~~~~~~~~~~~^~~~~~~~~~
brperm.cpp:88:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |     assert(b.to_int() < s.size());
      |            ~~~~~~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 6 ms 1580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 6 ms 1580 KB Output is correct
3 Runtime error 2779 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2628 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1236 KB Output is correct
2 Correct 6 ms 1580 KB Output is correct
3 Runtime error 2779 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -