답안 #401623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
401623 2021-05-10T15:02:46 Z maximath_1 Brperm (RMI20_brperm) C++17
100 / 100
1710 ms 64352 KB
#include <bits/stdc++.h>
#include "brperm.h"
using namespace std;
const int MX = 500005;

int n;
char ss[MX];
int cnt[MX][27];
pair<int, int> pc[MX];

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

	for(int i = 0, j, cnt, rs; i < n; i ++){
		j = i; cnt = rs = 0;
		for(; j > 0; j /= 2, cnt ++)
			rs = (rs << 1) + (j % 2);
		pc[i] = make_pair(rs, cnt);
	}

	for(int i = 0; i < n; i ++){
		if(i > 0){
			for(int j = 0; j < 26; j ++)
				cnt[i][j] = cnt[i - 1][j];
		}
		cnt[i][s[i] - 'a'] ++;
	}
}

inline int get(int x, int k){
	return pc[x].first * (1 << (k - pc[x].second));
}

int query(int i, int k){
	if(i + (1 << k) - 1 >= n) return 0;
	for(int j = 0; j < 26; j ++)
		if(cnt[i + (1 << k) - 1][j] - (i == 0 ? 0 : cnt[i - 1][j]) == (1 << k))
			return 1;
	for(int j = i; j < i + (1 << k); j ++)
		if(ss[j] != ss[i + get(j - i, k)]) return 0;
	return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 58 ms 12968 KB Output is correct
4 Correct 47 ms 12944 KB Output is correct
5 Correct 48 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1710 ms 64352 KB Output is correct
2 Correct 293 ms 63968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 472 KB Output is correct
3 Correct 58 ms 12968 KB Output is correct
4 Correct 47 ms 12944 KB Output is correct
5 Correct 48 ms 12892 KB Output is correct
6 Correct 1710 ms 64352 KB Output is correct
7 Correct 293 ms 63968 KB Output is correct
8 Correct 275 ms 64068 KB Output is correct
9 Correct 286 ms 63988 KB Output is correct
10 Correct 293 ms 64076 KB Output is correct