# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958019 | 2024-04-04T16:40:22 Z | puelwon | Joyful KMP (KRIII5_JK) | C++17 | 1 ms | 2140 KB |
#include <stdio.h> #include <string.h> #include <vector> using namespace std; #define mod 1000000007 long long int f(int n) { long long int sum=1; for(int i=26;i>26-n;i--) { sum=(sum*i)%mod; } return sum; } int main(void) { char str[1000001]; (void)scanf("%s",str); long long int k; (void)scanf("%lld",&k); int ar[27]={}; int er[27]={}; int unused=0; vector<int> we[27]; int len=strlen(str); for(int i=0;i<len;i++) { if(er[str[i]-'a']==0) { er[str[i]-'a']=1; ar[str[i]-'a']=unused; we[unused++].push_back(i); } else { we[ar[str[i]-'a']].push_back(i); } } long long int cnt=f(unused); long long int cc=26-(unused-1); int re[27]={}; k--; for(int i=unused-1;i>=0;i--) { re[i]=k%cc; k/=cc; cc++; } if(k!=0) { printf("%lld\n",cnt); printf("OVER"); return 0; } char ans[1000001]={}; for(int i=0;i<unused;i++) { int pp=re[i]+'a'; int tt[27+'a']={}; for(int k=0;k<i;k++) { tt[(int)ans[k]]=1; } for(int k='a';k<=pp;k++) { if(tt[k]==1) pp++; } for(int j=0;j<we[i].size();j++) { ans[we[i][j]]=pp; } } printf("%lld\n",cnt); printf("%s",ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 2140 KB | Output is correct |
2 | Incorrect | 1 ms | 2140 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |