Submission #208867

# Submission time Handle Problem Language Result Execution time Memory
208867 2020-03-12T11:15:05 Z Sensei Tavan (COCI16_tavan) C++14
80 / 80
5 ms 504 KB
/*
	DATE:		2020-03-12 14:04:45
	NAME:		
	PROBLEM:	COCI16_TAVAN
*/
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 500;

string st;

set<char> s[MAXN + 7];

long long suffe[MAXN + 7];

string dfs(int i, int mi, int x) {
  if (i >= st.size()) {
    return "";
  }
  if (st[i] != '#') {
    return st[i] + dfs(i + 1, mi, x);
  }
  for (set<char>::iterator it = s[mi].begin(); it != s[mi].end(); it++) {
    if (suffe[mi - 1] < x) {
      x -= suffe[mi - 1];
      continue;
    }
    else {
      return *it + dfs(i + 1, mi - 1, x);
    }
  }
}

int main() {
  int n, m, k, x;
  cin >> n >> m >> k >> x;

  cin >> st;
  st.insert(st.begin(), '#');

  for (int i = m; i >= 1; i--) {
    string temp;
    cin >> temp;
    for (int j = 0; j < temp.size(); j++) {
      s[i].insert(temp[j]);
    }
  }

  suffe[0] = 1;

  for (int i = 1; i <= m; i++) {
    suffe[i] = suffe[i - 1] * s[i].size();
    if (suffe[i] > x) {
      suffe[i] = x + 1;
    }
  }

  cout << dfs(1, m, x) << "\n";

  return 0;
}

Compilation message

tavan.cpp: In function 'std::__cxx11::string dfs(int, int, int)':
tavan.cpp:19:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (i >= st.size()) {
       ~~^~~~~~~~~~~~
tavan.cpp: In function 'int main()':
tavan.cpp:46:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int j = 0; j < temp.size(); j++) {
                     ~~^~~~~~~~~~~~~
tavan.cpp: In function 'std::__cxx11::string dfs(int, int, int)':
tavan.cpp:34:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 504 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct