結果

問題 No.186 中華風 (Easy)
ユーザー cormorancormoran
提出日時 2016-12-27 19:20:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,052 bytes
コンパイル時間 1,862 ms
コンパイル使用メモリ 167,616 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 00:50:05
合計ジャッジ時間 2,903 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
4,380 KB
testcase_01 AC 6 ms
4,376 KB
testcase_02 AC 6 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 12 ms
4,380 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 19 ms
4,376 KB
testcase_09 AC 18 ms
4,380 KB
testcase_10 AC 16 ms
4,380 KB
testcase_11 AC 23 ms
4,376 KB
testcase_12 AC 7 ms
4,380 KB
testcase_13 AC 8 ms
4,380 KB
testcase_14 AC 9 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 4 ms
4,380 KB
testcase_19 AC 12 ms
4,380 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 10 ms
4,380 KB
testcase_22 AC 11 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl

template<class T> bool set_min(T &a, const T &b) { return a > b  ? a = b, true : false; }
template<class T> bool set_max(T &a, const T &b) { return a < b  ? a = b, true : false; }
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) { for(T &a : v) is >> a; return is; }
template<class T> ostream& operator << (ostream &os , const vector<T> &v) { for(const T &t : v) os << "\t" << t; return os << endl; }
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) { return os << "<" << v.first << ", " << v.second << ">"; }

const int INF = 1 << 30;
const ll INFL = 1LL << 60;

template<typename T>
T gcd(T a,T b){
    T c=a,d=b,r;
    do{r=c%d;c=d;d=r;}while(r);
    return c;
}

template<typename T>
T lcm(T a,T b){return a*b/gcd(a,b);}

class Solver {
  public:
    bool solve() {
        vector<int> X(3), Y(3);
        rep(i, 3) cin >> X[i] >> Y[i];

        if(*max_element(all(X)) == 0) {
            cout << lcm<ll>(lcm<ll>(Y[0], Y[1]), Y[2]) << endl;
            return 0;
        }
        
        ll A = -1;
        for(ll k = 0; k <= Y[1]; k++) {
            ll a = X[0] + k * Y[0];
            if(a >= X[1] and (a - X[1]) % Y[1] == 0) {
                A = a;
                break;
            }
        }
        ll g = lcm<ll>(Y[0], Y[1]);
        ll AA = -1;
        if(A >= 0) {
            for(ll k = 0; k <= Y[2]; k++) {
                ll a = A + k * g;
                if(a >= X[2] and (a - X[2]) % Y[2] == 0) {
                    AA = a;
                    break;
                }
            }
        }
        cout << AA << endl;
        
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}
0