답안 #94429

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94429 2019-01-18T12:19:33 Z choikiwon Joyful KMP (KRIII5_JK) C++17
2 / 7
352 ms 79064 KB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;

const int mod = 1e9 + 7;
const int MN = 1000010;

string S;
ll K;
int pi[MN], sol[MN];
vector<int> V[MN], P, more, smul, X;

int main() {
    std::ios::sync_with_stdio(false);

    cin >> S >> K;

    X.push_back(0);
    P.push_back(26);
    more.push_back(0);
    for(int i = 1, j = 0; i < S.size(); i++) {
        vector<int> chk(26, 0);
        while(j && S[i] != S[j]) {
            if(!chk[ S[j] - 'a' ]) {
                chk[ S[j] - 'a' ] = 1;
                V[i].push_back(j);
            }
            j = pi[j - 1];
        }
        if(S[i] == S[j]) {
            pi[i] = ++j;
        }
        else {
            if(!chk[ S[0] - 'a' ]) {
                V[i].push_back(0);
            }
            if(26 - (int)V[i].size() > 1) {
                more.push_back(P.size());
            }
            P.push_back(26 - (int)V[i].size());
            X.push_back(i);
        }
    }

    smul.resize(more.size());
    for(int i = (int)more.size() - 1; i >= 0; i--) {
        smul[i] = P[ more[i] ];
        if(i != (int)more.size() - 1) {
            smul[i] = 1LL * smul[i] * smul[i + 1] % mod;
        }
    }

    cout << smul[0] << endl;

    int pos1 = 0;
    for(int i = 0; i < X.size(); i++) {
        while(pos1 < more.size() && more[pos1] <= i) pos1++;

        int pos2 = 0;
        for(int j = 0; j < 26; j++) {
            if(pos2 < V[ X[i] ].size() && V[ X[i] ][pos2] == j) {
                pos2++;
                continue;
            }

            ll tmp = 1;
            for(int k = pos1; k < more.size(); k++) {
                if((K + tmp - 1) / tmp <= P[ more[k] ]) {
                    tmp = K;
                    break;
                }
                tmp *= P[ more[k] ];
            }
            if(K > tmp) {
                K -= tmp;
                continue;
            }
            sol[ X[i] ] = j;
            break;
        }
    }

    if(K != 1) {
        cout << "OVER";
        return 0;
    }

    for(int i = 0; i < S.size(); i++) {
        if(pi[i]) sol[i] = sol[ pi[i] - 1 ];
        cout << (char)('a' + sol[i]);
    }
}

Compilation message

JK.cpp: In function 'int main()':
JK.cpp:22:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1, j = 0; i < S.size(); i++) {
                           ~~^~~~~~~~~~
JK.cpp:57:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < X.size(); i++) {
                    ~~^~~~~~~~~~
JK.cpp:58:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(pos1 < more.size() && more[pos1] <= i) pos1++;
               ~~~~~^~~~~~~~~~~~~
JK.cpp:62:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(pos2 < V[ X[i] ].size() && V[ X[i] ][pos2] == j) {
                ~~~~~^~~~~~~~~~~~~~~~~~
JK.cpp:68:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = pos1; k < more.size(); k++) {
                               ~~^~~~~~~~~~~~~
JK.cpp:89:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < S.size(); i++) {
                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 23800 KB Output is correct
2 Correct 19 ms 23800 KB Output is correct
3 Partially correct 19 ms 23800 KB Output is partially correct
4 Partially correct 24 ms 23832 KB Output is partially correct
5 Partially correct 346 ms 78828 KB Output is partially correct
6 Partially correct 352 ms 78812 KB Output is partially correct
7 Partially correct 351 ms 78892 KB Output is partially correct
8 Partially correct 341 ms 78900 KB Output is partially correct
9 Partially correct 344 ms 79064 KB Output is partially correct
10 Correct 24 ms 23800 KB Output is correct
11 Correct 23 ms 23800 KB Output is correct
12 Partially correct 24 ms 23800 KB Output is partially correct
13 Partially correct 24 ms 24056 KB Output is partially correct
14 Partially correct 26 ms 24184 KB Output is partially correct
15 Partially correct 34 ms 25720 KB Output is partially correct
16 Partially correct 46 ms 27248 KB Output is partially correct
17 Partially correct 127 ms 40636 KB Output is partially correct
18 Partially correct 239 ms 58304 KB Output is partially correct
19 Partially correct 258 ms 58220 KB Output is partially correct
20 Partially correct 251 ms 56936 KB Output is partially correct
21 Partially correct 234 ms 57900 KB Output is partially correct
22 Partially correct 234 ms 54880 KB Output is partially correct
23 Partially correct 96 ms 33792 KB Output is partially correct
24 Partially correct 98 ms 33840 KB Output is partially correct
25 Partially correct 96 ms 33792 KB Output is partially correct
26 Partially correct 99 ms 33740 KB Output is partially correct
27 Partially correct 103 ms 33920 KB Output is partially correct
28 Partially correct 100 ms 33792 KB Output is partially correct
29 Partially correct 101 ms 33788 KB Output is partially correct
30 Partially correct 99 ms 33792 KB Output is partially correct
31 Partially correct 101 ms 33792 KB Output is partially correct
32 Partially correct 103 ms 33900 KB Output is partially correct
33 Partially correct 101 ms 33792 KB Output is partially correct
34 Partially correct 99 ms 33764 KB Output is partially correct
35 Partially correct 92 ms 33824 KB Output is partially correct
36 Partially correct 92 ms 33728 KB Output is partially correct
37 Partially correct 93 ms 33792 KB Output is partially correct
38 Partially correct 92 ms 33788 KB Output is partially correct
39 Partially correct 98 ms 33792 KB Output is partially correct
40 Partially correct 103 ms 33788 KB Output is partially correct
41 Partially correct 101 ms 33916 KB Output is partially correct
42 Partially correct 102 ms 33792 KB Output is partially correct
43 Partially correct 99 ms 33792 KB Output is partially correct
44 Correct 99 ms 33732 KB Output is correct
45 Correct 100 ms 33808 KB Output is correct
46 Partially correct 98 ms 33712 KB Output is partially correct
47 Partially correct 99 ms 33788 KB Output is partially correct
48 Partially correct 96 ms 33792 KB Output is partially correct
49 Partially correct 96 ms 33836 KB Output is partially correct
50 Partially correct 100 ms 33760 KB Output is partially correct