結果

問題 No.3679 なんかでっかい虫リターンズ
コンテスト
ユーザー kentakunkentakun
提出日時 2026-09-05 21:44:57
言語 C++23(gnu拡張gcc16)
(gcc 16.1.0 + boost 1.92.0 + ACL)
コンパイル:
g++-16 -O2 -lm -std=gnu++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 1 ms / 2,000 ms
+ 860µs
コード長 3,097 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,687 ms
コンパイル使用メモリ 363,508 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2026-09-05 21:45:10
合計ジャッジ時間 4,343 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:140:13: warning: 'nox' may be used uninitialized [-Wmaybe-uninitialized]
  140 |   ans += abs(p - nox) + abs(q - noy);
      |          ~~~^~~~~~~~~
main.cpp:117:6: note: 'nox' was declared here
  117 |   ll nox, noy;
      |      ^~~
main.cpp:140:28: warning: 'noy' may be used uninitialized [-Wmaybe-uninitialized]
  140 |   ans += abs(p - nox) + abs(q - noy);
      |                         ~~~^~~~~~~~~
main.cpp:117:11: note: 'noy' was declared here
  117 |   ll nox, noy;
      |           ^~~

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define ld long double
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)(b); i++)
#define FORR(i, a, b) for (ll i = (a); i <= (ll)(b); i++)
#define repR(i, n) for (ll i = n - 1; i >= 0LL; i--)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout << (x) << "\n"
#define YES(n) cout << ((n) ? "YES\n" : "NO\n")
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n")
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tll;
using u64 = unsigned long long;
using vii = vector<int>;
using vvii = vector<vii>;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;

template <class T>
using PQ = priority_queue<T>;

template <class T>
using PQR = priority_queue<T, vector<T>, greater<T>>;

// const ll MOD = 1e9+7LL;
const ll MOD = 998244353LL;
const ll INF = 1LL << 62;
const double INF_D = numeric_limits<double>::infinity();

template <class T>
constexpr void printArray(const vector<T> &vec, char split = ' ')
{
  rep(i, vec.size())
  {
    cout << vec[i];
    cout << (i == (int)vec.size() - 1 ? '\n' : split);
  }
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
ll dx[4] = {0, 1, 0, -1};
ll dy[4] = {1, 0, -1, 0};
bool isIn(ll nx, ll ny, ll h, ll w)
{
  if (nx >= 0 && nx < h && ny >= 0 && ny < w)
  {
    return true;
  }
  return false;
}
int main()
{
  ll h, w;
  cin >> h >> w;
  ll a, b;
  cin >> a >> b;
  a--;
  b--;
  ll r1, c1, r2, c2;
  cin >> r1 >> c1 >> r2 >> c2;
  r1--;
  c1--;
  r2--;
  c2--;
  ll p, q;
  cin >> p >> q;
  p--;
  q--;
  vvll t(h, vll(w));
  for (int i = r1; i <= r2; i++)
  {
    for (int j = c1; j <= c2; j++)
    {
      t[i][j] = 1;
    }
  }
  queue<pll> que;
  que.push({a, b});
  vvll dist(h, vll(w, -1));
  dist[a][b] = 0;
  ll ans = 0;
  ll nox, noy;
  while (que.size())
  {
    auto [x, y] = que.front();
    que.pop();
    if (t[x][y] == 1)
    {
      ans = dist[x][y];
      nox = x;
      noy = y;
      break;
    }
    rep(i, 4)
    {
      ll nx = dx[i] + x;
      ll ny = dy[i] + y;
      if (isIn(nx, ny, h, w) && dist[nx][ny] == -1)
      {
        dist[nx][ny] = dist[x][y] + 1;
        que.push({nx, ny});
      }
    }
  }
  ans += abs(p - nox) + abs(q - noy);
  ans += abs(p - a) + abs(q - b);
  cout << ans << endl;
}
/*cin.tie(0);
ios::sync_with_studio(false);
next_permutation(v.begin(), v.end())

cout << fixed << setprecision(10);
__int128

//ソート済み
v.erase(unique(v.begin(), v.end()), v.end());
__builtin_popcountll(i)

// maskからnowのビットだけ削除
mask & ~(1 << now)

*/
0