結果
問題 | No.1236 長針と短針 |
ユーザー |
![]() |
提出日時 | 2020-09-28 21:03:31 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 46 ms / 2,000 ms |
コード長 | 9,069 bytes |
コンパイル時間 | 1,934 ms |
コンパイル使用メモリ | 194,916 KB |
最終ジャッジ日時 | 2025-01-14 23:17:54 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
/* #region Head */// #define _GLIBCXX_DEBUG#include <bits/stdc++.h>using namespace std;using ll = long long;using ull = unsigned long long;using ld = long double;using pll = pair<ll, ll>;template <class T> using vc = vector<T>;template <class T> using vvc = vc<vc<T>>;using vll = vc<ll>;using vvll = vvc<ll>;using vld = vc<ld>;using vvld = vvc<ld>;using vs = vc<string>;using vvs = vvc<string>;template <class T, class U> using um = unordered_map<T, U>;template <class T> using pq = priority_queue<T>;template <class T> using pqa = priority_queue<T, vc<T>, greater<T>>;template <class T> using us = unordered_set<T>;#define REP(i, m, n) for (ll i = (m), i##_len = (ll)(n); i < i##_len; ++(i))#define REPM(i, m, n) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; ++(i))#define REPR(i, m, n) for (ll i = (m), i##_min = (ll)(n); i >= i##_min; --(i))#define REPD(i, m, n, d) for (ll i = (m), i##_len = (ll)(n); i < i##_len; i += (d))#define REPMD(i, m, n, d) for (ll i = (m), i##_max = (ll)(n); i <= i##_max; i += (d))#define REPI(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)#define ALL(x) begin(x), end(x)#define SIZE(x) ((ll)(x).size())#define PERM(c) \sort(ALL(c)); \for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))#define UNIQ(v) v.erase(unique(ALL(v)), v.end());#define endl '\n'#define sqrt sqrtl#define floor floorl#define log2 log2lconstexpr ll INF = 1'010'000'000'000'000'017LL;constexpr int IINF = 1'000'000'007LL;constexpr ll MOD = 1'000'000'007LL; // 1e9 + 7// constexpr ll MOD = 998244353;constexpr ld EPS = 1e-12;constexpr ld PI = 3.14159265358979323846;template <typename T> istream &operator>>(istream &is, vc<T> &vec) { // vector 入力for (T &x : vec) is >> x;return is;}template <typename T> ostream &operator<<(ostream &os, vc<T> &vec) { // vector 出力 (for dump)os << "{";REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "" : ", ");os << "}";return os;}template <typename T> ostream &operator>>(ostream &os, vc<T> &vec) { // vector 出力 (inline)REP(i, 0, SIZE(vec)) os << vec[i] << (i == i_len - 1 ? "\n" : " ");return os;}template <typename T, typename U> istream &operator>>(istream &is, pair<T, U> &pair_var) { // pair 入力is >> pair_var.first >> pair_var.second;return is;}template <typename T, typename U> ostream &operator<<(ostream &os, pair<T, U> &pair_var) { // pair 出力os << "(" << pair_var.first << ", " << pair_var.second << ")";return os;}// map, um, set, us 出力template <class T> ostream &out_iter(ostream &os, T &map_var) {os << "{";REPI(itr, map_var) {os << *itr;auto itrcp = itr;if (++itrcp != map_var.end()) os << ", ";}return os << "}";}template <typename T, typename U> ostream &operator<<(ostream &os, map<T, U> &map_var) { return out_iter(os, map_var); }template <typename T, typename U> ostream &operator<<(ostream &os, um<T, U> &map_var) {os << "{";REPI(itr, map_var) {auto [key, value] = *itr;os << "(" << key << ", " << value << ")";auto itrcp = itr;if (++itrcp != map_var.end()) os << ", ";}os << "}";return os;}template <typename T> ostream &operator<<(ostream &os, set<T> &set_var) { return out_iter(os, set_var); }template <typename T> ostream &operator<<(ostream &os, us<T> &set_var) { return out_iter(os, set_var); }template <typename T> ostream &operator<<(ostream &os, pq<T> &pq_var) {pq<T> pq_cp(pq_var);os << "{";if (!pq_cp.empty()) {os << pq_cp.top(), pq_cp.pop();while (!pq_cp.empty()) os << ", " << pq_cp.top(), pq_cp.pop();}return os << "}";}// dump#define DUMPOUT cerrvoid dump_func() { DUMPOUT << endl; }template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) {DUMPOUT << head;if (sizeof...(Tail) > 0) DUMPOUT << ", ";dump_func(move(tail)...);}// chmax (更新「される」かもしれない値が前)template <typename T, typename U, typename Comp = less<>> bool chmax(T &xmax, const U &x, Comp comp = {}) {if (comp(xmax, x)) {xmax = x;return true;}return false;}// chmin (更新「される」かもしれない値が前)template <typename T, typename U, typename Comp = less<>> bool chmin(T &xmin, const U &x, Comp comp = {}) {if (comp(x, xmin)) {xmin = x;return true;}return false;}// ローカル用#define DEBUG_#ifdef DEBUG_#define DEB#define dump(...) \DUMPOUT << " " << string(#__VA_ARGS__) << ": " \<< "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \<< " ", \dump_func(__VA_ARGS__)#else#define DEB if (false)#define dump(...)#endif#define VAR(type, ...) \type __VA_ARGS__; \cin >> __VA_ARGS__;template <typename T> istream &operator,(istream &is, T &rhs) { return is >> rhs; }template <typename T> ostream &operator,(ostream &os, const T &rhs) { return os << ' ' << rhs; }struct AtCoderInitialize {static constexpr int IOS_PREC = 15;static constexpr bool AUTOFLUSH = false;AtCoderInitialize() {ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);cout << fixed << setprecision(IOS_PREC);if (AUTOFLUSH) cout << unitbuf;}} ATCODER_INITIALIZE;void Yn(bool p) { cout << (p ? "Yes" : "No") << endl; }void YN(bool p) { cout << (p ? "YES" : "NO") << endl; }/* #endregion */// #include <atcoder/all>// using namespace atcoder;/* #region AnalogClock */// h 時 m 分 s 秒の時計の状態を表すクラスtemplate <typename sec_t, typename slope_t = ll, typename len_t = ld> struct AnalogClock {static constexpr ll Y_MAX = 3600 * 12;sec_t s; // 00:00:00 からの秒数len_t len_s; // 秒針の長さlen_t len_m; // 分針(長針)の長さlen_t len_h; // 時針(短針)の長さAnalogClock(ll h, ll m, sec_t s, len_t len_s = 1, len_t len_m = 1, len_t len_h = 1): s(0), len_s(len_s), len_m(len_m), len_h(len_h) {init(h, m, s);}void init(ll h, ll m, const sec_t s) {h += m / 60;m %= 60;h %= 12;this->s = h * 3600 + m * 60 + s;if (this->s > 3600 * 12) { // 念の為ll q = (ll)(this->s / 3600 * 12);this->s -= 3600 * 12 * q;}}// 秒針は傾き 12*60=720 の直線// 分針(長針)は傾き 12 の直線// 時針(短針)は傾き 1 の直線pair<sec_t, sec_t> _get_heights(const slope_t slope0, const slope_t slope1) const noexcept {assert(slope0 < slope1);sec_t y_0 = s * slope0;sec_t y_1 = s * slope1;ll q_0 = (ll)(y_0 / Y_MAX);ll q_1 = (ll)(y_1 / Y_MAX);y_0 -= Y_MAX * q_0;y_1 -= Y_MAX * q_1;while (y_0 < 0) y_0 += Y_MAX;while (y_1 < 0) y_1 += Y_MAX;while (y_0 > Y_MAX) y_0 -= Y_MAX;while (y_1 > Y_MAX) y_1 -= Y_MAX;if (y_1 > y_0) y_1 -= Y_MAX;return {y_0, y_1};}// 時針(長針)の角速度を傾きの 1 単位としたとき,2つの針の速度の傾きから,交差するまでの時間を求めるsec_t intersect_by_slope(slope_t slope0, slope_t slope1) const noexcept {assert(slope0 > 0);assert(slope1 > 0);if (slope0 == slope1) return 0;if (slope0 > slope1) swap(slope0, slope1);// assert slope1 の傾きのほうが大きいauto [y_0, y_1] = _get_heights(slope0, slope1);return (y_0 - y_1) / (slope1 - slope0);}// 時針(短針)と分針(長針)が何秒後に交差するかを返すsec_t intersect_h_m() const { return intersect_by_slope(1, 12); }// 分針(長針)と秒針が何秒後に交差するかを返すsec_t intersect_m_s() const { return intersect_by_slope(12, 12 * 60); }// 時針(短針)と秒針が何秒後に交差するかを返すsec_t intersect_h_s() const { return intersect_by_slope(1, 12 * 60); }};/* #endregion */// Problemvoid solve() {VAR(ll, a, b);AnalogClock<ll> clk(a, b, 0);cout << clk.intersect_h_m() << endl;}// entry pointint main() {solve();return 0;}