답안 #172051

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172051 2019-12-31T01:57:43 Z _qVp_ Tavan (COCI16_tavan) C++14
80 / 80
14 ms 484 KB
#include <bits/stdc++.h>
 
using namespace std;
 
const long long md = 505;
 
long long n, m, k, x, cnt = 1;
long long f[md];
string s, can[md], ans[md];
 
void findChar(long long p) {
    if (p == m - 1) {
        ans[p] = can[p][x - cnt];
        return ;
    }
    for(long long j = 0; j < k; j++) {
        if (cnt + f[m - p - 1] > x) {
            ans[p] = can[p][j];
            findChar(p + 1);
            break;
        } else cnt += f[m - p - 1];
    }
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin >> n >> m >> k >> x;
    cin >> s;
    for(long long i = 0; i < m; i++) {
        cin >> can[i];
        sort(can[i].begin(), can[i].end());
    }
    f[1] = k;
    for(int i = 2; i <= m; i++) {
        f[i] = min(x, f[i - 1] * k);
    }
    findChar(0);
    long long pos = 0;
    for(long long i = 0; i < n; i++) {
        if (s[i] == '#') {
            cout << ans[pos++]; 
        } else cout << s[i];
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 484 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 14 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct