結果

問題 No.186 中華風 (Easy)
コンテスト
ユーザー zoidzium (zz)
提出日時 2025-12-20 13:39:32
言語 C++23
(gcc 13.3.0 + boost 1.89.0)
結果
WA  
実行時間 -
コード長 5,980 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,597 ms
コンパイル使用メモリ 283,848 KB
実行使用メモリ 7,852 KB
最終ジャッジ日時 2025-12-20 13:39:44
合計ジャッジ時間 4,277 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 6 WA * 17
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

#include <cassert>
using namespace std;

using ull = unsigned long long;
using ll = long long;
using xy = pair<ll, ll>;
using coord = pair<double, double>;
using bs8 = bitset<8>;
using bs16 = bitset<16>;
using bs32 = bitset<32>;
using bs64 = bitset<64>;

using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vvs = vector<vs>;
using vxy = vector<xy>;
using vvxy = vector<vxy>;
using vcoord = vector<coord>;
using vvcoord = vector<vcoord>;

#define rep(var, n) for (ll var = 0; var < (ll)(n); var++)
#define cnt(var, n, m) for (ll var = (n); var <= (ll)(m); var++)
#define rcnt(var, n, m) for (ll var = (n); var >= (ll)(m); var--)
#define each(ite, C) for (auto ite = (C).begin(); ite != (C).end(); ite++)
#define reach(ite, C) for (auto ite = (C).rbegin(); ite != (C).rend(); ite++)
#define yn(b) cout << (((b) > 0) ? "Yes" : "No") << endl;
#define ZINIT 1

#if __has_include("zout.h")
#include "zout.h"
#else
namespace zz_print {
class dbg {
 public:
  static bool unprint;
  static string margin;
  static string separated;
  static string indentS;
  static int hierarchical;
  static int topHier;
  static int precision;
  static bool exponential;

  static void setFloat(const int& prec, const bool& expo) {
    precision = prec;
    exponential = expo;
  };

  template <int hier = 0, int sep = 2, int mgn = 1, typename... Args>
  static void zout(Args&&... args) {};
};
bool dbg::unprint = false;
string dbg::margin = "";
string dbg::separated = "";
string dbg::indentS = "";
int dbg::hierarchical = 0;
int dbg::topHier = 0;
int dbg::precision = 6;
bool dbg::exponential = false;
};  // namespace zz_print
using namespace zz_print;
#endif

xy gcdex(ll a, ll b) {
  xy ans;

  if (abs(a) < abs(b)) {
    ans = gcdex(b, a);
    swap(ans.first, ans.second);
    return ans;
  } else if (b == 0) {
    return xy{1, 0};
  }

  //  a > b
  //  da x + db y = d
  //   a x +  b y = 1
  //   (b(a/b) + a%b) x + b y = 1
  //   b ((a/b)x + y) + a%b x = 1
  //   b x' + a%b y' = 1
  //
  //   |x|   | 0   1  | |x'|
  //   | | = |        |*|  |
  //   |y|   | 1 -a/b | |y'|
  //
  ans = gcdex(b, a % b);
  return xy{ans.second, ans.first - (a / b) * ans.second};
};
xy gcdex(xy ab) { return gcdex(ab.first, ab.second); }
ll gcd(ll a, ll b) {
  xy ans = gcdex(a, b);
  return abs(a * ans.first + b * ans.second);
}
ll gcd(xy ab) { return gcd(ab.first, ab.second); }
vl gcd(const vl& vec) {
  ll n = vec.size();
  vl subvec;
  rep(i, n / 2) subvec.push_back(gcd(vec[2 * i], vec[2 * i + 1]));
  if (n % 2) subvec.push_back(vec[n - 1]);
  return gcd(subvec);
}

