/*
www.youtube.com/YugiHackerChannel
oj.vnoi.info/user/YugiHackerKhongCopCode
*/
#include<bits/stdc++.h>
#define el cout<<"\n"
#define f0(i,n) for(int i=0;i<n;++i)
#define f1(i,n) for(int i=1;i<=n;++i)
#define maxn 100005
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
int n, d[12][maxn], r;
char a[12][maxn];
queue <pii> q;
main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
f1 (i, 10) f1 (j, n) cin >> a[i][j];
q.push({10, 1});
while (q.size())
{
int u = q.front().fi, v = q.front().se;
if (v == n) r = u;
q.pop();
int u_up = max(1, u-1);
int u_down = min(10, u+1);
if (a[u_up][v+1] == '.' && d[u_up][v+1] == 0)
{
q.push({u_up, v+1});
d[u_up][v+1] = u;
}
if (a[u_down][v+1] == '.' && d[u_down][v+1] == 0)
{
q.push({u_down, v+1});
d[u_down][v+1] = u;
}
}
//f1 (i, 10) {f1 (j, n) if (d[i][j]) cout << '*'; else cout << '.'; el;}
vector <pii> ans;
for (int i=n; i; i--)
{
int cnt = 0;
//cout << r << ' ' << i, el;
while (d[r][i] == r+1 || (r == 1 && d[r][i] == 1))
{
++cnt;
r = d[r][i];
//cout << r << ' ' << i, el;
i--;
}
if (cnt) ans.push_back({i-1, cnt});
r = d[r][i];
}
reverse(ans.begin(), ans.end());
cout << ans.size(), el;
for (auto p:ans) cout << p.fi << ' ' << p.se, el;
}
Compilation message
jetpack.cpp:17:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
17 | main()
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
388 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
2 ms |
596 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
6 ms |
1492 KB |
Output is correct |
8 |
Correct |
14 ms |
3312 KB |
Output is correct |
9 |
Correct |
22 ms |
4756 KB |
Output is correct |
10 |
Correct |
28 ms |
6612 KB |
Output is correct |