답안 #654782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654782 2022-11-01T15:34:58 Z longvu Jetpack (COCI16_jetpack) C++14
72 / 80
45 ms 16776 KB
/**
 *    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 = 2; 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

jetpack.cpp: In function 'int32_t main()':
jetpack.cpp:98:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   98 |     for (auto [x, y] : anstr) {
      |               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Incorrect 1 ms 468 KB Crashed with an obstacle
4 Correct 1 ms 596 KB Output is correct
5 Correct 2 ms 1108 KB Output is correct
6 Correct 2 ms 1364 KB Output is correct
7 Correct 7 ms 3540 KB Output is correct
8 Correct 18 ms 8220 KB Output is correct
9 Correct 27 ms 12108 KB Output is correct
10 Correct 45 ms 16776 KB Output is correct