Submission #359078

# Submission time Handle Problem Language Result Execution time Memory
359078 2021-01-26T10:23:03 Z jesus_coconut Tower Defense (CEOI19_towerdefense) C++17
25 / 100
1 ms 364 KB
#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 || (d == 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 time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 0 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Incorrect 1 ms 364 KB Expected but did not find "impossible".
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 0 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 ms 364 KB Output is correct
10 Correct 0 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 0 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 0 ms 364 KB Output is correct
18 Correct 0 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Incorrect 1 ms 364 KB Expected but did not find "impossible".
22 Halted 0 ms 0 KB -