답안 #22781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22781 2017-04-30T07:26:53 Z 팀명을 한번 정하면 못바꿀까?(#898, qja0950) Joyful KMP (KRIII5_JK) C++14
2 / 7
143 ms 84012 KB
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <set>
#include <map>
#include <queue>
#include <tuple>
#include <string.h>

using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<int, int> pi;

const int MAX_N = 1e6 + 100, MOD = 1e9 + 7;

char P[MAX_N]; int N, F[MAX_N];
int S[MAX_N];
char Ans[MAX_N];
vector<int> D[MAX_N];
ll Memo[MAX_N][2]; int Next[MAX_N];

int main() {
	scanf("%s", P+1); N = strlen(P+1);
	for(int i=1; i<=N; i++) S[i] = i;
	for(int i=2, k=0;i<=N;i++) {
		vector<int> list;
		while(k && P[k+1] != P[i]) {
//			printf("Diff %d %d\n", k+1, i);
			list.push_back(k+1);
			k = F[k];
		}
		if(P[k+1] == P[i]) {
//			printf("Same %d %d\n", k+1, i);
			S[i] = S[k+1];
			k++;
		} else {
//			printf("Diff %d %d\n", k+1, i);
			list.push_back(k+1);
		}
		F[i] = k;
		for(int x : list)
			D[S[i]].push_back(S[x]);
	}
	for(int i=1; i<=N; i++) {
//		printf("%d(%c) : %d\n", i, P[i], F[i]);
		sort(D[i].begin(), D[i].end()); D[i].erase(unique(D[i].begin(), D[i].end()), D[i].end());
//		printf("S : %d\n", S[i]);
//		for(int x : D[i]) printf("%d ", x); puts("");
	}
	int ans = 1, past = N+1;
	Memo[N+1][0] = 0; Memo[N+1][1] = 1;
	ll be[2] = {0, 1}, base = 1e15;
	for(int i=N; i>=1; i--) {
		if(S[i] != i) continue;
		int cnt = 0;
		for(int x : D[i]) if(x < i) cnt++;
		ans = 1ll * ans * (26 - cnt) % MOD;

		Next[i] = past; past = i;
		be[1] *= (26 - cnt); 
		if(be[0] < base) be[0] *= (26 - cnt);
		be[0] += be[1] / base; be[1] %= base;
		Memo[i][0] = be[0], Memo[i][1] = be[1];
	}
	printf("%d\n", ans);
	ll K; scanf("%lld", &K);
	if(be[0] < K/base || (be[0] == K/base && be[1] < K%base)) puts("OVER");
	else {
		for(int i=1; i<=N; i++) {
			if(S[i] != i) {
				Ans[i] = Ans[S[i]];
				continue;
			}
		}
	}
	return 0;
}

Compilation message

JK.cpp: In function 'int main()':
JK.cpp:26:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%s", P+1); N = strlen(P+1);
                  ^
JK.cpp:69:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  ll K; scanf("%lld", &K);
                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 53916 KB Output is correct
2 Correct 0 ms 53916 KB Output is correct
3 Partially correct 6 ms 53916 KB Output is partially correct
4 Partially correct 6 ms 53916 KB Output is partially correct
5 Partially correct 126 ms 83880 KB Output is partially correct
6 Partially correct 133 ms 84012 KB Output is partially correct
7 Partially correct 126 ms 84012 KB Output is partially correct
8 Partially correct 129 ms 84012 KB Output is partially correct
9 Partially correct 139 ms 83880 KB Output is partially correct
10 Correct 6 ms 53916 KB Output is correct
11 Correct 6 ms 53916 KB Output is correct
12 Partially correct 3 ms 53916 KB Output is partially correct
13 Partially correct 9 ms 54048 KB Output is partially correct
14 Partially correct 3 ms 54048 KB Output is partially correct
15 Partially correct 16 ms 54616 KB Output is partially correct
16 Partially correct 19 ms 55236 KB Output is partially correct
17 Partially correct 69 ms 60240 KB Output is partially correct
18 Partially correct 133 ms 66752 KB Output is partially correct
19 Partially correct 143 ms 67508 KB Output is partially correct
20 Partially correct 136 ms 67252 KB Output is partially correct
21 Partially correct 139 ms 66824 KB Output is partially correct
22 Partially correct 133 ms 66892 KB Output is partially correct
23 Partially correct 23 ms 53916 KB Output is partially correct
24 Partially correct 16 ms 53916 KB Output is partially correct
25 Partially correct 13 ms 53916 KB Output is partially correct
26 Partially correct 19 ms 53916 KB Output is partially correct
27 Partially correct 19 ms 53916 KB Output is partially correct
28 Partially correct 16 ms 53916 KB Output is partially correct
29 Partially correct 26 ms 53916 KB Output is partially correct
30 Partially correct 16 ms 53916 KB Output is partially correct
31 Partially correct 16 ms 53916 KB Output is partially correct
32 Partially correct 9 ms 53916 KB Output is partially correct
33 Partially correct 19 ms 53916 KB Output is partially correct
34 Partially correct 26 ms 53916 KB Output is partially correct
35 Partially correct 13 ms 53916 KB Output is partially correct
36 Partially correct 19 ms 53916 KB Output is partially correct
37 Partially correct 13 ms 53916 KB Output is partially correct
38 Partially correct 23 ms 53916 KB Output is partially correct
39 Partially correct 16 ms 53916 KB Output is partially correct
40 Partially correct 23 ms 53916 KB Output is partially correct
41 Partially correct 23 ms 53916 KB Output is partially correct
42 Partially correct 26 ms 53916 KB Output is partially correct
43 Partially correct 16 ms 53916 KB Output is partially correct
44 Partially correct 9 ms 53916 KB Output is partially correct
45 Partially correct 13 ms 53916 KB Output is partially correct
46 Partially correct 9 ms 53916 KB Output is partially correct
47 Partially correct 26 ms 53916 KB Output is partially correct
48 Partially correct 19 ms 53916 KB Output is partially correct
49 Correct 16 ms 53916 KB Output is correct
50 Partially correct 16 ms 53916 KB Output is partially correct