結果

問題 No.894 二種類のバス
ユーザー NoiriNoiri
提出日時 2019-09-27 22:20:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 873 bytes
コンパイル時間 1,511 ms
コンパイル使用メモリ 169,096 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 22:29:12
合計ジャッジ時間 2,359 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:36:13:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'lcm' may be used uninitialized [-Wmaybe-uninitialized]
  202 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:33:8: note: 'lcm' was declared here
   33 |     ll lcm;
      |        ^~~

ソースコード

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);
    cout << lcm << endl;

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

    cout << ans << endl;
}
0