Submission #46328502


Source Code Expand

// Author: XZC(L_Wave)
// Language: Cpp/G++14
// Problem: F - Push and Carry
// Contest: AtCoder - UNIQUE VISION Programming Contest 2023 Autumn(AtCoder Beginner Contest 323)
// URL: https://atcoder.jp/contests/abc323/tasks/abc323_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// Create Time: not 2023-10-07 20:00:33, but 1926-08-17 11:45:14
// 
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i <= i##ABRACADABRA; i++)
#define drep(i, a, b) for (int i = (a), i##ABRACADABRA = (b); i >= i##ABRACADABRA; i--)
using namespace std;
using ll = long long;

struct Point {
  ll x, y;
  void read() {
    scanf("%lld%lld", &x, &y);
  }
  friend bool operator==(Point a, Point b) {
    return a.x==b.x && a.y==b.y;
  }
  Point xp(ll t) const {
    return {x + t, y};
  }
  Point yp(ll t) const {
    return {x, y + t};
  }
} man, car, to;

ll manhattan(Point a, Point b) {
  return llabs(a.x - b.x) + llabs(a.y - b.y);
}

ll mvc(Point a, Point b, Point c) {
  if (a == b)
    return 0;
  if (a == c || b == c)
    return (ll)1e18;
  if (a.x == b.x && a.x == c.x) {
    if (a.y > b.y)
      swap(a, b);
    if (a.y <= c.y && c.y <= b.y)
      return b.y - a.y + 2;
    else
      return b.y - a.y;
  }
  if (a.y == b.y && a.y == c.y) {
    if (a.x > b.x)
      swap(a, b);
    if (a.x <= c.x && c.x <= b.x)
      return b.x - a.x + 2;
    else
      return b.x - a.x;
  }
  return manhattan(a, b);
}

ll go(Point a, Point b) {
  if (a.x == b.x || a.y == b.y)
    return manhattan(a, b);
  return manhattan(a, b) + 2;
}

ll gofor() {
  ll mind = 1e18;
  if (car.x < to.x)
    mind = min(mind, mvc(man, car.xp(-1), car));
  if (car.x > to.x)
    mind = min(mind, mvc(man, car.xp(+1), car));
  if (car.y < to.y)
    mind = min(mind, mvc(man, car.yp(-1), car));
  if (car.y > to.y)
    mind = min(mind, mvc(man, car.yp(+1), car));
  return mind;
}

int main() {
  man.read();
  car.read();
  to.read();
  printf("%lld\n", gofor() + go(car, to));
  return 0;
}

Submission Info

Submission Time
Task F - Push and Carry
User fft_ntt
Language C++ 20 (gcc 12.2)
Score 525
Code Size 2122 Byte
Status AC
Exec Time 1 ms
Memory 3892 KiB

Compile Error

Main.cpp: In member function ‘void Point::read()’:
Main.cpp:21:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |     scanf("%lld%lld", &x, &y);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 3
AC × 55
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, random2_00.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3684 KiB
example_01.txt AC 1 ms 3760 KiB
example_02.txt AC 1 ms 3740 KiB
hand_00.txt AC 1 ms 3892 KiB
hand_01.txt AC 1 ms 3828 KiB
random2_00.txt AC 1 ms 3660 KiB
random2_01.txt AC 1 ms 3824 KiB
random2_02.txt AC 1 ms 3684 KiB
random2_03.txt AC 1 ms 3888 KiB
random2_04.txt AC 1 ms 3764 KiB
random2_05.txt AC 1 ms 3656 KiB
random2_06.txt AC 1 ms 3768 KiB
random2_07.txt AC 1 ms 3740 KiB
random2_08.txt AC 1 ms 3668 KiB
random2_09.txt AC 1 ms 3700 KiB
random_00.txt AC 1 ms 3688 KiB
random_01.txt AC 1 ms 3824 KiB
random_02.txt AC 1 ms 3832 KiB
random_03.txt AC 1 ms 3828 KiB
random_04.txt AC 1 ms 3628 KiB
random_05.txt AC 1 ms 3584 KiB
random_06.txt AC 1 ms 3824 KiB
random_07.txt AC 1 ms 3764 KiB
random_08.txt AC 1 ms 3668 KiB
random_09.txt AC 1 ms 3892 KiB
random_10.txt AC 1 ms 3768 KiB
random_11.txt AC 1 ms 3700 KiB
random_12.txt AC 1 ms 3764 KiB
random_13.txt AC 1 ms 3584 KiB
random_14.txt AC 1 ms 3688 KiB
random_15.txt AC 1 ms 3692 KiB
random_16.txt AC 1 ms 3660 KiB
random_17.txt AC 1 ms 3576 KiB
random_18.txt AC 1 ms 3688 KiB
random_19.txt AC 1 ms 3580 KiB
random_20.txt AC 1 ms 3628 KiB
random_21.txt AC 1 ms 3824 KiB
random_22.txt AC 1 ms 3744 KiB
random_23.txt AC 1 ms 3664 KiB
random_24.txt AC 1 ms 3664 KiB
random_25.txt AC 1 ms 3764 KiB
random_26.txt AC 1 ms 3736 KiB
random_27.txt AC 1 ms 3740 KiB
random_28.txt AC 1 ms 3764 KiB
random_29.txt AC 1 ms 3688 KiB
random_30.txt AC 1 ms 3828 KiB
random_31.txt AC 1 ms 3824 KiB
random_32.txt AC 1 ms 3824 KiB
random_33.txt AC 1 ms 3672 KiB
random_34.txt AC 1 ms 3736 KiB
random_35.txt AC 1 ms 3660 KiB
random_36.txt AC 1 ms 3580 KiB
random_37.txt AC 1 ms 3824 KiB
random_38.txt AC 1 ms 3692 KiB
random_39.txt AC 1 ms 3584 KiB