Submission #747535

# Submission time Handle Problem Language Result Execution time Memory
747535 2023-05-24T09:36:26 Z saayan007 Journey (NOI18_journey) C++17
100 / 100
143 ms 10848 KB
#include "bits/stdc++.h"
using namespace std;

#define int long long
#define fr first
#define sc second
#define eb emplace_back
#define nl '\n'

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");} 
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif

const int inf = 5e8L + 1;
signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int N, M, H;
    cin >> N >> M >> H;
    pair<int, int> adj[N][H];
    for(int i = 0; i < N - 1; ++i) {
        for(int j = 0; j < H; ++j) {
            cin >> adj[i][j].fr >> adj[i][j].sc;
        }
    }

    /* for(int i = 0; i < N - 1; ++i) { */
    /*     for(int j = 0; j < H; ++j) { */
    /*         cout << adj[i][j].fr << ' ' << adj[i][j].sc << ' '; */
    /*     } */
    /*     cout << nl; */
    /* } */

    int res[N][M] = {};
    res[0][0] = 1;
    for(int i = 0; i < N - 1; ++i) {
        for(int j = 0; j < M; ++j) {
            if(i != 0 && j != 0) res[i][j] += res[i][j - 1];
            if(res[i][j] >= inf) res[i][j] = inf;
            for(int k = 0; k < H; ++k) {
                if(j + adj[i][k].sc < M && adj[i][k].fr > i) {
                    res[adj[i][k].fr][j + adj[i][k].sc] += res[i][j];
                    if(res[adj[i][k].fr][j + adj[i][k].sc] >= inf) res[adj[i][k].fr][j + adj[i][k].sc] = inf;
                }
            }
        }
    }
    for(int i = 0; i < M; ++i) {
        if(i != 0) res[N - 1][i] += res[N - 1][i - 1];
        if(res[N - 1][i] >= inf) res[N - 1][i] = inf;
        cout << res[N - 1][i] << ' ';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory 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 2 ms 440 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
# Verdict Execution time Memory 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 2 ms 440 KB Output is correct
6 Correct 2 ms 328 KB Output is correct
7 Correct 54 ms 7792 KB Output is correct
8 Correct 88 ms 10848 KB Output is correct
9 Correct 32 ms 3284 KB Output is correct
10 Correct 143 ms 4576 KB Output is correct