ll ganner(const vxy& pm) {
  ll p = 1, mod;
  if (pm.empty()) return p;
  ll n = pm.size();
  p = pm[0].first;
  mod = pm[0].second;
  cnt(i, 1, n - 1) {
    xy ans = gcdex(mod, pm[i].second);
    ll d = mod * ans.first + pm[i].second * ans.second;
    if ((p % d) != (pm[i].first % d)) return -1;
    ll s = (pm[i].first - p) / d;
    dbg::zout("ganner: ", p, mod, pm[i], ans, d, s);
    p = (s * mod * ans.first + p);
    mod /= d;
    mod *= pm[i].second;
    // p %= mod;
    // if (p < 0) p += mod;
  }

  return p;
};

namespace zz_mod {
template <ll mod = 998244353>
class pp {
 public:
  ll val;
  void flush() {
    val %= mod;
    if (val < 0) val += mod;
  };
  void weak_flush() {
    if (val < 0) {
      val += mod;
    } else if (val >= mod) {
      val -= mod;
    }
  };
  pp(ll x = 0) {
    val = x % mod;
    weak_flush();
  };
  friend std::ostream& operator<<(std::ostream& os, const pp<mod>& x) {
    return os << '{' << x.val << '|' << mod << '}';
  };

  pp<mod>& operator+=(const pp<mod>& p) {
    val += p.val;
    weak_flush();
    return *this;
  };
  pp<mod>& operator+=(ll x) {
    val += x % mod;
    weak_flush();
    return *this;
  };
  friend pp<mod> operator+(pp<mod> a, const pp<mod>& b) { return a += b; };
  friend pp<mod> operator+(pp<mod> a, ll x) { return a += x; };
  friend pp<mod> operator+(ll x, pp<mod> a) { return a += x; };

  pp<mod>& operator-=(const pp<mod>& p) {
    val -= p.val;
    weak_flush();
    return *this;
  };
  pp<mod>& operator-=(ll x) {
    val -= x % mod;
    weak_flush();
    return *this;
  };
  friend pp<mod> operator-(pp<mod> a, const pp<mod>& b) { return a -= b; };
  friend pp<mod> operator-(pp<mod> a, ll x) { return a -= x; };
  friend pp<mod> operator-(ll x, const pp<mod>& a) { return pp<mod>(x) -= a; };

  pp<mod>& operator*=(const pp<mod>& p) {
    val = (__int128)val * p.val;
    flush();
    return *this;
  };
  pp<mod>& operator*=(ll x) {
    val = (__int128)val * x;
    flush();
    return *this;
  };
  friend pp<mod> operator*(pp<mod> a, const pp<mod>& b) { return a *= b; };
  friend pp<mod> operator*(pp<mod> a, ll x) { return a *= x; };
  friend pp<mod> operator*(ll x, const pp<mod>& a) { return pp<mod>(x) *= a; };

  pp<mod> inv() {
    xy ans = gcdex(mod, val);
    assert((mod * ans.first + val * ans.second) == 1);
    pp<mod> p(ans.second);
    return p;
  };
  pp<mod>& operator/=(const pp<mod>& p) { return *this *= p.inv(); }
  pp<mod>& operator/=(ll x) { return *this *= gcdex(mod, x).second; }

  friend pp<mod> operator/(pp<mod> a, const pp<mod>& b) { return a /= b; };
  friend pp<mod> operator/(pp<mod> a, ll x) { return a /= x; };
  friend pp<mod> operator/(ll x, const pp<mod>& a) {
    a = a.inv();
    return a /= x;
  };

  pp<mod> exp(ll n) {
    if (n < 0) return inv().exp(-n);
    pp<mod> p = *this, ans(1);
    while (n > 1) {
      if (n & 1) ans *= p;
      p *= p;
      n >>= 1;
    }
    if (n > 0) ans *= p;
    return ans;
  };
};

}  // namespace zz_mod
using namespace zz_mod;

/////////////////////////////////////////////////

/////////////////////////////////////////////////

int main() {
  // dbg::unprint = true;

  vl X(3), Y(3);

  rep(i, 3) cin >> X[i] >> Y[i];

  vxy VEC;
  rep(i, 3) VEC.emplace_back(X[i], Y[i]);
  cout << ganner(VEC) << endl;
  return 0;
}
0