結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー koba-e964koba-e964
提出日時 2016-12-13 01:01:05
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,100 bytes
コンパイル時間 438 ms
コンパイル使用メモリ 56,120 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 21:52:43
合計ジャッジ時間 2,583 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,376 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 1 ms
4,376 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,376 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll> PL;

ll gcd(ll x, ll y) {
  return y == 0 ? x : gcd(y, x % y);
}

PL add(PL x, PL y) {
  PL w = PL(x.first * y.second + x.second * y.first, x.second * y.second);
  ll g = gcd(w.first, w.second);
  w.first /= g;
  w.second /= g;
  return w;
}

PL inv(PL x) {
  return x.first > 0 ? PL(x.second, x.first) : PL(-x.second, -x.first);
}

PL fr_lcm(PL x, PL y) {
  ll numer = x.first / gcd(x.first, y.first) * y.first;
  ll denom = gcd(x.second, y.second);
  return PL(numer, denom);
}

int main(void){
  ll t1, t2, t3;
  cin >> t1 >> t2 >> t3;
  PL mi = PL(1e16, 1);
  REP(i, 0, 2) {
    REP(j, 0, 2) {
      PL b = PL(1, t1);
      PL d = PL(-1 + 2 * i, t2);
      PL f = PL(-1 + 2 * j, t3);
      PL b_d = inv(add(b, d));
      PL b_f = inv(add(b, f));
      PL res = fr_lcm(b_d, b_f);
      if ((double)mi.first / mi.second > (double)res.first / res.second) {
	mi = res;
      }
    }
  }
  cout << mi.first << "/" << mi.second << endl;
}
0