結果

問題 No.186 中華風 (Easy)
ユーザー ayanamizutaayanamizuta
提出日時 2019-01-24 14:52:02
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 765 bytes
コンパイル時間 2,519 ms
コンパイル使用メモリ 144,960 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-10-14 09:38:32
合計ジャッジ時間 2,687 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

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

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

bool bl=false;

long long solve(long long x1,long long y1,long long x2,long long y2){
  REP(i,y2){
    if((x1+i*y1)%y2==x2)return (x1+i*y1)%lcm(y1,y2);
  }
  bl=true;
  return -1;
}

LL x[3],y[3];

int main(){
  cin>>x[0]>>y[0]>>x[1]>>y[1]>>x[2]>>y[2];
  LL ret,lc=lcm(y[0],y[1]);
  ret = solve(x[0],y[0],x[1],y[1]);
  ret = solve(ret,lc,x[2],y[2]);
  if(bl){
    cout<<-1<<endl;
    return 0;
  }
  cout<<ret%(lcm(lc,y[2]))<<endl;
  return 0;
}
0