#include <bits/stdc++.h>
#define pb push_back
#define endl "\n"
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define fname ""
#define sz(x) (int)(x.size())
typedef long long ll;
using namespace std;
const ll N = (ll)(5e5) + 322;
const ll INF = (ll)(1e9);
const ll mod = (ll)(1e9) + 7;
const double eps = 1e-9;
int n, m, k;
vector <string> v;
char ch[33][33];
string s;
void dfs(int x, int y, string &s) {
s += ch[x][y];
if (x == n && y == m) {
v.pb(s);
return;
}
if (x + 1 <= n)
dfs(x + 1, y, s);
if (y + 1 <= m)
dfs(x, y + 1, s);
}
int main () {
//freopen(fname".in", "r", stdin);
//freopen(fname".out", "w", stdout);
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= m; ++j) {
cin >> ch[i][j];
}
}
cin >> k;
dfs(1, 1, s);
sort(all(v));
cout << v[k - 1];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2024 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2024 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |