/**
* author: wxhtzdy
* created: 11.08.2022 20:41:13
**/
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<string> s(10);
for (int i = 0; i < 10; i++) {
cin >> s[i];
}
vector<vector<bool>> was(10, vector<bool>(n));
vector<vector<pair<int, int>>> prv(10, vector<pair<int, int>>(n));
vector<pair<int, int>> que;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < n; j++) {
if (j == n - 1 && s[i][j] == '.') {
was[i][j] = true;
que.emplace_back(i, j);
}
}
}
for (int b = 0; b < (int) que.size(); b++) {
int x = que[b].first;
int y = que[b].second;
if (x > 0 && y > 0 && !was[x - 1][y - 1] && s[x - 1][y - 1] == '.') {
was[x - 1][y - 1] = true;
prv[x - 1][y - 1] = make_pair(x, y);
que.emplace_back(x - 1, y - 1);
}
if (x < 9 && y > 0 && !was[x + 1][y - 1] && s[x + 1][y - 1] == '.') {
was[x + 1][y - 1] = true;
prv[x + 1][y - 1] = make_pair(x, y);
que.emplace_back(x + 1, y - 1);
}
if (x == 9 && y > 0 && !was[x][y - 1] && s[x][y - 1] == '.') {
was[x][y - 1] = true;
prv[x][y - 1] = make_pair(x, y);
que.emplace_back(x, y - 1);
}
if (x == 0 && y > 0 && !was[x][y - 1] && s[x][y - 1] == '.') {
was[x][y - 1] = true;
prv[x][y - 1] = make_pair(x, y);
que.emplace_back(x, y - 1);
}
}
if (n == 1) {
cout << 0 << '\n';
return 0;
}
vector<pair<int, int>> cells;
int x = 9, y = 0;
while (y < n - 1) {
cells.emplace_back(x, y);
auto p = prv[x][y];
x = p.first;
y = p.second;
}
vector<pair<int, int>> ans;
for (int i = 0; i < (int) cells.size() - 1; i++) {
if (cells[i].first > cells[i + 1].first || (cells[i].first == cells[i + 1].first && cells[i].second == 0)) {
ans.emplace_back(cells[i].second, 1);
}
}
vector<pair<int, int>> nans;
for (int i = 0; i < (int) ans.size(); i++) {
int ptr = i;
while (ptr + 1 < (int) ans.size() && ans[ptr + 1].first == ans[ptr].first + 1) {
ptr += 1;
}
nans.emplace_back(ans[i].first, ptr - i + 1);
i = ptr;
}
//swap(ans, nans);
cout << (int) ans.size() << '\n';
for (int i = 0; i < (int) ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Crashed with an obstacle |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Incorrect |
1 ms |
468 KB |
Crashed with an obstacle |
5 |
Incorrect |
3 ms |
1360 KB |
Crashed with an obstacle |
6 |
Incorrect |
3 ms |
1524 KB |
Crashed with an obstacle |
7 |
Incorrect |
8 ms |
3448 KB |
Crashed with an obstacle |
8 |
Incorrect |
20 ms |
9176 KB |
Crashed with an obstacle |
9 |
Incorrect |
32 ms |
11824 KB |
Crashed with an obstacle |
10 |
Incorrect |
27 ms |
14412 KB |
Crashed with an obstacle |