結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー どららどらら
提出日時 2015-06-20 00:05:49
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,911 bytes
コンパイル時間 737 ms
コンパイル使用メモリ 81,592 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 10:23:56
合計ジャッジ時間 7,207 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

int gcd(int a, int b){return (b==0?a:gcd(b,a%b));}
int lcm(int a, int b){return a/gcd(a,b)*b;}

bool solve3(ll T1, ll T2, ll T3, ll v, ll x){
  double d1 = v/(double)x/(double)T1;
  double d2 = v/(double)x/(double)T2;
  double d3 = v/(double)x/(double)T3;
  d1 -= (int)(d1);
  if(d1>0.5) d1 = 1.0-d1;
  d2 -= (int)(d2);
  if(d2>0.5) d2 = 1.0-d2;
  d3 -= (int)(d3);
  if(d3>0.5) d3 = 1.0-d3;

  //cout << x << " " << d1 << " " << d2 << " " << d3 << endl;
  if(fabs(d1-d2)<1e-9 && fabs(d2-d3)<1e-9) return true;
  return false;
}
bool solve2(ll T1, ll T2, ll v, ll x){
  double d1 = v/(double)x/(double)T1;
  double d2 = v/(double)x/(double)T2;
  d1 -= (int)(d1);
  if(d1>0.5) d1 = 1.0-d1;
  d2 -= (int)(d2);
  if(d2>0.5) d2 = 1.0-d2;
  if(fabs(d1-d2)<1e-9) return true;
  return false;
}

vector<ll> divisor(int n){
  vector<ll> ret;
  for(ll i=1; i*i<=n; i++){
    if(n%i==0){
      ret.push_back(i);
      if(i!=n/i) ret.push_back(n/i);
    }
  }
  sort(ret.begin(), ret.end());
  reverse(ret.begin(), ret.end());
  return ret;
}


int main(){
  ll T1, T2, T3;
  cin >> T1;
  cin >> T2;
  cin >> T3;

  ll v = lcm(T1, lcm(T2, T3));

  ll x = 0;
  for(ll i=v-1; i>0; i--){
    if(solve2(T1, T2, v, i)){
      x = i;
      break;
    }
  }

  vector<ll> div = divisor(x);
  rep(i,div.size()){    
    if(solve3(T1, T2, T3, v, div[i])){
      cout << v << "/" << div[i] << endl;
      return 0;
    }
  }
  return 0;
}
0