Submission #94140

#TimeUsernameProblemLanguageResultExecution timeMemory
94140MrTEKTavan (COCI16_tavan)C++14
40 / 80
2 ms504 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int,int> ii; const int N = 5e3 + 5; string s,ans,t[N]; int n,m,k,x; bool ok[N]; ll suff[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m >> k >> x >> s; for (int i = 1 ; i <= m ; i++) { cin >> t[i]; sort(t[i].begin(),t[i].end()); t[i].resize(unique(t[i].begin(),t[i].end()) - t[i].begin()); } suff[m + 1] = 1; for (int i = m ; i >= 1 ; i--) { suff[i] = suff[i + 1] * t[i].size(); if (ok[i + 1] || suff[i] > x) ok[i] = true; // cerr << i << ' ' << t[i] << ' ' << suff[i] << "\n"; } int lst = 0; for (int i = 0 ; i < n ; i++) { if (s[i] == '#') { lst++; int p = 0; while(!ok[i + 1] && p < t[lst].size() && suff[lst + 1] < x) { x -= suff[lst + 1]; p++; } // cerr << "anan " << x << ' ' << p << "\n"; ans.push_back(t[lst][p]); } else ans.push_back(s[i]); } cout << ans << endl; }

Compilation message (stderr)

tavan.cpp: In function 'int main()':
tavan.cpp:36:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       while(!ok[i + 1] && p < t[lst].size() && suff[lst + 1] < x) {
                           ~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...