Submission #159701

# Submission time Handle Problem Language Result Execution time Memory
159701 2019-10-24T02:17:03 Z silxikys Jetpack (COCI16_jetpack) C++14
80 / 80
36 ms 4088 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int N = 1e5+5;
char grid[10][N];
int n;
bool poss[10][N];

int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < n; j++) {
            cin >> grid[i][j];
        }
    }
    poss[9][0] = true;
    for (int j = 1; j < n; j++) {
        for (int i = 0; i < 10; i++) {
            if (grid[i][j] == 'X') continue;
            poss[i][j] |= poss[max(0,i-1)][j-1];
            poss[i][j] |= poss[min(9,i+1)][j-1];
        }
    }
    for (int j = n-2; j >= 0; j--) {
        for (int i = 0; i < 10; i++) {
            if (grid[i][j] == 'X') continue;
            bool p = false;
            p |= poss[max(0,i-1)][j+1];
            p |= poss[min(9,i+1)][j+1];
            poss[i][j] &= p;
        }
    }
    /*
    for (int i = 0; i < 10; i++) {
        for (int j = 0; j < n; j++) {
            cout << poss[i][j] << ' ';
        }
        cout << '\n';
    }
    */
    vector<int> pos(n,0);
    pos[0] = 9;
    for (int j = 1; j < n; j++) {
        int pr = pos[j-1];
        if (poss[min(9,pr+1)][j]) 
            pos[j] = min(9,pr+1);
        else if (poss[max(0,pr-1)][j])
            pos[j] = max(0,pr-1);
        else assert(false);
        //cout << j << ": " << pos[j] << endl;
    }
    vector<pair<int,int>> ans;
    pair<int,int> curr = {-1,-1};
    for (int j = 0; j < n-1; j++) {
        if (pos[j+1] == pos[j] - 1 || pos[j] == 0 && pos[j+1] == 0) {
            if (curr.first == -1) {
                curr = {j,1};
            }
            else {
                curr.second++;
            }
        }
        else {
            if (curr.first != -1) {
                ans.push_back(curr);
            }
            curr = {-1,-1};
        }
    }
    if (curr.first != -1) {
        ans.push_back(curr);
    }
    //output
    cout << ans.size() << '\n';
    for (auto p: ans) {
        cout << p.first << ' ' << p.second << '\n';
    }
}

Compilation message

jetpack.cpp: In function 'int main()':
jetpack.cpp:57:51: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
         if (pos[j+1] == pos[j] - 1 || pos[j] == 0 && pos[j+1] == 0) {
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 3 ms 508 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 8 ms 1144 KB Output is correct
8 Correct 16 ms 2168 KB Output is correct
9 Correct 24 ms 3064 KB Output is correct
10 Correct 36 ms 4088 KB Output is correct