답안 #1070110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070110 2024-08-22T11:42:36 Z Sorting Brperm (RMI20_brperm) C++17
0 / 100
20 ms 42520 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <iomanip>
#include <queue>
#include <stack>
#include <numeric>
#include <cassert>
#include <cmath>
#include <random>
#include <ctime>
#include <chrono>
#include "brperm.h"
#define MAXN 100010 //500010
#define LOGN 25
using namespace std;
long long tab[MAXN][LOGN];
string str="";
 
//transition: x-> r*(2^(k-bits)), bits=log2(x), r=transition for x in base form
//unchanged: 2^(k/2)*fl, fl=1 for k%2=0, otherwise fl=2
//changed: (2^k - unchanged)/2

int calc_log(int x){
    if(x == 0) return 0;
    return 1 + calc_log(x / 2);
}

void init(int n, const char s[])
{
    for(int i=0;i<n;i++) str += s[i];
    for(int j=0;j<=20;j++){tab[0][j]=0;}
    for(int i=1;i<=n;i++)
    {
        int logx = calc_log(i);
        int si=i,cntr=0;
        long long m=0;
        while(si>0)
        {
            bool bit=si&1;
            long long ncalc=logx-1-cntr;
            ncalc=1<<ncalc;
            m+=bit*ncalc;
            si>>=1;
            cntr++;
        }
        tab[i][logx]=m;
        for(int j=logx+1;j<=20;j++)
        {
            tab[i][j]=tab[i][j-1]<<1;
        }
    }
}
 
int query(int i, int k)
{
    int lim=(1<<k);
    //if(i+lim>=(int)str.size())return 0;
    for(int curr=0;curr<lim;curr++)
    {
        if(i+curr>=str.size())return 0;
        if(str[i+curr]!=str[i+tab[curr][k]])return 0;
    }
    return 1;
}

Compilation message

brperm.cpp: In function 'int query(int, int)':
brperm.cpp:64:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |         if(i+curr>=str.size())return 0;
      |            ~~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 4956 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 4956 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 20 ms 42520 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 4956 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -