Submission #359077

#TimeUsernameProblemLanguageResultExecution timeMemory
359077jesus_coconutTower Defense (CEOI19_towerdefense)C++17
25 / 100
1 ms384 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; pii s, t; int d; void read() { cin >> s.first >> s.second; cin >> t.first >> t.second; cin >> d; } int dist(pii s, pii t) { return abs(s.first - t.first) + abs(s.second - t.second); } void solve() { read(); int dd = d - dist(s, t); if (dd == 0) { cout << 0 << '\n'; } else if (dd < 0 || dd % 2 || (dd == 2 && abs(s.first - t.first) == 1)) { cout << "impossible\n"; } else { vector<pair<int, int>> ans; if (abs(s.first - t.first) > 1) { int x = t.first + (s.first - t.first) / abs(s.first - t.first); for (int i = min(s.second, t.second); i <= max(s.second, t.second); ++i) { ans.emplace_back(x, i); } dd -= 2; int mn = min(s.second, t.second) - 1; int mx = max(s.second, t.second) + 1; while (dd > 0) { ans.emplace_back(x, mn); ans.emplace_back(x, mx); dd -= 2; --mn; ++mx; } } else { int y = t.second + (s.second - t.second) / abs(s.second - t.second); for (int i = min(s.first, t.first); i <= max(s.first, t.first); ++i) { ans.emplace_back(i, y); } dd -= 2; int mn = min(s.first, t.first) - 1; int mx = max(s.first, t.first) + 1; while (dd > 0) { ans.emplace_back(mn, y); ans.emplace_back(mx, y); dd -= 2; --mn; ++mx; } } cout << ans.size() << '\n'; for (auto &[a, b] : ans) cout << a << ' ' << b << '\n'; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...