Submission #94158

# Submission time Handle Problem Language Result Execution time Memory
94158 2019-01-16T12:05:18 Z Kewo Tavan (COCI16_tavan) C++14
80 / 80
30 ms 31736 KB
#include <bits/stdc++.h>
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define mp make_pair
#define timer ((double)clock() / CLOCKS_PER_SEC)
#define endl "\n"
#define spc " "
#define d1(x) cerr<<#x<<":"<<x<<endl
#define d2(x, y) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<endl
#define d3(x, y, z) cerr<<#x<<":"<<x<<" "<<#y<<":"<<y<<" "<<#z<<":"<<z<<endl
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<double, double> dd;

const int N = (int)(1e6 + 5);
const int LOG = (int)(20);

int n, m, k, wh;
string ans, str, s[N];

void f(int x, int y) {
	if(x == m + 1)
		return;
	lli pw = 1;
	bool fl = false;
	int to = 0;
	for(int i = 1; i <= m - x; i++) {
		pw *= k;
		if(pw > y) {
			fl = true;
			break;
		}
	}
	if(!fl)
		to = y / pw;
	ans.pb(s[x][to]);
	f(x + 1, y - to * pw);
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	cin >> n >> m >> k >> wh;
	wh--;
	cin >> str;
	for(int i = 1; i <= m; i++) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	f(1, wh);

	int ind = 0;
	for(int i = 0; i < n; i++) {
		if(str[i] == '#')
			cout << ans[ind++];
		else
			cout << str[i];
	}
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 31608 KB Output is correct
2 Correct 29 ms 31608 KB Output is correct
3 Correct 28 ms 31608 KB Output is correct
4 Correct 30 ms 31608 KB Output is correct
5 Correct 28 ms 31608 KB Output is correct
6 Correct 28 ms 31612 KB Output is correct
7 Correct 29 ms 31736 KB Output is correct
8 Correct 28 ms 31636 KB Output is correct
9 Correct 29 ms 31608 KB Output is correct
10 Correct 28 ms 31608 KB Output is correct