# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98260 | dalgerok | Jetpack (COCI16_jetpack) | C++17 | 44 ms | 15096 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |