結果

問題 No.186 中華風 (Easy)
コンテスト
ユーザー fken57
提出日時 2026-06-01 02:13:42
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 5,564 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,327 ms
コンパイル使用メモリ 377,920 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2026-06-01 02:13:48
合計ジャッジ時間 5,442 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
純コード判定待ち
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

//#define //_GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
/*long long型*/
using ll = long long;
using vll=vector<ll>;
using vvll=vector<vll>;
using vvvll=vector<vvll>;
/*ull*/
using ull = unsigned long long;
using vull=vector<ull>;
using vvull=vector<vull>;
using vvvull=vector<vvull>;
/*Graphの型*/
using Graph=vvll;
using EdgeGraph=vector<vector<pair<ll,ll>>>;
/*文字列型*/
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vs=vector<string>;
/*pair型(ll,ll)*/
using Pll=pair<ll,ll>;
using vPll=vector<Pll>;
/*tuple型(ll,ll,ll)*/
using tup=tuple<ll,ll,ll>;
/*bool型*/
using bl=bool;
using vbl=vector<bool>;
using vvbl=vector<vbl>;
using vvvbl=vector<vvbl>;
/*long double*/
using ld=long double;
using vld=vector<ld>;
using vvld=vector<vld>;
using vvvld=vector<vvld>;
/*mint*/
using mint = atcoder::modint998244353;
using vmint= vector<mint>;
using vvmint = vector<vmint>;
using vvvmint = vector<vvmint>;
/*inf*/
const int infint = 1073741823;
const ll inf = 1LL << 60;
/*chmin,max*/
template <class T> inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template <class T> inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
/*rep*/
#define rep(i,x,lim) for(ll i = (x);i < (ll)(lim);i++)
/*mod big prime*/
const ll mod1000000007=(1e+9)+7;
const ll mod998244353=998244353;
/*8方向ライブラリ(Grid対応)*/
ll dx[8]={1,-1,0,0,1,1,-1,-1};
ll dy[8]={0,0,1,-1,1,-1,1,-1};
/*2べき、10べき(64bit)*/
const vector<ull> pow2ll{1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288,1048576,2097152,4194304,8388608,16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,4294967296,8589934592,17179869184,34359738368,68719476736,137438953472,274877906944,549755813888,1099511627776,2199023255552,4398046511104,8796093022208,17592186044416,35184372088832,70368744177664,140737488355328,281474976710656,562949953421312,1125899906842624,2251799813685248,4503599627370496,9007199254740992,18014398509481984,36028797018963968,72057594037927936,144115188075855872,288230376151711744,576460752303423488,1152921504606846976,2305843009213693952,4611686018427387904, 9223372036854775808ull};
const vector<ull> pow10ll{1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000, 10000000000000000000ull};
/*inline 剰余*/
inline long long mod(long long a,long long m){
    return (a % m + m) %m;
}
/*余りが任意の時の高速で求める*/
int modpow(ll x,ll n,ll m){
    if(n==0) return 1%m;
    x=((x%m)+m)%m;
    if(n%2==0){
        ll r=modpow(x,n/2,m);
        return r*r%m;
    }
    else{
        ll r=modpow(x,n/2,m);
        return r*r%m*x%m;
    }
}


ll op(ll a,ll b){return max(a,b);}
ll opmin(ll a,ll b){return min(a,b);}
ll e(){return 0;}

/*pair unordered set*/
template<class T> size_t HashCombine(const size_t seed,const T &v){
    return seed^(std::hash<T>()(v)+0x9e3779b9+(seed<<6)+(seed>>2));
}
/* pair set*/
template<class T,class S> struct std::hash<std::pair<T,S>>{
    size_t operator()(const std::pair<T,S> &keyval) const noexcept {
        return HashCombine(std::hash<T>()(keyval.first), keyval.second);
    }
};

/*二項係数lib*/
/*@brief Cominitを呼び出して二項係数を高速で計算する(10^7程度まで)*/
const int MAX = 1010000;
mint fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    const int MOD = mint::mod();
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i;
        inv[i] = MOD - inv[MOD%i] * (MOD / i);
        finv[i] = finv[i - 1] * inv[i];
    }
}


mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
// Injecting ../../templete.hpp <- _lib/math/Equation/ChineseRem.hpp
// Skipping already injected ../templete.hpp

/*@param ax+by=gcd(x,y)を求める*/
/*@result gcd(x,y)*/
ll extGCD(ll a,ll b,ll &x,ll &y){
    ll d=a;

    if(b != 0){
        d = extGCD(b,a%b,y,x);
        y -= (a/b)*x;
    }
    else{
        x=1;
        y=0;
    }

    if(d < 0){
        d = -d;
    }

    return d;
}
// Skipping already injected ../../templete.hpp
// Skipping already injected ../templete.hpp

/*@param ax+by=gcd(x,y)を求める*/
/*@result gcd(x,y)*/
// Injecting ../extGCD.hpp <- _lib/math/Equation/ChineseRem.hpp

struct ChineseRemAns{
    bool isSolvable;
    ll r;
    ll Complexmod;
};

ChineseRemAns ChineseRem(const vector<ll> &b,const vector<ll> &m){
    ll r=0;ll M=1;
    for(int i=0; i<(int)b.size();++i){
        ll s,t;
        ll d=extGCD(M,m[i],s,t);
        if(mod(b[i]-r,d)!=0){
            return{
                false,
                0,
                0
            };
        }
        ll temp=(b[i]-r)/d*s%(m[i]/d);
        ll lcmCRT = m[i] * (M/d);

        r=mod(r+M*temp,lcmCRT);
        M=lcmCRT;
    }
    return{
        true,
        r,
        M
    };
}
// Injecting _lib/math/Equation/ChineseRem.hpp <- ABC/433/433e.cpp

void solve(){
    vll X(3),Y(3);
    rep(i,0,3){
        cin >> X[i] >> Y[i];
    }
    ChineseRemAns a= ChineseRem(X,Y);
    if(a.isSolvable==false) cout << -1;
    else if(a.r==0) cout << a.Complexmod;
    else cout << a.r;
}

int main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    ll T=1;
    //cin >> T;
    while(T--){
        solve();
    }
}
0