답안 #98554

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98554 2019-02-24T02:53:34 Z qwqHandwer Tavan (COCI16_tavan) C++
80 / 80
3 ms 512 KB
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <cmath>

#define FILE_IN(__fname) freopen(__fname, "r", stdin)
#define FILE_OUT(__fname) freopen(__fname, "w", stdout)
#define IMPROVE_IO() std::ios::sync_with_stdio(false)

using std::cin;
using std::cout;
using std::endl;

const int MAX = 500 + 10;

int n, m, k, x;
std::string s;
std::string keywords[MAX];
char rep[MAX];

void Process(int now = 1, int left = x - 1) {
    if (now == m + 1) return;
    long long int maxNow = 1;
    bool ud = false;
    for (int i = 1; i <= m - now; ++i) {
        maxNow *= k;
        if (maxNow > left) {
            ud = true;
            break;
        }
    }
    if (ud) {
        rep[now] = keywords[now][0];
        Process(now + 1, left);
    }
    else {
        rep[now] = keywords[now][left / maxNow];
        Process(now + 1, left - (left / maxNow) * maxNow);
    }
}

int main() {
    IMPROVE_IO();
    cin >> n >> m >> k >> x;
    cin >> s;
    for (int i = 1; i <= m; ++i) {
        cin >> keywords[i];
        std::sort(keywords[i].begin(), keywords[i].end());
    }
    Process();
    for (int i = 0, cnt = 1; i < n; ++i) {
        cout << (s[i] == '#' ? rep[cnt++] : s[i]);
    }
    cout << endl;
    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 384 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 384 KB Output is correct