結果

問題 No.186 中華風 (Easy)
ユーザー koba-e964koba-e964
提出日時 2015-05-02 19:21:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,114 bytes
コンパイル時間 571 ms
コンパイル使用メモリ 87,016 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 00:45:58
合計ジャッジ時間 1,812 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;

int x[3], y[3];

/* m2 is small (<= 10^6) */
int calc(ll x1, ll m1, ll x2, ll m2, ll *x3, ll *m3) {
  ll g = __gcd(m1, m2);
  ll l = m1 / g * m2;
  for (ll i = x1; i < l; i += m1) {
    if (i % m2 == x2) {
      *x3 = i;
      *m3 = l;
      return 1;
    }
  }
  return 0;
}


int main(void){
  REP(i, 0, 3) {
    cin >> x[i] >> y[i];
  }
  ll rx = 0, rm = 1;
  REP(i, 0, 3) {
    if (! calc(rx, rm, x[i], y[i], &rx, &rm)) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << (rx == 0 ? rm : rx) << endl;
}
0