Submission #98260

#TimeUsernameProblemLanguageResultExecution timeMemory
98260dalgerokJetpack (COCI16_jetpack)C++17
80 / 80
44 ms15096 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...