Submission #98260

# Submission time Handle Problem Language Result Execution time Memory
98260 2019-02-21T17:44:35 Z dalgerok Jetpack (COCI16_jetpack) C++17
80 / 80
44 ms 15096 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e5 + 5;



int n = 10, m;
char a[11][N];
int d[11][N];
pair < int, int > p[11][N];

inline bool check(int x, int y){
    return 1 <= x && x <= n && 1 <= y && y <= m && a[x][y] == '.';
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> m;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            cin >> a[i][j];
        }
    }
    memset(d, -1, sizeof(d));
    queue < pair < int, int > > q;
    q.push(make_pair(n, 1));
    d[n][1] = 0;
    while(!q.empty()){
        int x = q.front().first,
            y = q.front().second;
        q.pop();
        if(check(x - 1, y + 1) && d[x - 1][y + 1] == -1){
            d[x - 1][y + 1] = d[x][y] + 1;
            p[x - 1][y + 1] = make_pair(x, y);
            q.push(make_pair(x - 1, y + 1));
        }
        if(check(x + 1, y + 1) && d[x + 1][y + 1] == -1){
            d[x + 1][y + 1] = d[x][y] + 1;
            p[x + 1][y + 1] = make_pair(x, y);
            q.push(make_pair(x + 1, y + 1));
        }
        if((x == n || x == 1) && check(x, y + 1) && d[x][y + 1] == -1){
            d[x][y + 1] = d[x][y] + 1;
            p[x][y + 1] = make_pair(x, y);
            q.push(make_pair(x, y + 1));
        }
    }
    for(int i = 1; i <= n; i++){
        if(d[i][m] != -1){
            int cur = 0, x = i, y = m;
            vector < pair < int, int > > ans;
            for(int j = d[i][m]; j >= 0; j--){
                int xx = p[x][y].first,
                    yy = p[x][y].second;
                if(xx - 1 == x && yy + 1 == y || (xx == x && x == 1)){
                    cur += 1;
                }
                else{
                    if(cur){
                        ans.push_back(make_pair(j, cur));
                    }
                    cur = 0;
                }
                a[x][y] = '#';
                x = xx;
                y = yy;
            }
            cout << (int)ans.size() << "\n";
            reverse(ans.begin(), ans.end());
            for(auto it : ans){
                cout << it.first << " " << it.second << "\n";
            }
            return 0;
        }
    }
}

Compilation message

jetpack.cpp: In function 'int main()':
jetpack.cpp:57:32: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
                 if(xx - 1 == x && yy + 1 == y || (xx == x && x == 1)){
                    ~~~~~~~~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 4864 KB Output is correct
2 Correct 6 ms 4736 KB Output is correct
3 Correct 6 ms 4736 KB Output is correct
4 Correct 7 ms 4864 KB Output is correct
5 Correct 8 ms 5248 KB Output is correct
6 Correct 9 ms 5504 KB Output is correct
7 Correct 15 ms 6784 KB Output is correct
8 Correct 25 ms 9728 KB Output is correct
9 Correct 37 ms 12288 KB Output is correct
10 Correct 44 ms 15096 KB Output is correct