# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
42119 | wasyl | Jetpack (COCI16_jetpack) | C++11 | 26 ms | 4756 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>
#ifndef dbg
#define dbg(...)
#endif
#define all(x) begin(x), end(x)
#define rsz(...) resize(__VA_ARGS__)
#define psh(...) push_back(__VA_ARGS__)
#define emp(...) emplace_back(__VA_ARGS__)
#define prt(...) print(cout, __VA_ARGS__)
#define dprt(...) dbg(print(cerr,__VA_ARGS__))
#define dmp(...) dprt(#__VA_ARGS__, '=', __VA_ARGS__)
using namespace std;using ll=long long;
template<typename t>using V=vector<t>;
template<typename t>void print(ostream& os, const t& a){os<<a<<'\n';}
template<typename t, typename... A>void print
(ostream& os, const t& a, A&&... b){os<<a<<' ';print(os, b...);}
int n;
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
V< V< bool > > rt(10, V< bool >(n));
V< V< bool > > tb(10, V< bool >(n));
for (int i = 9; i >= 0; --i)
{
string s; cin >> s;
for (int k = 0; k < n; ++k)
tb[i][k] = s[k] == '.';
}
queue< pair< int, int > > Q;
rt[0][0] = true;
Q.push({0, 0});
while (!Q.empty())
{
auto p = Q.front(); Q.pop();
// dprt(p.first, p.second);
if (p.second == n - 1)
continue;
if (p.first > 0 and rt[p.first - 1][p.second + 1] == false and
tb[p.first - 1][p.second + 1] == true)
{
rt[p.first - 1][p.second + 1] = true;
Q.push({p.first - 1, p.second + 1});
}
if (p.first < 9 and rt[p.first + 1][p.second + 1] == false and
tb[p.first + 1][p.second + 1] == true)
{
rt[p.first + 1][p.second + 1] = true;
Q.push({p.first + 1, p.second + 1});
}
if ((p.first == 0 or p.first == 9)
and rt[p.first][p.second + 1] == false and
tb[p.first][p.second + 1] == true)
{
rt[p.first][p.second + 1] = true;
Q.push({p.first, p.second + 1});
}
}
dbg(
for (int i = 9; i >= 0; --i)
{
for (int k = 0; k < n; ++k)
cerr << (rt[i][k]);
cerr << '\n';
}
);
int x = 0, y = n - 1;
while (rt[x][y] == false)
++x;
dmp(x, y);
V< pair< int, int > > ph;
ph.psh({x, y});
while (x != 0 or y != 0)
{
if (x > 0 and rt[x - 1][y - 1])
{
ph.psh({x - 1, y - 1});
--x, --y;
}
else if (x < 9 and rt[x + 1][y - 1])
{
ph.psh({x + 1, y - 1});
++x, --y;
}
else if ((x == 0 or x == 9) and rt[x][y - 1])
{
ph.psh({x, y - 1});
--y;
}
}
reverse(all(ph));
dbg(
for (auto& p : ph)
dprt(p.first, p.second);
);
V< pair< int, int > > odp;
for (int i = 0; i < ph.size(); ++i)
{
if (i < ph.size() - 1 and (ph[i].first < ph[i + 1].first or
(ph[i].first == 9 and ph[i + 1].first == 9)))
{
int pt = i + 1;
while (pt < ph.size() - 1 and
(ph[pt].first < ph[pt + 1].first or(ph[pt].first == 9 and
ph[pt + 1].first == 9)))
++pt;
odp.psh({i, pt - i});
i = pt;
}
}
prt(odp.size());
for (auto& p : odp)
prt(p.first, p.second);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |