| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 396261 | srvlt | K-th path (IZhO11_kthpath) | C++17 | 17 ms | 340 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) begin(x),end(x)
#define ld long double
#define SZ(x) (int)(x).size()
#define mem(x,y) memset(&x,y,sizeof(x))
using namespace std;
const int n0=33;
const ll inf=1e18+123;
int n,m;
char c[n0][n0],s[n0+n0];
void add(ll &x,ll y) {
	x=min(inf,x+y);
}
ll dp[n0][n0][2];
ll get() {
	mem(dp,0);
	if(c[1][1]<=s[1])
		dp[1][1][(c[1][1]<s[1])]=1;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			for(int k=0; k<2; k++) {
				if(k) {
					if(i<n) {
						add(dp[i+1][j][1],dp[i][j][1]);
					}
					if(j<m) {
						add(dp[i][j+1][1],dp[i][j][1]);
					}
				}	else {
					if(i<n && c[i+1][j]<=s[i+j]) {
						add(dp[i+1][j][(c[i+1][j]<s[i+j])],dp[i][j][0]);
					}
					if(j<m && c[i][j+1]<=s[i+j]) {
						add(dp[i][j+1][(c[i][j+1]<s[i+j])],dp[i][j][0]);
					}
				}
			}
		}
	}
	return dp[n][m][1];
}
int main() {
	ios_base::sync_with_stdio(0),cin.tie(0);
	cin >> n >> m;
	for(int i=1; i<=n; i++) {
		for(int j=1; j<=m; j++) {
			cin >> c[i][j];
		}
	}
	ll k;
	cin >> k;
	int len=n+m-1;
	for(int i=1; i<=len; i++) s[i]='$';
	for(int i=1; i<=len; i++) {
		int last=-1;
		for(int j=0; j<26; j++) {
			s[i]=char('a'+j);
			if(get()<k) last=j;
		}
		assert(last!=-1);
		s[i]=char('a'+last);
	}
	for(int i=1; i<=len; i++) cout << s[i];
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
