#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=101;
const ll inf=2e18;
int n,m;
ll dp[maxN+1][maxN+1],k,comb[maxN+1][maxN+1];
char c[maxN+1][maxN+1];
vector<pii> v[26];
string s;
int main()
{
//freopen("","r",stdin);
//freopen("","w",stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>c[i][j];
}
}
cin>>k;
for(int i=0;i<=60;i++)
{
comb[0][i]=1;
}
for(int i=1;i<=60;i++)
{
for(int j=i;j<=60;j++)
{
if(i==j)
{
comb[i][j]=1;
}
else comb[i][j]=comb[i-1][j-1]+comb[i][j-1];
}
}
s+=c[1][1];
dp[1][1]=1;
for(int st=2;st<=n+m-1;st++)
{
ll res=0,cur=0;
for(int ch=0;ch<26;ch++)
{
for(int i=1;i<=st;i++)
{
int j=st+1-i;
if(c[i][j]-'a'==ch)
{
dp[i][j]=dp[i-1][j]+dp[i][j-1];
res+=(dp[i][j]*comb[n-i][n-i+m-j]);
}
else dp[i][j]=0;
}
if(res>=k)
{
s+=(char)(ch+'a');
k-=cur;
break;
}
cur=res;
}
}
cout<<s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |