답안 #494374

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
494374 2021-12-15T10:55:43 Z jasen_penchev Brperm (RMI20_brperm) C++14
50 / 100
3000 ms 11120 KB
#include "brperm.h"
#include <iostream>
#include <string>
#define endl '\n'
using namespace std;

const int LOG = 20;

string str = "";

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;
        }
    }

    return;
}

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

    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:39: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]
   39 |     if (pos + (1ll << k) > str.size()) return 0;
      |         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 4540 KB Output is correct
2 Correct 59 ms 4572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 4540 KB Output is correct
2 Correct 59 ms 4572 KB Output is correct
3 Correct 102 ms 5084 KB Output is correct
4 Correct 85 ms 5080 KB Output is correct
5 Correct 88 ms 5052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3074 ms 11120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 4540 KB Output is correct
2 Correct 59 ms 4572 KB Output is correct
3 Correct 102 ms 5084 KB Output is correct
4 Correct 85 ms 5080 KB Output is correct
5 Correct 88 ms 5052 KB Output is correct
6 Execution timed out 3074 ms 11120 KB Time limit exceeded
7 Halted 0 ms 0 KB -