답안 #22867

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22867 2017-04-30T07:55:19 Z past future present(#977, kazel, pjh0123, nemo) Joyful KMP (KRIII5_JK) C++14
2 / 7
83 ms 10880 KB
#include<stdio.h>
#include<string.h>

using ll = long long;
const int mod = 1e9 + 7;
char s[1000005], ans[1000005];
int n, ff[1000005];


void calculate_pi() {
    ff[0] = -1;
    for (int i = 1, j = -1; i < n; i++) {
        while (j >= 0 && s[i] != s[j + 1]) j = ff[j];
        if (s[i] == s[j + 1])
            ff[i] = ++j;
        else
            ff[i] = -1;
    }
}

int pt[1000005], psz;

int main()
{
    ll k;
    scanf("%s%lld", s,&k);
    n = strlen(s);

    int num = 26;
    ff[0]=-1;
    for (int i = 1, j=-1; i < n; i++){
        char orig = s[i];
        int origj = j;

        while(j >=0 && s[i] != s[j+1]) j=ff[j];
        if(s[i]==s[j+1]) ff[i] = ++j;
        else ff[i] = -1;

        int afterj = j;
        if(ff[i] == -1){
            ll c = 0;
            for(int ii=0;ii<26;ii++){
                s[i] = 'a'+ii;
                j = origj;

                while(j >=0 && s[i] != s[j+1]) j=ff[j];
                if(s[i]==s[j+1]) ff[i] = ++j;
                else ff[i] = -1;
                
                if(ff[i] == -1)c++;
            }

            num = num*c%mod;
            pt[++psz] = i;
            ff[i] = -1;
        }
        j = afterj;
        s[i] = orig;
    }
    printf("%d\n", num);
    k--;
    for (int j = psz; j >= 0; j--)
    {
        ans[pt[j]] = 'a' + k % 25;
        k /= 25;
    }
    if (k > 0)
    {
        puts("OVER");
        return 0;
    }
    for (int i = 1; i < n; i++)
    {
        if (ans[i])
        {
            if (ans[i] >= ans[0]) ans[i]++;
            continue;
        }
        ans[i] = ans[ff[i]];
    }
    puts(ans);
}

Compilation message

JK.cpp: In function 'int main()':
JK.cpp:26:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s%lld", s,&k);
                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 10880 KB Output is correct
2 Correct 0 ms 10880 KB Output is correct
3 Partially correct 0 ms 10880 KB Output is partially correct
4 Partially correct 0 ms 10880 KB Output is partially correct
5 Partially correct 69 ms 10880 KB Output is partially correct
6 Partially correct 76 ms 10880 KB Output is partially correct
7 Partially correct 79 ms 10880 KB Output is partially correct
8 Partially correct 69 ms 10880 KB Output is partially correct
9 Partially correct 83 ms 10880 KB Output is partially correct
10 Correct 0 ms 10880 KB Output is correct
11 Correct 0 ms 10880 KB Output is correct
12 Partially correct 0 ms 10880 KB Output is partially correct
13 Partially correct 0 ms 10880 KB Output is partially correct
14 Partially correct 0 ms 10880 KB Output is partially correct
15 Partially correct 0 ms 10880 KB Output is partially correct
16 Partially correct 3 ms 10880 KB Output is partially correct
17 Partially correct 23 ms 10880 KB Output is partially correct
18 Partially correct 53 ms 10880 KB Output is partially correct
19 Partially correct 43 ms 10880 KB Output is partially correct
20 Partially correct 43 ms 10880 KB Output is partially correct
21 Partially correct 49 ms 10880 KB Output is partially correct
22 Partially correct 49 ms 10880 KB Output is partially correct
23 Partially correct 6 ms 10880 KB Output is partially correct
24 Partially correct 3 ms 10880 KB Output is partially correct
25 Partially correct 9 ms 10880 KB Output is partially correct
26 Partially correct 6 ms 10880 KB Output is partially correct
27 Partially correct 9 ms 10880 KB Output is partially correct
28 Partially correct 6 ms 10880 KB Output is partially correct
29 Partially correct 6 ms 10880 KB Output is partially correct
30 Partially correct 9 ms 10880 KB Output is partially correct
31 Partially correct 6 ms 10880 KB Output is partially correct
32 Partially correct 9 ms 10880 KB Output is partially correct
33 Partially correct 6 ms 10880 KB Output is partially correct
34 Partially correct 6 ms 10880 KB Output is partially correct
35 Partially correct 6 ms 10880 KB Output is partially correct
36 Partially correct 9 ms 10880 KB Output is partially correct
37 Partially correct 3 ms 10880 KB Output is partially correct
38 Partially correct 9 ms 10880 KB Output is partially correct
39 Partially correct 6 ms 10880 KB Output is partially correct
40 Partially correct 6 ms 10880 KB Output is partially correct
41 Partially correct 6 ms 10880 KB Output is partially correct
42 Partially correct 6 ms 10880 KB Output is partially correct
43 Partially correct 3 ms 10880 KB Output is partially correct
44 Correct 3 ms 10880 KB Output is correct
45 Correct 9 ms 10880 KB Output is correct
46 Partially correct 9 ms 10880 KB Output is partially correct
47 Partially correct 6 ms 10880 KB Output is partially correct
48 Partially correct 3 ms 10880 KB Output is partially correct
49 Correct 9 ms 10880 KB Output is correct
50 Partially correct 6 ms 10880 KB Output is partially correct