| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 396261 | srvlt | K번째 경로 (IZhO11_kthpath) | C++17 | 17 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... | ||||
