답안 #752504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
752504 2023-06-03T05:49:18 Z AtabayRajabli K번째 경로 (IZhO11_kthpath) C++11
0 / 100
367 ms 262144 KB
#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
#define pll pair<ll, ll>
#define MAX 5e4 + 1
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define OPT ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define sec second
#define fi first
#define elif else if
#define print(k) cerr << "Ans : "; cout << k << endl;
#define int ll
#define ask(a, b) cout << "? " << a << " " << b << endl;
#define ins insert

typedef long long ll;
typedef unsigned long long ull;
const int oo = INT_MAX;
const int ooo = 0x3F3F3F3F3F3F3F3FLL;
const int mod = 301907;
using namespace std;

string c[35];
vector<vector<int>> wy(35, vector<int>(35));
vector<char> ans;
int a, b, k;

void solve()
{
    cin >> a >> b;

    for(int i = 0 ; i<a; i++)cin >> c[i];

    cin >> k;

    for(int i = 1; i<35; i++)
        for(int j = 1; j<35; j++)
            wy[i][j] = wy[i-1][j] + wy[i][j-1], wy[1][1] = 1;

    string ans(a+b-1, c[0][0]);
    vector<array<int, 2>> now = {{0, 0}}, temp;

    for(int j = 0; j<a+b-1; j++)
    {
        map<char, int> sum;

        for(auto &[x, y] : now)
            sum[c[x][y]] += wy[a-x][b-y];

        for(auto &[x, y] : sum)
        {
            ans[j] = x;
            if(y < k)k -= y;
            else break;
        }

        for(auto &[x, y] : now)
        {
            if(c[x][y] == ans[j])
            {
                if(x+1 <= a)
                {
                    temp.pb({x+1, y});
                }
                if(y+1 <= b)
                {
                    temp.pb({x, y+1});
                }
            }
        }

        now = temp;
        temp.clear();
    }


    cout << ans;
}

int32_t main()
{
    OPT

    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Compilation message

kthpath.cpp: In function 'void solve()':
kthpath.cpp:48:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   48 |         for(auto &[x, y] : now)
      |                   ^
kthpath.cpp:51:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |         for(auto &[x, y] : sum)
      |                   ^
kthpath.cpp:58:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   58 |         for(auto &[x, y] : now)
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Runtime error 367 ms 262144 KB Execution killed with signal 9
11 Halted 0 ms 0 KB -