| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 883679 | heeheeheehaaw | K번째 경로 (IZhO11_kthpath) | C++17 | 0 ms | 348 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define int long long
using namespace std;
int comb[62][62];
int a[32][32];
bool visited[32][32];
string from[32][32];
int dx[] = {0, 1};
int dy[] = {1, 0};
int apare[32];
const int llm = 1000000000000000001;
int calc(int x, int y, int n, int m)
{
return comb[n - x + m - y][m - y];
}
signed main()
{
int n, m, k;
cin>>n>>m;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
{
char c;
cin>>c;
a[i][j] = (int)c - 'a' + 1;
}
cin>>k;
for(int i = 0; i <= 60; i++)
comb[i][0] = 1, comb[i][i] = 1;
for(int i = 1; i <= 60; i++)
for(int j = 1; j < i; j++)
{
if(comb[i - 1][j] + comb[i - 1][j - 1] >= llm)
comb[i][j] == llm;
else
comb[i][j] = comb[i - 1][j] + comb[i - 1][j - 1];
}
vector<pair<int, int>> v;
int curr = 0;
v.push_back({1, 1});
from[1][1] = "a";
while(!v.empty())
{
vector<pair<int, int>> aux;
for(int i = 1; i <= 26; i++)
apare[i] = 0;
for(auto it : v)
{
int x = it.first, y = it.second;
for(int dir = 0; dir < 2; dir++)
{
int nx = x + dx[dir];
int ny = y + dy[dir];
if(nx < 1 || nx > n || ny < 1 || ny > m || visited[nx][ny])
continue;
visited[nx][ny] = true;
apare[a[nx][ny]] += calc(nx, ny, n, m);
if(apare[a[nx][ny]] >= llm)
apare[a[nx][ny]] = llm;
aux.push_back({nx, ny});
}
}
for(auto it : aux)
visited[it.first][it.second] = false;
aux.clear();
int ch;
for(int i = 1; i <= 26; i++)
{
if(apare[i] != 0)
{
int newc = curr + apare[i];
if(k > curr && k <= newc)
{
ch = i;
break;
}
else
{
curr = newc;
}
}
}
for(auto it : v)
{
int x = it.first, y = it.second;
for(int dir = 0; dir < 2; dir++)
{
int nx = x + dx[dir];
int ny = y + dy[dir];
if(nx < 1 || nx > n || ny < 1 || ny > m || visited[nx][ny] || a[nx][ny] != ch)
continue;
visited[nx][ny] = true;
aux.push_back({nx, ny});
from[nx][ny] = from[x][y];
from[nx][ny].push_back((char)ch + 'a' - 1);
}
}
v = aux;
}
cout<<from[n][m];
return 0;
}
/**
3 4
abcd
efdg
hijk
4
*/
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
