結果

問題 No.538 N.G.S.
ユーザー t98slider
提出日時 2022-12-31 17:41:04
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,608 bytes
コンパイル時間 1,410 ms
コンパイル使用メモリ 169,180 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-11-26 15:12:55
合計ジャッジ時間 2,854 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct yuri {
ll num,den;
yuri() : num(0),den(1) {}
yuri(ll a) : num(a),den(1){}
yuri(ll a,ll b) : num(a),den(b){safe();}
void safe(){
if(den<0)den*=-1,num*=-1;
ll v=__gcd(abs(num),den);
num/=v,den/=v;
}
yuri& operator++() {num+=den;return *this;}
yuri& operator--() {num-=den;return *this;}
yuri& operator+=(const yuri& rhs) {
num=num*rhs.den+den*rhs.num;
den=den*rhs.den;
safe();
return *this;
}
yuri& operator-=(const yuri& rhs) {
num=num*rhs.den-den*rhs.num;
den=den*rhs.den;
safe();
return *this;
}
yuri& operator*=(const yuri& rhs) {
num=num*rhs.num;
den=den*rhs.den;
safe();
return *this;
}
yuri& operator/=(const yuri& rhs) {
num=num*rhs.den;
den=den*rhs.num;
safe();
return *this ;
}
yuri operator+() const { return *this; }
yuri operator-() const { return yuri() - *this; }
friend yuri operator+(const yuri& lhs, const yuri& rhs) {
return yuri(lhs) += rhs;
}
friend yuri operator-(const yuri& lhs, const yuri& rhs) {
return yuri(lhs) -= rhs;
}
friend yuri operator*(const yuri& lhs, const yuri& rhs) {
return yuri(lhs) *= rhs;
}
friend yuri operator/(const yuri& lhs, const yuri& rhs) {
return yuri(lhs) /= rhs;
}
friend bool operator==(const yuri& lhs, const yuri& rhs) {
return (lhs.num==rhs.num&&lhs.den==rhs.den);
}
friend bool operator!=(const yuri& lhs, const yuri& rhs) {
return (lhs.num!=rhs.num||lhs.den!=rhs.den);
}
friend bool operator<(const yuri& lhs, const yuri& rhs) {
return (lhs.num*rhs.den<lhs.den*rhs.num);
}
friend bool operator<=(const yuri& lhs, const yuri& rhs) {
return (lhs.num*rhs.den<=lhs.den*rhs.num);
}
friend bool operator>(const yuri& lhs, const yuri& rhs) {
return (lhs.num*rhs.den>lhs.den*rhs.num);
}
friend bool operator>=(const yuri& lhs, const yuri& rhs) {
return (lhs.num*rhs.den>=lhs.den*rhs.num);
}
friend ostream& operator << (ostream &os, const yuri& rhs) noexcept {
if(rhs.den==1)return os << rhs.num;
return os << rhs.num << '/' << rhs.den;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
vector<ll> b(3);
for(auto &&v:b)cin >> v;
ll d0 = b[1] - b[0], d1 = b[2] - b[1];
yuri r(d1, d0), d = b[1] - b[0] * r;
cout << r * b[2] + d << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0