# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
654786 | longvu | Jetpack (COCI16_jetpack) | C++14 | 35 ms | 16728 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
* author: longvu
* created: 11/01/22 09:56:51
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
const int INF = numeric_limits<int>::max();
const int naxn = (int)(12);
const int naxm = (int)(109001);
const int mod = 1e9 + 7;
template<class X, class Y>
bool maximize(X& x, const Y y) {
if (y > x) {x = y; return true;}
return false;
}
template<class X, class Y>
bool minimize(X& x, const Y y) {
if (y < x) {x = y; return true;}
return false;
}
#define Fi first
#define Se second
bitset<naxm> a[naxn], dp[naxn], ans;
pair<int, int> tr[naxn][naxm];
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= 10; ++i) {
for (int j = 1; j <= n; ++j) {
char c;
cin >> c;
a[i][j] = (c == 'X' ? 1 : 0);
}
}
dp[10][0] = 1;
for (int j = 0; j < n; ++j) {
if (dp[10][j] && !a[10][j + 1] && !dp[10][j + 1]) {
dp[10][j + 1] = 1;
tr[10][j + 1] = {10, 0};
}
if (dp[1][j] && !a[1][j + 1] && !dp[1][j + 1]) {
dp[1][j + 1] = 1;
tr[1][j + 1] = {1, 1};
}
if (!j) {
continue;
}
for (int i = 1; i <= 10; ++i) {
if (dp[i][j]) {
if (i < 10 && !a[i + 1][j + 1] && !dp[i + 1][j + 1]) {
dp[i + 1][j + 1] = 1;
tr[i + 1][j + 1] = {i, 0};
}
if (i > 1 && !a[i - 1][j + 1] && !dp[i - 1][j + 1]) {
dp[i - 1][j + 1] = 1;
tr[i - 1][j + 1] = {i, 1};
}
}
}
}
int i = 1, j = n;
for (int e = 1; e <= 10; ++e) {
if (dp[e][n]) {
i = e;
}
}
while (j) {
ans[j - 1] = tr[i][j].Se;
i = tr[i][j].Fi;
j--;
}
// for (int i = 0; i < n; ++i) {
// cout << ans[i] << " ";
// }
// cout << '\n';
vector<pair<int, int>> anstr;
for (int i = 1; i < n; ++i) {
if (ans[i]) {
int r = i;
while (r + 1 < n && ans[r + 1]) {
r++;
}
anstr.push_back({i - 1, r - i + 1});
i = r;
}
}
cout << sz(anstr) << '\n';
for (auto [x, y] : anstr) {
cout << x << " " << y << '\n';
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |