Submission #654786

#TimeUsernameProblemLanguageResultExecution timeMemory
654786longvuJetpack (COCI16_jetpack)C++14
80 / 80
35 ms16728 KiB
/** * 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)

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) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...