Submission #94438

#TimeUsernameProblemLanguageResultExecution timeMemory
94438choikiwonJoyful KMP (KRIII5_JK)C++17
7 / 7
383 ms79052 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int MN = 1000010; int fa[MN]; void init() { for(int i = 0; i < MN; i++) fa[i] = i; } int find(int u) { if(fa[u] == u) return u; else return fa[u] = find(fa[u]); } void mrg(int u, int v) { u = find(u); v = find(v); if(u == v) return; fa[v] = u; } 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; int ans = 26; init(); 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; mrg(pi[i] - 1, i); } 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); ans = 1LL * ans * (26 - (int)V[i].size()) % mod; } } cout << ans << endl; int pos1 = 0; for(int i = 0; i < X.size(); i++) { while(pos1 < more.size() && more[pos1] <= i) pos1++; vector<int> chk(26, 0); for(int j = 0; j < V[ X[i] ].size(); j++) { chk[ sol[ find(V[ X[i] ][j]) ] ] = 1; } bool ok = false; for(int j = 0; j < 26; j++) { if(chk[j]) continue; ll tmp = 1; for(int k = pos1; k < more.size(); k++) { ll C = K / tmp; if(K % tmp) C++; if(C <= P[ more[k] ]) { tmp = K; break; } tmp *= P[ more[k] ]; } if(K > tmp) { K -= tmp; continue; } sol[ X[i] ] = j; ok = true; break; } if(!ok) { cout << "OVER"; return 0; } } 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 (stderr)

JK.cpp: In function 'int main()':
JK.cpp:39:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1, j = 0; i < S.size(); i++) {
                           ~~^~~~~~~~~~
JK.cpp:68:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < X.size(); i++) {
                    ~~^~~~~~~~~~
JK.cpp:69:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(pos1 < more.size() && more[pos1] <= i) pos1++;
               ~~~~~^~~~~~~~~~~~~
JK.cpp:72:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j = 0; j < V[ X[i] ].size(); j++) {
                        ~~^~~~~~~~~~~~~~~~~~
JK.cpp:81:33: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             for(int k = pos1; k < more.size(); k++) {
                               ~~^~~~~~~~~~~~~
JK.cpp:109:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < S.size(); i++) {
                    ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...