結果
| 問題 |
No.1236 長針と短針
|
| コンテスト | |
| ユーザー |
Tatsu_mr
|
| 提出日時 | 2024-10-26 15:14:01 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 3,410 bytes |
| コンパイル時間 | 3,157 ms |
| コンパイル使用メモリ | 246,428 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-26 15:14:06 |
| 合計ジャッジ時間 | 4,461 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 20 |
ソースコード
#include <bits/stdc++.h>
#define For(i, a, b) for(long long i = a; i < b; i++)
#define rep(i, n) For(i, 0, n)
#define rFor(i, a, b) for(long long i = a; i >= b; i--)
#define ALL(v) (v).begin(), (v).end()
#define rALL(v) (v).rbegin(), (v).rend()
using namespace std;
using lint = long long;
using ld = long double;
int INF = 2000000000;
lint LINF = 1000000000000000000;
struct Fraction {
using lint = long long;
private:
lint gcd(lint x, lint y) {
if (y == 0) {
return x;
}
return gcd(y, x % y);
}
void reduce() {
if (p != 0) {
lint g = gcd(abs(p), abs(q));
p /= g;
q /= g;
} else {
q = 1;
}
}
int comp(lint a, lint b, lint c, lint d) const {
if (a == c && b == d) {
return 0;
}
return (a * d < c * b ? -1 : 1);
}
public:
lint p, q;
Fraction() : p(0), q(1) {}
Fraction(lint p_, lint q_) : p(p_), q(q_) {
assert(q_ != 0);
if (q < 0) {
p = -p;
q = -q;
}
reduce();
}
Fraction(lint p_) : p(p_), q(1) {}
Fraction &operator+=(const Fraction &a) {
lint np = p * a.q + q * a.p;
lint nq = q * a.q;
*this = Fraction(np, nq);
return *this;
}
Fraction &operator-=(const Fraction &a) {
lint np = p * a.q - q * a.p;
lint nq = q * a.q;
*this = Fraction(np, nq);
return *this;
}
Fraction &operator*=(const Fraction &a) {
lint np = p * a.p;
lint nq = q * a.q;
*this = Fraction(np, nq);
return *this;
}
Fraction &operator/=(const Fraction &a) {
assert(a.p != 0);
lint np = p * a.q;
lint nq = q * a.p;
*this = Fraction(np, nq);
return *this;
}
Fraction operator+(const Fraction &a) {
return Fraction(*this) += a;
}
Fraction operator-(const Fraction &a) {
return Fraction(*this) -= a;
}
Fraction operator*(const Fraction &a) {
return Fraction(*this) *= a;
}
Fraction operator/(const Fraction &a) {
return Fraction(*this) /= a;
}
Fraction operator-() {
p = -p;
return *this;
}
bool operator==(const Fraction &a) const {
return comp(p, q, a.p, a.q) == 0;
}
bool operator!=(const Fraction &a) const {
return comp(p, q, a.p, a.q) != 0;
}
bool operator<(const Fraction &a) const {
return comp(p, q, a.p, a.q) == -1;
}
bool operator>(const Fraction &a) const {
return comp(p, q, a.p, a.q) == 1;
}
bool operator<=(const Fraction &a) const {
return comp(p, q, a.p, a.q) <= 0;
}
bool operator>=(const Fraction &a) const {
return comp(p, q, a.p, a.q) >= 0;
}
friend ostream &operator<<(ostream &os, Fraction a) {
return os << a.p << "/" << a.q;
}
};
int main() {
int a, b;
cin >> a >> b;
if (a >= 12) {
a -= 12;
}
Fraction sht(1, 120), lng(1, 10);
sht *= Fraction((a * 60 + b) * 60);
lng *= Fraction(b * 60);
Fraction d = sht - lng;
if (d < Fraction(0)) {
d += Fraction(360);
}
Fraction ans = d / Fraction(11, 120);
cout << ans.p / ans.q << endl;
}
Tatsu_mr