답안 #398732

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
398732 2021-05-04T18:54:21 Z MilosMilutinovic Brperm (RMI20_brperm) C++14
100 / 100
1700 ms 34428 KB
/**
 *    author:  milos
 *    created: 04.05.2021 20:27:22       
**/
#include <bits/stdc++.h>
#include "brperm.h"
 
using namespace std;
 
const int N = 500050;
 
string s = "";
vector<pair<int, int>> a(N);
vector<vector<int>> cnt(N, vector<int>(2));
void Calc(int n) {
  for (int i = 0; i < n; i++) {
    int j = i, cnt = 0, res = 0;
    while (j) {
      res = res * 2 + j % 2;
      cnt++;
      j /= 2;
    }
    a[i] = {res, cnt};
  } 
}
 
void init(int n, const char seq[]) {
  for (int i = 0; i < n; i++) {
    s += seq[i];
    if (i > 0) {
      cnt[i][0] = cnt[i - 1][0];
      cnt[i][1] = cnt[i - 1][1];
    }
    if (s[i] == 'a') {
      cnt[i][0] += 1;
    }
    if (s[i] == 'b') {
      cnt[i][1] += 1;
    }
  }
  Calc(n); 
}
 
int Rev(int x, int k) {
  return a[x].first * (1 << (k - a[x].second));
}
 
int query(int i, int k) {
  if (i + (1 << k) > (int) s.size()) {
    return 0;
  }
  int L = i, R = i + (1 << k) - 1;
  if (cnt[R][0] - (L == 0 ? 0 : cnt[L - 1][0]) == R - L + 1) {
    return 1;
  }
  if (cnt[R][1] - (L == 0 ? 0 : cnt[L - 1][1]) == R - L + 1) {
    return 1;
  }
  for (int j = i; j < i + (1 << k); j++) {
    if (s[j] != s[i + Rev(j - i, k)]) {
      return 0;  
    }
  }
  return 1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 31588 KB Output is correct
2 Correct 39 ms 31820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 31588 KB Output is correct
2 Correct 39 ms 31820 KB Output is correct
3 Correct 75 ms 32820 KB Output is correct
4 Correct 75 ms 32908 KB Output is correct
5 Correct 79 ms 32708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1700 ms 34428 KB Output is correct
2 Correct 307 ms 34300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 31588 KB Output is correct
2 Correct 39 ms 31820 KB Output is correct
3 Correct 75 ms 32820 KB Output is correct
4 Correct 75 ms 32908 KB Output is correct
5 Correct 79 ms 32708 KB Output is correct
6 Correct 1700 ms 34428 KB Output is correct
7 Correct 307 ms 34300 KB Output is correct
8 Correct 273 ms 34284 KB Output is correct
9 Correct 274 ms 34276 KB Output is correct
10 Correct 273 ms 34292 KB Output is correct