Submission #596746

# Submission time Handle Problem Language Result Execution time Memory
596746 2022-07-15T02:50:40 Z definitelynotmee Brperm (RMI20_brperm) C++17
67 / 100
2480 ms 7080 KB
#include "brperm.h"
#include<bits/stdc++.h>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
template<typename T>
using matrix = vector<vector<T>>;
const ll INFL = 1ll<<60;
const int MOD = 1e9+7;

string S;
vector<int> ocura, ocurb;
void init(int n, const char s[]) {

    S.resize(n);
    for(int i = 0; i < n; i++){
        S[i] = s[i];
        if(s[i] == 'a')
            ocura.push_back(i);
        else ocurb.push_back(i);
    }
    return;
}

int getreverse(int x, int k){
    int ret = 0;
    for(int i = 0; i < k; i++){
        ret+=(1<<i)*bool((1<<(k-i-1))&x);
    }
    return ret;
}

int query(int start, int k) {

    if(k == 0)
        return 1;


    bool ok = 1;
    if(start+(1<<k)>S.size())
        return 0;

    if(S.size() <= 1e5 || k <= 10){
        for(int i = 0; i < (1<<k); i++){
            //cout << k << ": " <<  bitset<4>(i-s   tart) << ' ' << bitset<4>(getreverse(i-start,k)) << '\n';
            //assert(getreverse(i,k)+start < S.size());
            ok&=S[getreverse(i,k)+start] == S[i+start];
        }
    } else {
        int ct = upper_bound(all(ocura),start+(1<<k))-lower_bound(all(ocura),start);
        if(ct <= 100){
            auto id = upper_bound(all(ocura),start);
            bool ok = 1;
            while(id!=ocura.end() && *id < start+(1<<k))
                ok&=S[getreverse(*id-start,k)+start] == S[*id], id++;
            return ok;
        } else if ((1<<k)-ct <= 100){
            auto id = upper_bound(all(ocurb),start);
            bool ok = 1;
            while(id!=ocurb.end() && *id < start+(1<<k))
                ok&=S[getreverse(*id-start,k)+start] == S[*id], id++;
            return ok;
        } else {
            return 0;
        }
    }
    

    return ok;
}

Compilation message

brperm.cpp: In function 'int query(int, int)':
brperm.cpp:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     if(start+(1<<k)>S.size())
      |        ~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2462 ms 1356 KB Output is correct
4 Correct 2470 ms 1312 KB Output is correct
5 Correct 2480 ms 1356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 217 ms 6044 KB Output is correct
2 Correct 474 ms 7080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 2462 ms 1356 KB Output is correct
4 Correct 2470 ms 1312 KB Output is correct
5 Correct 2480 ms 1356 KB Output is correct
6 Correct 217 ms 6044 KB Output is correct
7 Correct 474 ms 7080 KB Output is correct
8 Incorrect 362 ms 7076 KB Output isn't correct
9 Halted 0 ms 0 KB -