Submission #94145

# Submission time Handle Problem Language Result Execution time Memory
94145 2019-01-16T11:43:34 Z MrTEK Tavan (COCI16_tavan) C++14
80 / 80
2 ms 504 KB
#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;
  }
  int lst = 0;
  for (int i = 0 ; i < n ; i++) {
    if (s[i] == '#') {
      lst++;
      int p = 0;
      while(!ok[lst + 1] && p < t[lst].size() && suff[lst + 1] < x) {
        x -= suff[lst + 1];
        p++;
      }
      ans.push_back(t[lst][p]);
    }
    else
      ans.push_back(s[i]);
  }
  cout << ans << endl;
}

Compilation message

tavan.cpp: In function 'int main()':
tavan.cpp:35:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       while(!ok[lst + 1] && p < t[lst].size() && suff[lst + 1] < x) {
                             ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 2 ms 504 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 504 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct