#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
// author : AtabeyR
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sec second
#define fi first
#define int ll
#define print(k) cerr << "Ans : "; cout << k << endl;
#define ins insert
#define bpc __builtin_popcountll
#define skip continue
#define endll "\n"
#define li 2*ind+1
#define ri 2*ind+2
#define lb lower_bound
#define ub upper_bound
typedef long long ll;
typedef unsigned long long ull;
const int oo = 0x3F3F3F3F;
const int ooo = 0x3F3F3F3F3F3F3F3FLL;
const int mod = 998244353;
const int sz = 1e5+6;
using namespace std;
using namespace __gnu_pbds;
template<class T> using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
int lcm(int a, int b)
{
return a*b / (__gcd(a, b));
}
int gcd(int a, int b)
{
return __gcd(a, b);
}
int n, m, k, a[sz];
string s[sz];
void f(int i, int j, string k, vector<string> &res)
{
if(i == n-1 && j == m-1) res.pb(k);
if(i + 1 < n)f(i+1, j, k + s[i+1][j], res);
if(j + 1 < m)f(i, j+1, k + s[i][j+1], res);
}
void dont(int balls)
{
cin >> n >> m;
for(int i = 0 ; i<n; i++)cin >> s[i];
cin >> k;
vector<string> v;
string st = "";
st.pb(s[0][0]);
f(0, 0, st, v);
sort(all(v));
cout << v[k-1] << endll;
}
int32_t main()
{
// freopen("i.txt", "r", stdin);
// freopen("o.txt", "w", stdout);
OPT
int t = 1;
//cin >> t;
for(int i = 1; i<=t; i++)
dont(i);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3420 KB |
Output is correct |
2 |
Correct |
1 ms |
3420 KB |
Output is correct |
3 |
Correct |
1 ms |
3420 KB |
Output is correct |
4 |
Correct |
359 ms |
69024 KB |
Output is correct |
5 |
Correct |
2 ms |
3676 KB |
Output is correct |
6 |
Correct |
324 ms |
61864 KB |
Output is correct |
7 |
Runtime error |
950 ms |
262144 KB |
Execution killed with signal 9 |
8 |
Halted |
0 ms |
0 KB |
- |