Submission #6580125


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;
  using PS = vector<pair<ll, ll>>;
  using P = pair<ll, ll>;
  auto f = [&](ll x, ll y) -> tuple<ll, vector<pair<ll, ll>>> {
    if ((abs(X - x) + abs(Y - y)) % K != 0) return make_tuple(INF, PS{});
    return make_tuple(1 + (abs(X - x) + abs(Y - y)) / K, PS{{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 make_tuple(INF, PS{});
    return make_tuple(2 + (abs(X - x - a) + abs(Y - y - b)) / K, PS{{x, y}, {a, b}});
  };
  tuple<ll, vector<pair<ll, ll>>> cand(INF, {});
  for (ll i = 0; i <= min(K, 10000000LL); 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 <= min(K, 3000000LL); 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
Task E - Golf
User pekempey
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2109 Byte
Status WA
Exec Time 1913 ms
Memory 2304 KB

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 52
WA × 3
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, sample_03.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt, sub1_22.txt, sub1_23.txt, sub1_24.txt, sub1_25.txt, sub1_26.txt, sub1_27.txt, sub1_28.txt, sub1_29.txt, sub1_30.txt, sub1_31.txt, sub1_32.txt, sub1_33.txt, sub1_34.txt, sub1_35.txt, sub1_36.txt, sub1_37.txt, sub1_38.txt, sub1_39.txt, sub1_40.txt, sub1_41.txt, sub1_42.txt, sub1_43.txt, sub1_44.txt, sub1_45.txt, sub1_46.txt, sub1_47.txt, sub1_48.txt, sub1_49.txt, sub1_50.txt, sub1_51.txt, sub1_52.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 3 ms 256 KB
sample_03.txt AC 1 ms 256 KB
sub1_01.txt AC 2 ms 256 KB
sub1_02.txt AC 639 ms 256 KB
sub1_03.txt AC 639 ms 256 KB
sub1_04.txt AC 29 ms 256 KB
sub1_05.txt AC 3 ms 256 KB
sub1_06.txt AC 7 ms 256 KB
sub1_07.txt AC 5 ms 256 KB
sub1_08.txt AC 1 ms 256 KB
sub1_09.txt AC 1 ms 256 KB
sub1_10.txt AC 1913 ms 256 KB
sub1_11.txt AC 1905 ms 256 KB
sub1_12.txt AC 2 ms 256 KB
sub1_13.txt AC 8 ms 256 KB
sub1_14.txt AC 5 ms 256 KB
sub1_15.txt AC 4 ms 256 KB
sub1_16.txt AC 1 ms 256 KB
sub1_17.txt AC 9 ms 256 KB
sub1_18.txt WA 1642 ms 256 KB
sub1_19.txt AC 639 ms 256 KB
sub1_20.txt AC 2 ms 384 KB
sub1_21.txt AC 17 ms 256 KB
sub1_22.txt AC 21 ms 256 KB
sub1_23.txt AC 2 ms 256 KB
sub1_24.txt AC 1 ms 256 KB
sub1_25.txt AC 4 ms 256 KB
sub1_26.txt WA 1904 ms 256 KB
sub1_27.txt WA 1904 ms 256 KB
sub1_28.txt AC 2 ms 256 KB
sub1_29.txt AC 1 ms 256 KB
sub1_30.txt AC 3 ms 256 KB
sub1_31.txt AC 7 ms 256 KB
sub1_32.txt AC 1 ms 256 KB
sub1_33.txt AC 2 ms 256 KB
sub1_34.txt AC 29 ms 2304 KB
sub1_35.txt AC 4 ms 256 KB
sub1_36.txt AC 4 ms 256 KB
sub1_37.txt AC 1509 ms 256 KB
sub1_38.txt AC 1 ms 256 KB
sub1_39.txt AC 2 ms 256 KB
sub1_40.txt AC 1 ms 256 KB
sub1_41.txt AC 1 ms 256 KB
sub1_42.txt AC 1 ms 256 KB
sub1_43.txt AC 1 ms 256 KB
sub1_44.txt AC 1 ms 256 KB
sub1_45.txt AC 1 ms 256 KB
sub1_46.txt AC 1 ms 256 KB
sub1_47.txt AC 11 ms 896 KB
sub1_48.txt AC 1 ms 256 KB
sub1_49.txt AC 1 ms 256 KB
sub1_50.txt AC 1 ms 256 KB
sub1_51.txt AC 12 ms 1024 KB
sub1_52.txt AC 1 ms 256 KB