Submission #496003

# Submission time Handle Problem Language Result Execution time Memory
496003 2021-12-20T11:15:27 Z vulpes Jump (BOI06_jump) C++17
100 / 100
8 ms 1648 KB
#include <bits/stdc++.h>
using namespace std;

struct number {
    vector<int> a;
    number() {
        a = {0};
    }
    number operator+(const number &x) {
        number y; y.a.resize(max(x.a.size(), a.size()) + 1);
        for (int i = 0; i < max(x.a.size(), a.size()); i++) {
            int f = (i < x.a.size() ? x.a[i] : 0);
            int s = (i < a.size() ? a[i] : 0);
            y.a[i] += f + s;
            y.a[i + 1] += y.a[i] / 10;
            y.a[i] %= 10;
        }
        while (y.a.size() > 1 && !y.a.back()) {
            y.a.pop_back();
        }
        return y;
    }
};
void print(number x) {
    for (int i = x.a.size(); i; i--) {
        cout << x.a[i - 1];
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> a[i][j];
        }
    }
    vector<vector<number>> d(n, vector<number>(n));
    d[0][0].a = {1};
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n - (i == n - 1); j++) {
            if (i + a[i][j] < n) {
                d[i + a[i][j]][j] = d[i + a[i][j]][j] + d[i][j];
            }
            if (j + a[i][j] < n) {
                d[i][j + a[i][j]] = d[i][j + a[i][j]] + d[i][j];
            }
        }
    }
    print(d[n - 1][n - 1]);
    return cout << endl, 0;
}

Compilation message

jump.cpp: In member function 'number number::operator+(const number&)':
jump.cpp:11:27: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
   11 |         for (int i = 0; i < max(x.a.size(), a.size()); i++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
jump.cpp:12:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |             int f = (i < x.a.size() ? x.a[i] : 0);
      |                      ~~^~~~~~~~~~~~
jump.cpp:13:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |             int s = (i < a.size() ? a[i] : 0);
      |                      ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 312 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 316 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 316 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 572 KB Output is correct
16 Correct 4 ms 1100 KB Output is correct
17 Correct 5 ms 824 KB Output is correct
18 Correct 5 ms 1340 KB Output is correct
19 Correct 4 ms 1100 KB Output is correct
20 Correct 8 ms 1648 KB Output is correct