답안 #656830

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
656830 2022-11-08T09:13:53 Z TheEvilBird K번째 경로 (IZhO11_kthpath) C++17
0 / 100
522 ms 262144 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
//typedef __int128_t int128;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const char en = '\n';
const int INF = 1e9 + 7;
const ll INFLL = 1e18;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

#ifdef __APPLE__
#include "debug.h"
//#define debug(...) 42
#else
#define debug(...) 42
#endif

const pii go[2] = {
        {1, 0},
        {0, 1}
};

int n, m;
vector<string> grid, s;
string cur;

bool in(int x, int y) {
    return 0 <= x && x < n && 0 <= y && y < m;
}

void dfs(int x, int y) {
    cur += grid[x][y];
    if (x == n - 1 && y == m - 1) {
        s.emplace_back(cur);
        return;
    }
    for (auto [dx, dy]: go) {
        int nx = x + dx, ny = y + dy;
        if (in(nx, ny)) {
            dfs(nx, ny);
            cur.pop_back();
        }
    }
}

void solve() {
    cin >> n >> m;
    grid.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> grid[i];
    }
    dfs(0, 0);
    sort(all(s));
    ll k;
    cin >> k;
    cout << s[k - 1] << en;
}

int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
#else
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 290 ms 64236 KB Output is correct
5 Correct 2 ms 468 KB Output is correct
6 Correct 256 ms 57856 KB Output is correct
7 Runtime error 522 ms 262144 KB Execution killed with signal 9
8 Halted 0 ms 0 KB -