Submission #958019

#TimeUsernameProblemLanguageResultExecution timeMemory
958019puelwonJoyful KMP (KRIII5_JK)C++17
0 / 7
1 ms2140 KiB
#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 (stderr)

JK.cpp: In function 'int main()':
JK.cpp:75:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int j=0;j<we[i].size();j++)
      |                 ~^~~~~~~~~~~~~
JK.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   (void)scanf("%s",str);
      |         ~~~~~^~~~~~~~~~
JK.cpp:21:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   (void)scanf("%lld",&k);
      |         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...