結果

問題 No.229 線分上を往復する3つの動点の一致
ユーザー kotatsugamekotatsugame
提出日時 2020-03-09 17:39:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,417 bytes
コンパイル時間 924 ms
コンパイル使用メモリ 78,836 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-08 05:04:20
合計ジャッジ時間 2,635 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 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 2 ms
4,384 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,384 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,376 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 1 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 2 ms
4,384 KB
testcase_39 AC 1 ms
4,380 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 2 ms
4,384 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 1 ms
4,380 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:42:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   42 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
long gcd(long a,long b){return b?gcd(b,a%b):a;}
long T1,T2,T3;
vector<pair<long,long> >ans;
pair<long,long>mul(long t,pair<long,long>x)
{
	pair<long,long>ret=x;
	ret.second*=t;
	long g=gcd(ret.first,ret.second);
	ret.first/=g;
	ret.second/=g;
	ret.first%=ret.second;
	ret.first=min(ret.first,ret.second-ret.first);
	return ret;
}
void f(long t1,long t2)
{
	pair<long,long>p=make_pair(t1*t2,t2-t1);
	long g=gcd(p.first,p.second);
	p.first/=g;
	p.second/=g;
	pair<long,long>X[3]={mul(T1,p),mul(T2,p),mul(T3,p)};
	if(X[0]==X[1]&&X[1]==X[2]&&X[2]==X[0])ans.push_back(p);
}
long calc(long X,long a,long b)
{
	long ret=1;
	for(long i=1;i*i<=X;i++)
	{
		if(X%i==0)
		{
			if(a%i==b%i||i-a%i==b%i)ret=max(ret,i);
			long j=X/i;
			if(a%j==b%j||j-a%j==b%j)ret=max(ret,j);
		}
	}
	return ret;
}
main()
{
	cin>>T1>>T2>>T3;
	long lcm=T1/gcd(T1,T2)*T2;
	lcm=lcm/gcd(lcm,T3)*T3;
	ans.push_back(make_pair(lcm,1));
	ans.push_back(make_pair(lcm,calc(lcm/T1-lcm/T2,lcm/T1,lcm/T3)));
	ans.push_back(make_pair(lcm,calc(lcm/T1-lcm/T3,lcm/T1,lcm/T2)));
	ans.push_back(make_pair(lcm,calc(lcm/T2-lcm/T3,lcm/T2,lcm/T1)));
	f(T1,T2);
	f(T1,T3);
	f(T2,T3);
	sort(ans.begin(),ans.end(),[](pair<long,long>a,pair<long,long>b){
		return a.first*b.second<b.first*a.second;
	});
	long g=gcd(ans[0].first,ans[0].second);
	cout<<ans[0].first/g<<"/"<<ans[0].second/g<<endl;
}
0