Submission #596602

# Submission time Handle Problem Language Result Execution time Memory
596602 2022-07-14T21:29:52 Z Deepesson Brperm (RMI20_brperm) C++17
100 / 100
819 ms 30844 KB
#include <bits/stdc++.h>
#define MAX 505000

void init(int n, const char s[]);
int query(int i, int k);
std::vector<int> cores[26];
int inverte(int x,int k){
    int ans=0;
    for(int i=0;i!=k;++i){
        int u = (k-1)-i;
        if((1<<i)&x)ans+=1<<u;
    }
    return ans;
}
int pec[MAX][20];
int lim;
char vals[MAX];
void init(int n, const char s[]) {
    for(int j=0;j!=n;++j){
        vals[j]=s[j];
        cores[s[j]-'a'].push_back(j);
    }
    for(int i=0;i!=20;++i){
        int sz = 1<<i;
        if(sz>MAX)break;
        for(int k=0;k!=sz;++k){
            pec[k][i]=inverte(k,i);
        }
    }
    lim = n;
}

int query(int i, int k) {
    int sz = 1<<(k);
    if(i+sz>lim)return 0;
    int count=0;
    for(int j=0;j!=sz;++j){
        int mirror = pec[j][k];
        count++;
        if(vals[mirror+i]!=vals[j+i])return 0;
        if(count==505)break;
    }

    ///Ideia: testar um tiquinho de cada cor
    for(int j=0;j!=26;++j){
        int l=0,r=cores[j].size();
        while(l<r){
            int m = (l+r)/2;
            if(cores[j][m]>=i){
                r=m;
            }else l=m+1;
        }
        int anda=0;
        while(l<cores[j].size()&&anda<50&&cores[j][l]<i+sz){
            int pos = cores[j][l]-i;
            int mirror = pec[pos][k];
            if(vals[mirror+i]!=vals[pos+i])return 0;
            ++anda;
            ++l;
        }
    }
    return 1;
}

Compilation message

brperm.cpp: In function 'int query(int, int)':
brperm.cpp:54:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |         while(l<cores[j].size()&&anda<50&&cores[j][l]<i+sz){
      |               ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 20844 KB Output is correct
2 Correct 37 ms 20824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 20844 KB Output is correct
2 Correct 37 ms 20824 KB Output is correct
3 Correct 155 ms 21716 KB Output is correct
4 Correct 158 ms 21752 KB Output is correct
5 Correct 158 ms 21708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 589 ms 24892 KB Output is correct
2 Correct 264 ms 29780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 20844 KB Output is correct
2 Correct 37 ms 20824 KB Output is correct
3 Correct 155 ms 21716 KB Output is correct
4 Correct 158 ms 21752 KB Output is correct
5 Correct 158 ms 21708 KB Output is correct
6 Correct 589 ms 24892 KB Output is correct
7 Correct 264 ms 29780 KB Output is correct
8 Correct 814 ms 30744 KB Output is correct
9 Correct 814 ms 30844 KB Output is correct
10 Correct 819 ms 30772 KB Output is correct