結果

問題 No.186 中華風 (Easy)
ユーザー simansiman
提出日時 2016-03-28 01:40:10
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 22 ms / 2,000 ms
コード長 965 bytes
コンパイル時間 592 ms
コンパイル使用メモリ 73,496 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-27 00:48:33
合計ジャッジ時間 1,775 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <limits.h>
#include <time.h>
#include <string>
#include <string.h>
#include <sstream>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

ll gcd(ll a, ll b){
  if(b == 0) return a;
  return gcd(b, a%b);
}

ll lcm(ll a, ll b){
  return a*b / gcd(a, b);
}

int main(){
  ll x1, y1, x2, y2, x3, y3;
  cin >> x1 >> y1;
  cin >> x2 >> y2;
  cin >> x3 >> y3;
  ll n1, n2;
  bool success = false;
  ll l = lcm(y1, y2);

  for(int i = 0; i <= y2 && !success; i++){
    n1 = x1 + y1 * i;

    if (n1 > 0 && n1 % y2 == x2) {
      for(int j = 0; j <= y3 && !success; j++){
        n2 = n1 + l * j;

        if (n2 % y3 == x3) {
          success = true;
          break;
        }
      }
    }
  }

  if (success) {
    cout << n2 << endl;
  } else {
    cout << -1 << endl;
  }

  return 0;
}
0