Submission #17854

# Submission time Handle Problem Language Result Execution time Memory
17854 2016-01-12T13:39:46 Z Adilkhan K-th path (IZhO11_kthpath) C++
0 / 100
1183 ms 262144 KB
#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];

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, "");
	sort(all(v));
	cout << v[k - 1];
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2024 KB Output is correct
2 Correct 0 ms 2024 KB Output is correct
3 Correct 0 ms 2164 KB Output is correct
4 Correct 756 ms 100312 KB Output is correct
5 Correct 0 ms 2296 KB Output is correct
6 Correct 693 ms 100312 KB Output is correct
7 Memory limit exceeded 1183 ms 262144 KB Memory limit exceeded
8 Halted 0 ms 0 KB -