답안 #635819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
635819 2022-08-27T04:42:15 Z zeroesandones Jump (BOI06_jump) C++17
100 / 100
28 ms 980 KB
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

#define FOR(i, j, k) for (ll i = j; i < (ll) k; ++i)
#define FORD(i, j, k) for (ll i = j; i >= (ll) k; --i)
#define nl "\n"
#define all(x) (x).begin(), (x).end()

#define sc second
#define fr first
#define pb push_back

string add(string a, string b) {
    if(a.length() < b.length()) swap(a, b);

    while(b.length() < a.length())
        b = "0" + b;

    string ans;
    int carry = 0;

    FORD(i, a.length() - 1, 0) {
        int c = (a[i] - '0') + (b[i] - '0') + carry;
        char num = (char) (c % 10 + (int)('0'));
        ans =  num + ans;
        carry = c / 10;
    }

    if(carry) {
        char num = (char) (carry + (int)('0'));
        ans = num + ans;
    }

    return ans;
}

void solve()
{
    int n;
    cin >> n;

    int a[n][n];
    FOR(i, 0, n){
        FOR(j, 0, n) {
            cin >> a[i][j];
        }
    }

    string dp[n][n] = {};
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            dp[i][j] = "0";
        }
    }
    dp[0][0] = "1";
    FOR(i, 0, n) {
        FOR(j, 0, n) {
            if(a[i][j] == 0)
                continue;
            if(i + a[i][j] < n)
                dp[i + a[i][j]][j] = add(dp[i][j], dp[i + a[i][j]][j]);
            if(j + a[i][j] < n)
                dp[i][j + a[i][j]] = add(dp[i][j], dp[i][j + a[i][j]]);
        }
    }

    // FOR(i, 0, n) {
        // FOR(j, 0, n){
            // cout << dp[i][j] << " ";
        // }
        // cout << nl;
    // }
    cout << dp[n - 1][n - 1] << nl;
}

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 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 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 4 ms 468 KB Output is correct
16 Correct 17 ms 724 KB Output is correct
17 Correct 8 ms 592 KB Output is correct
18 Correct 20 ms 800 KB Output is correct
19 Correct 14 ms 772 KB Output is correct
20 Correct 28 ms 980 KB Output is correct