Submission #1842060
Source Code Expand
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
#define rl rd<LL>
using namespace std;
typedef long long LL;
const int maxN = 2e5 + 7;
const int maxC = 26;
const int maxM = 127;
const LL INF = 1e18;
template<class T> inline T rd() {
bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}
char s[maxN];
int n, len, t;
int nx[maxN];
LL occ[maxC];
LL L, R;
void kmp() {
nx[1] = 0; int i, j;
for (i = 2, j = 0; i <= n; ++ i) {
while (j && s[j+1] != s[i]) j = nx[j];
if (s[j+1] == s[i]) ++ j;
nx[i] = j;
}
}
void solve1(LL len, LL kd) {
LL tms = len / t, res = len % t;
rep (i, 1, t) occ[s[i] - 'a'] += kd * (tms + (i <= res));
}
namespace solve2 {
LL f[maxM][maxC], len[maxM], Top;
void init() {
len[1] = t; rep (i, 1, t) ++ f[1][s[i] - 'a'];
len[0] = n - t; rep (i, t+1, n) ++ f[0][s[i] - 'a'];
For (i, 2, maxM) {
len[i] = len[i-1] + len[i-2];
Top = i;
For (j, 0, maxC) f[i][j] = f[i-1][j] + f[i-2][j];
if (len[i] > INF) break;
}
}
void dfs(int p, LL l, LL kd) {
if (l <= 0) return;
assert(l <= len[p]);
if (l == len[p]) {
For (i, 0, 26) occ[i] += kd * f[p][i];
return;
}
if (p == 0 || p == 1) {
int bg = (p == 1) ? 0 : t;
rep (i, 1, l) occ[s[bg+i] - 'a'] += kd;
return;
}
dfs(p-1, min(l, len[p-1]), kd);
dfs(p-2, l - len[p-1], kd);
}
void work(LL l, LL kd) {
dfs(Top, l, kd);
}
}
int main() {
scanf("%s", s+1);
L = rl(), R = rl();
n = strlen(s+1) >> 1;
len = (n + 1) >> 1;
kmp();
t = n - nx[n];
if (n % t == 0) solve1(R, 1), solve1(L-1, -1);
else solve2::init(), solve2::work(R, 1), solve2::work(L-1, -1);
For (i, 0, 26) printf("%lld%c", occ[i], " \n"[i == 25]);
return 0;
}
Submission Info
Submission Time
2017-12-09 11:53:22+0900
Task
F - SS
User
acha
Language
C++14 (GCC 5.4.1)
Score
1100
Code Size
2188 Byte
Status
AC
Exec Time
2 ms
Memory
768 KB
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:83:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%s", s+1);
^
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
1100 / 1100
Status
Set Name
Test Cases
Sample
sample1.txt, sample2.txt, sample3.txt
All
mx_100000_1_0.txt, rnd_6_16666_4.txt, rnd_7777_1_0.txt, rnd_7777_1_2289.txt, rnd_7777_1_6444.txt, rnd_7777_9_0.txt, rnd_7777_9_1542.txt, rnd_7777_9_2299.txt, rnd_77_1_0.txt, rnd_77_1_14.txt, rnd_77_1_2.txt, rnd_77_9_0.txt, rnd_77_9_11.txt, rnd_77_9_54.txt, rnd_7_1_0.txt, rnd_7_1_2.txt, rnd_7_1_3.txt, rnd_7_9_0.txt, rnd_7_9_1.txt, rnd_7_9_2.txt, rndmx_100000_1_0.txt, sample1.txt, sample2.txt, sample3.txt
Case Name
Status
Exec Time
Memory
mx_100000_1_0.txt
AC
2 ms
768 KB
rnd_6_16666_4.txt
AC
2 ms
768 KB
rnd_7777_1_0.txt
AC
1 ms
256 KB
rnd_7777_1_2289.txt
AC
1 ms
256 KB
rnd_7777_1_6444.txt
AC
1 ms
256 KB
rnd_7777_9_0.txt
AC
1 ms
640 KB
rnd_7777_9_1542.txt
AC
1 ms
640 KB
rnd_7777_9_2299.txt
AC
1 ms
640 KB
rnd_77_1_0.txt
AC
1 ms
128 KB
rnd_77_1_14.txt
AC
1 ms
128 KB
rnd_77_1_2.txt
AC
1 ms
128 KB
rnd_77_9_0.txt
AC
1 ms
128 KB
rnd_77_9_11.txt
AC
1 ms
128 KB
rnd_77_9_54.txt
AC
1 ms
128 KB
rnd_7_1_0.txt
AC
1 ms
128 KB
rnd_7_1_2.txt
AC
1 ms
128 KB
rnd_7_1_3.txt
AC
1 ms
128 KB
rnd_7_9_0.txt
AC
1 ms
128 KB
rnd_7_9_1.txt
AC
1 ms
128 KB
rnd_7_9_2.txt
AC
1 ms
128 KB
rndmx_100000_1_0.txt
AC
2 ms
768 KB
sample1.txt
AC
1 ms
128 KB
sample2.txt
AC
1 ms
128 KB
sample3.txt
AC
1 ms
128 KB