Contest Duration: - (local time) (100 minutes) Back to Home

Submission #6578827

Source Code Expand

Copy
```#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;

ll sgn(ll x) {
if (x > 0) return 1;
if (x < 0) return -1;
return 0;
}

int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
ll K, X, Y; cin >> K >> X >> Y;
const ll INF = 1e18;
auto f = [&](ll x, ll y) -> tuple<ll, vector<pair<ll, ll>>> {
if ((abs(X - x) + abs(Y - y)) % K != 0) return {INF, {}};
return {1 + (abs(X - x) + abs(Y - y)) / K, {{x, y}}};
};
auto g = [&](ll x, ll y, ll a, ll b) -> tuple<ll, vector<pair<ll, ll>>> {
if ((abs(X - x - a) + abs(Y - y - b)) % K != 0) return {INF, {}};
return {2 + (abs(X - x - a) + abs(Y - y - b)) / K, {{x, y}, {a, b}}};
};
tuple<ll, vector<pair<ll, ll>>> cand(INF, {});
for (ll i = 0; i < K; i++) {
ll x = i;
ll y = K - i;
cand = min(cand, f(x, y));
cand = min(cand, f(-x, y));
cand = min(cand, f(x, -y));
cand = min(cand, f(-x, -y));
}
if (get<0>(cand) == INF) {
const ll xx[] = {K, 0, -K, 0};
const ll yy[] = {0, K, 0, -K};
rep(k, 4) {
for (ll i = 0; i < K; i++) {
ll x = i;
ll y = K - i;
cand = min(cand, g(x, y, xx[k], yy[k]));
cand = min(cand, g(-x, y, xx[k], yy[k]));
cand = min(cand, g(x, -y, xx[k], yy[k]));
cand = min(cand, g(-x, -y, xx[k], yy[k]));
}
}
if (get<0>(cand) == INF) {
cout << -1 << endl;
return 0;
}
}
ll cnt = get<0>(cand);
cout << cnt << endl;
ll x = 0, y = 0;
for (auto p : get<1>(cand)) {
x += p.first;
y += p.second;
cout << x << ' ' << y << '\n';
}
while (abs(X - x) > 0 || abs(Y - y) > 0) {
ll dx = min(K, abs(X - x));
ll dy = min(K - dx, abs(Y - y));
x += dx * sgn(X - x);
y += dy * sgn(Y - y);
cout << x << ' ' << y << '\n';
}
}```

Submission Info

Submission Time 2019-07-27 22:13:17+0900 E - Golf pekempey C++14 (GCC 5.4.1) 0 1963 Byte CE

Compile Error

```./Main.cpp: In lambda function:
./Main.cpp:20:60: error: converting to ‘std::tuple<long long int, std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >’ from initializer list would use explicit constructor ‘constexpr std::tuple<_T1, _T2>::tuple(const _T1&, const _T2&) [with _T1 = long long int; _T2 = std::vector<std::pair<long long int, long long int> >]’
if ((abs(X - x) + abs(Y - y)) % K != 0) return {INF, {}};
^
./Main.cpp:21:56: error: converting to ‘std::tuple<long long int, std::vector<std::pair<long long int, long long int>, std::allocator<std::pair<long long int, long long int> > > >’ from initializer list would use explicit constructor ‘constexpr std::tuple<_T1, _T2>::tuple(const _T1&, const _T2&) [with _T1 = long long int; _T2 = std::vector<std::pair<long long int, long long int> >]’
return {1 + (abs(X - x) + abs(Y - y)) / K, {{x, y}}};
...```