結果

問題 No.894 二種類のバス
ユーザー NoiriNoiri
提出日時 2019-09-27 22:20:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 848 bytes
コンパイル時間 2,983 ms
コンパイル使用メモリ 168,532 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 22:33:18
合計ジャッジ時間 2,177 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 1 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
testcase_16 AC 2 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 2 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

ll gcd;

bool overflow(ll a, ll b){
    ll M = 1e18;
    if(a < b) swap(a, b);
    b /= gcd;
    string s = to_string(a);
    bool over = false;
    rep(i, s.size()-1){
        ll x = stoll(s.substr(0, i+1));
        if(x * b > M){
            over = true;
            break;
        }
    }
    
    return over;
}

int main(){
    ll t, a, b;
    cin >> t >> a >> b;
    gcd = __gcd(a, b);
    bool ok = !overflow(a, b);
    ll lcm;
    if(ok) lcm = a / gcd * b;
    ll ans = 1 + t/a + t/b - (t%a==0) - (t%b==0);

    if(ok) ans += -t/lcm + (t%lcm == 0);

    cout << ans << endl;
}
0