Submission #22385

# Submission time Handle Problem Language Result Execution time Memory
22385 2017-04-30T04:21:03 Z Lazy Against The Machine(#969, unused, celicath, Paruelain) Joyful KMP (KRIII5_JK) C++14
0 / 7
0 ms 2180 KB
#include <bits/stdc++.h>
using namespace std;

string str;
bool yes[256];
char val[256];
int order;
__int128 fact[30];
vector<char> rem;

void recur(int idx, unsigned long long k)
{
    if (idx == str.size())
    {
        printf("\n");
        return;
    }

    if (val[str[idx]])
    {
        putchar(val[str[idx]]);
        recur(idx + 1, k);
        return;
    }

    for (int i = 0; i < rem.size(); i++)
    {
        if (k > fact[rem.size() - 1] / fact[rem.size() - order])
        {
            k -= fact[rem.size() - 1] / fact[rem.size() - order];
        }
        else
        {
            val[str[idx]] = rem[i];
            --order;
            rem.erase(rem.begin() + i);
            putchar(val[str[idx]]);
            recur(idx + 1, k);
            return;
        }
    }
}

int main()
{
    cin.sync_with_stdio(false);
    cin >> str;
    unsigned long long k;
    cin >> k;

    fact[0] = 1;
    for (int i = 1; i <= 26; i++) fact[i] = i * fact[i - 1];

    for (int i = 'a'; i <= 'z'; i++) rem.push_back(i);

    for (char t : str)
    {
        if (yes[t]) continue;
        yes[t] = true;
        ++order;
    }

    printf("%d\n", (int)(fact[26] / fact[26 - order] % 1000000007));

    if (fact[26] / fact[26 - order] < k)
    {
        printf("OVER\n");
    }
    else
    {
        recur(0, k);
    }
}

Compilation message

JK.cpp: In function 'void recur(int, long long unsigned int)':
JK.cpp:13:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if (idx == str.size())
             ^
JK.cpp:19:21: warning: array subscript has type 'char' [-Wchar-subscripts]
     if (val[str[idx]])
                     ^
JK.cpp:21:29: warning: array subscript has type 'char' [-Wchar-subscripts]
         putchar(val[str[idx]]);
                             ^
JK.cpp:26:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < rem.size(); i++)
                       ^
JK.cpp:34:25: warning: array subscript has type 'char' [-Wchar-subscripts]
             val[str[idx]] = rem[i];
                         ^
JK.cpp:37:33: warning: array subscript has type 'char' [-Wchar-subscripts]
             putchar(val[str[idx]]);
                                 ^
JK.cpp: In function 'int main()':
JK.cpp:58:18: warning: array subscript has type 'char' [-Wchar-subscripts]
         if (yes[t]) continue;
                  ^
JK.cpp:59:14: warning: array subscript has type 'char' [-Wchar-subscripts]
         yes[t] = true;
              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2180 KB Output is correct
2 Incorrect 0 ms 2180 KB Output isn't correct
3 Halted 0 ms 0 KB -