Submission #494377

# Submission time Handle Problem Language Result Execution time Memory
494377 2021-12-15T11:00:10 Z jasen_penchev Brperm (RMI20_brperm) C++14
100 / 100
1355 ms 13620 KB
#include "brperm.h"
#include <iostream>
#include <string>
#define endl '\n'
using namespace std;

const int LOG = 20;
const int MAXN = 500000;

string str = "";
int diff[MAXN + 5];
int mem[LOG + 5][(1ll << LOG) + 5];

void init(int n, const char s[])
{
    for (int i = 0; i < n; ++ i)
    {
        str += s[i];
    }

    for (int k = 0; k < 20; ++ k)
    {
        for (int i = 0; i < (1ll << k); ++ i)
        {
            int idx = 0;
            for (int j = 0; j < k; ++ j)
            {
                if ((i & (1ll << j))) idx += (1ll << (k - j - 1));
            }

            mem[k][i] = idx;
        }
    }

    diff[n - 1] = n;
    for (int i = n - 2; i >= 0; -- i)
    {
        if (s[i] == s[i + 1]) diff[i] = diff[i + 1];
        else diff[i] = i + 1;
    }

    return;
}

int query(int pos, int k)
{
    if (pos + (1ll << k) > str.size()) return 0;

    if (pos + (1ll << k) <= diff[pos]) return 1;

    for (int i = 0; i < (1ll << k); ++ i)
    {
        int idx = mem[k][i];

        if (str[pos + i] != str[pos + idx]) return 0;
    }

    return 1;
}

Compilation message

brperm.cpp: In function 'int query(int, int)':
brperm.cpp:47:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     if (pos + (1ll << k) > str.size()) return 0;
      |         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 58 ms 4636 KB Output is correct
2 Correct 59 ms 4548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 4636 KB Output is correct
2 Correct 59 ms 4548 KB Output is correct
3 Correct 76 ms 5468 KB Output is correct
4 Correct 78 ms 5444 KB Output is correct
5 Correct 81 ms 5444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1355 ms 8644 KB Output is correct
2 Correct 202 ms 13572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 4636 KB Output is correct
2 Correct 59 ms 4548 KB Output is correct
3 Correct 76 ms 5468 KB Output is correct
4 Correct 78 ms 5444 KB Output is correct
5 Correct 81 ms 5444 KB Output is correct
6 Correct 1355 ms 8644 KB Output is correct
7 Correct 202 ms 13572 KB Output is correct
8 Correct 185 ms 13620 KB Output is correct
9 Correct 178 ms 13564 KB Output is correct
10 Correct 184 ms 13608 KB Output is correct