Submission #22289

# Submission time Handle Problem Language Result Execution time Memory
22289 2017-04-30T03:39:10 Z ↓우리보다잘하는팀(#947, ainta, gs12117, gs13068) Joyful KMP (KRIII5_JK) C++14
7 / 7
99 ms 17716 KB
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

const long long INF = 91e17;

char a[1000001];
int f[1000001];
int c[1000001];
int v[26];
long long d[1000001];

int main() {
	long long m;
	int i, j, k, l, n, r;
	scanf("%s%lld", a, &m);
	n = strlen(a);
	f[i = 0] = j = -1;
	while (i < n) {
		if (j == -1) {
			for (k = 0; k < 26; k++) {
				if (!v[k]) c[i]++;
				v[k] = 0;
			}
			f[++i] = ++j;
		}
		else if (a[i] == a[j]) {
			for (k = 0; k < 26; k++) v[k] = 0;
			c[i] = 1;
			f[++i] = ++j;
		}
		else {
			v[a[j] - 97] = 1;
			j = f[j];
		}
	}
	d[n] = r = 1;
	for (i = n - 1; i >= 0; i--) {
		r = 1ll * r * c[i] % 1000000007;
		d[i] = 1. * d[i + 1] * c[i] > INF ? INF : d[i + 1] * c[i];
	}
	printf("%d\n", r);
	if (d[0] < m) {
		puts("OVER");
		return 0;
	}
	m--;
	j = -1;
	for (i = 0; i < n; i++) {
		for (k = 0; k < 26; k++) v[k] = 0;
		while (f[i + 1] != j + 1) {
			v[a[j] - 97] = 1;
			j = f[j];
		}
		if (j != -1) k = a[j] - 97;
		else {
			l = m / d[i + 1];
			m %= d[i + 1];
			for (k = 0; k < 26; k++) {
				if (!v[k]) {
					if (!l) break;
					l--;
				}
			}
		}
		putchar(a[i] = k + 97);
		j++;
	}
}

Compilation message

JK.cpp: In function 'int main()':
JK.cpp:18:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s%lld", a, &m);
                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 17716 KB Output is correct
2 Correct 0 ms 17716 KB Output is correct
3 Correct 0 ms 17716 KB Output is correct
4 Correct 0 ms 17716 KB Output is correct
5 Correct 89 ms 17716 KB Output is correct
6 Correct 99 ms 17716 KB Output is correct
7 Correct 99 ms 17716 KB Output is correct
8 Correct 89 ms 17716 KB Output is correct
9 Correct 96 ms 17716 KB Output is correct
10 Correct 0 ms 17716 KB Output is correct
11 Correct 0 ms 17716 KB Output is correct
12 Correct 0 ms 17716 KB Output is correct
13 Correct 0 ms 17716 KB Output is correct
14 Correct 0 ms 17716 KB Output is correct
15 Correct 3 ms 17716 KB Output is correct
16 Correct 9 ms 17716 KB Output is correct
17 Correct 43 ms 17716 KB Output is correct
18 Correct 86 ms 17716 KB Output is correct
19 Correct 86 ms 17716 KB Output is correct
20 Correct 86 ms 17716 KB Output is correct
21 Correct 86 ms 17716 KB Output is correct
22 Correct 86 ms 17716 KB Output is correct
23 Correct 59 ms 17716 KB Output is correct
24 Correct 49 ms 17716 KB Output is correct
25 Correct 56 ms 17716 KB Output is correct
26 Correct 59 ms 17716 KB Output is correct
27 Correct 59 ms 17716 KB Output is correct
28 Correct 49 ms 17716 KB Output is correct
29 Correct 46 ms 17716 KB Output is correct
30 Correct 66 ms 17716 KB Output is correct
31 Correct 56 ms 17716 KB Output is correct
32 Correct 49 ms 17716 KB Output is correct
33 Correct 53 ms 17716 KB Output is correct
34 Correct 59 ms 17716 KB Output is correct
35 Correct 66 ms 17716 KB Output is correct
36 Correct 53 ms 17716 KB Output is correct
37 Correct 56 ms 17716 KB Output is correct
38 Correct 59 ms 17716 KB Output is correct
39 Correct 56 ms 17716 KB Output is correct
40 Correct 56 ms 17716 KB Output is correct
41 Correct 53 ms 17716 KB Output is correct
42 Correct 63 ms 17716 KB Output is correct
43 Correct 43 ms 17716 KB Output is correct
44 Correct 46 ms 17716 KB Output is correct
45 Correct 53 ms 17716 KB Output is correct
46 Correct 59 ms 17716 KB Output is correct
47 Correct 59 ms 17716 KB Output is correct
48 Correct 56 ms 17716 KB Output is correct
49 Correct 26 ms 17716 KB Output is correct
50 Correct 59 ms 17716 KB Output is correct