/*
Saturday /\
May 7th, 2022 //\\
03:15 AM ///\\\
07/05/2022 //\\
UTC +07 ///\\\
////\\\\
///\\\
////\\\\
/////\\\\\
||
|| The tree
______||__________
*/
#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);
}
};
// freopen("input.INP", "r", stdin);
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:85:22: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
85 | for (const auto& [t, x] : result)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 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 |
472 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
1240 KB |
Output is correct |
7 |
Correct |
3 ms |
3028 KB |
Output is correct |
8 |
Correct |
7 ms |
6840 KB |
Output is correct |
9 |
Correct |
11 ms |
10328 KB |
Output is correct |
10 |
Correct |
16 ms |
14084 KB |
Output is correct |