結果

問題 No.2743 Twisted Lattice
ユーザー zatsu308zatsu308
提出日時 2024-04-21 11:59:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,250 bytes
コンパイル時間 3,181 ms
コンパイル使用メモリ 206,728 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-04-21 12:00:11
合計ジャッジ時間 12,616 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#ifndef LOCAL
// #pragma GCC target("avx2") // judge: v4 or cascadelake(←最後の一投で試すレベルでv4と差がないと思ってる)
#pragma GCC optimize("Ofast")
#endif
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

constexpr ll mod = 998244353;

template<ll mod>
struct Mint {
  using M=Mint; ll v;
  M& put(ll x) { v=(x<mod)?x:x-mod; return *this; }
  Mint(ll x=0) { put(x%mod+mod); }
  M operator+(M m) {return M().put(v+m.v);}
  M operator-(M m) {return M().put(v+mod-m.v);}
  M operator*(M m) {return M().put(v*m.v%mod);}
  M operator/(M m) {return M().put(v*m.inv().v%mod);}
// BEGIN IGNORE
  M operator+=(M m) { return put(v+m.v); }
  M operator-=(M m) { return put(v+mod-m.v); }
  M operator*=(M m) { return put(v*m.v%mod); }
  M operator/=(M m) { return put(v*m.inv().v%mod); }
// END IGNORE
  bool operator==(M m) { return v==m.v; }
  M pow(ll m) const {
    M x=v, res=1;
    while (m) {
      if (m&1) res=res*x;
      x=x*x; m>>=1;
    }
    return res;
  }
  M inv() { return pow(mod-2); }
};

using mint = Mint<mod>;

struct UnionFind{
  int n;
  vector<int> par;
  UnionFind(int n) : n(n), par(n, -1){}
  int find(int x){return par[x] < 0 ? x : find(par[x]);}
  bool Unite(int x, int y){
    x = find(x), y = find(y);
    if(x == y)return false;
    // size[x] < size[y]
    if(par[x] > par[y])swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return true;
  }
};

namespace std {
  template<typename T,typename U> struct hash<pair<T,U>> {
    size_t operator()(pair<T,U> const &val) const {
      return hash<T>{}(val.first)*1337^hash<U>{}(val.second);
    }};
}

int main(){

  int h, w, n;
  cin >> h >> w >> n;
  vector<ll> xs(n), ys(n);
  for(int i = 0; i < n; ++i){
    cin >> xs[i] >> ys[i];
    --xs[i], --ys[i];
  }
  for(int i = 0; i < n; ++i){
    ll ans = 1e18;
    ll dist;
    for(int j = 0; j < n; ++j){
      if(i == j)continue;
      int d = abs(ys[i] - ys[j]);
      if(d == 0){
        dist = abs(xs[i] - xs[j]);
      }
      else if(d == 1){
        dist = max(xs[i], xs[j]) + 1;
      }
      else if(d == 2){
        dist = xs[i] + xs[j] + 2;
      }
      else{
        dist = xs[i] + xs[j] + d;
      }
      ans = min(ans, dist);
    }
    cout << ans << endl;
  }

}
0