Submission #162594

#TimeUsernameProblemLanguageResultExecution timeMemory
162594_qVp_Jetpack (COCI16_jetpack)C++14
80 / 80
39 ms12296 KiB
#include <bits/stdc++.h>

using namespace std;

const int md = 1e5 + 10;

bool vis[15][md][5];
string s[15];
int n;
int ans[md];

void print() {
    int len = (ans[1] == 1);
    /*for(int i = 1; i <= n; i++)
        cout << ans[i] << " ";
    cout << endl;*/
    for(int i = 2; i <= n; i++) {
        if (ans[i] && ans[i - 1])
            ans[i] += ans[i - 1];
        if (ans[i] == 1)
            len++;
    }
    cout << len << '\n';
    for(int i = 1; i <= n; i++) {
        if (ans[i] == 1)
            cout << i - 1 << " ";
        if (ans[i] != 0 && ans[i + 1] == 0)
            cout << ans[i] << '\n';
    }
    exit(0);
}

void dfs(int x, int y, int ss) {
    vis[x][y][ss] = true;
    //cout << x << " " << y << " " << ss << endl;
    if (y == n)
        print();
    if (x == 10) {
        if (s[x][y + 1] == '.' && !vis[x][y + 1][0]) {
            //ans[y] = 1;
            dfs(x, y + 1, 0);
        } if (s[x - 1][y + 1] == '.' && !vis[x - 1][y + 1][1]) {
            ans[y] = 1;
            dfs(x - 1, y + 1, 1);
            ans[y] = 0;
        }
    } else if (x == 1) {
        if (s[x][y + 1] == '.' && !vis[x][y + 1][1]) {
            ans[y] = 1;
            dfs(x, y + 1, 1);
            ans[y] = 0;
        }
        if (s[x + 1][y + 1] == '.' && !vis[x + 1][y + 1][0]) {
            dfs(x + 1, y + 1, 0);
        }
    } else {
        //up
        if (s[x - 1][y + 1] == '.' && !vis[x - 1][y + 1][1]) {
            ans[y] = 1;
            dfs(x - 1, y + 1, 1);
            ans[y] = 0;
        }
        //down
        if (s[x + 1][y + 1] == '.' && !vis[x + 1][y + 1][0]) 
            dfs(x + 1, y + 1, 0);
    }
}

int main() {
    //freopen("test.in", "r", stdin);
    ios_base::sync_with_stdio(0);
    cin >> n;
    //cout << n << endl;
    for(int i = 1; i <= 10; i++) {
        cin >> s[i];
    //    cout << s[i] << endl;
        s[i] = '#' + s[i];
    }
    //for(int i = 1; i <= 10; i++)
    //    cout << s[i] << endl;
    dfs(10, 1, 0);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...