답안 #958019

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958019 2024-04-04T16:40:22 Z puelwon Joyful KMP (KRIII5_JK) C++17
0 / 7
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

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);
      |         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 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 -