Submission #595726

# Submission time Handle Problem Language Result Execution time Memory
595726 2022-07-14T03:50:08 Z nguyen31hoang08minh2003 Jetpack (COCI16_jetpack) C++14
80 / 80
15 ms 14024 KB
/*
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /
 \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/
 /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \
/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \
\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /
 \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /
 /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\
/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /
 \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/
  \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /    \  /
   \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/      \/
   /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\      /\
  /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \    /  \
 /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\  /\
/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \/  \
/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\
\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/

*/
#include <bits/stdc++.h>
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) int((x).size())

template<class A, class B>
bool minimize(A &a, const B& b) {
    return a <= b ? false : (a = b, true);
}

template<class A, class B>
bool maximize(A &a, const B& b) {
    return a >= b ? false : (a = b, true);
}

template<class X, class Y>
std::ostream& operator << (std::ostream& outputStream, const std::pair<X, Y> &p) {
    return outputStream << '{' << p.first << ", " << p.second >> '}';
}

template<class T>
std::ostream& operator << (std::ostream& outputStream, const std::vector<T>& values) {
    outputStream << '{';
    for (const T& value : values)
        outputStream << value << ' ';
    return outputStream << '}';
}

using namespace std;

const int ROWS = 10, MAX_N = 1e5 + 5;

signed main() {
    int n;
    string field[ROWS];
    vector<pair<int, int> > result;
    const function<bool(int, int)> DP = [&](const int x, const int y) -> bool {
        static bool seen[ROWS][MAX_N]{}, dp[ROWS][MAX_N]{};
        if (y >= n)
            return true;
        if (x < 0 || x >= ROWS || field[x][y] == 'X')
            return false;
        if (!seen[x][y]) {
            seen[x][y] = true;
            dp[x][y] = DP(max(0, x - 1), y + 1) || DP(min(x + 1, ROWS - 1), y + 1);
        }
        return dp[x][y];
    };
    const function<void(int, int, int)> trace = [&](const int x, const int y, const int z) {
        if (y >= n) {
            if (z)
                result.emplace_back(y - z, z);
            return;
        }
        if (DP(max(0, x - 1), y + 1))
            trace(max(0, x - 1), y + 1, z + 1);
        else {
            if (z)
                result.emplace_back(y - z, z);
            trace(min(x + 1, ROWS - 1), y + 1, 0);
        }
    };
    cin.tie(0) -> sync_with_stdio(0);
    cout.tie(0);
    cin >> n;
    for (int x = 0; x < ROWS; ++x)
        cin >> field[x];
    trace(ROWS - 1, 0, 0);
    cout << result.size() << '\n';
    for (const auto& [t, x] : result)
        cout << t << ' ' << x << '\n';
    return 0;
}

Compilation message

jetpack.cpp: In function 'int main()':
jetpack.cpp:94:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   94 |     for (const auto& [t, x] : result)
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 984 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 3 ms 3028 KB Output is correct
8 Correct 7 ms 6908 KB Output is correct
9 Correct 10 ms 10264 KB Output is correct
10 Correct 15 ms 14024 KB Output is correct