結果

問題 No.70 睡眠の重要性!
ユーザー NoiriNoiri
提出日時 2024-01-13 20:40:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,329 bytes
コンパイル時間 1,721 ms
コンパイル使用メモリ 170,464 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-01-13 20:41:01
合計ジャッジ時間 2,348 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:39:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   39 |         auto [sp_h, sp_m] = parser(sp);
      |              ^
main.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   40 |         auto [wu_h, wu_m] = parser(wu);
      |              ^
main.cpp: In function 'std::pair<int, int> parser(std::string)':
main.cpp:26:17: warning: 'h' may be used uninitialized [-Wmaybe-uninitialized]
   26 |     return {h, m};
      |                 ^
main.cpp:14:9: note: 'h' was declared here
   14 |     int h, m;
      |         ^

ソースコード

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() );
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
using ll = long long;

pair<int, int> parser(string s){
    int h, m;
    string tmp = "";
    for(int i = 0; i < s.size(); i++){
        if(s[i] == ':'){
            h = stoi(tmp);
            tmp = "";
            continue;
        }
        tmp += (""s + s[i]);
    }
    m = stoi(tmp);

    return {h, m};
}


int main(){
    int n; 
    cin >> n;

    int ans = 0;
    for(int i = 0; i < n; i++){
        string sp, wu;
        cin >> sp >> wu;

        auto [sp_h, sp_m] = parser(sp);
        auto [wu_h, wu_m] = parser(wu);

        if(sp_h < wu_h){
            ans += (wu_h - sp_h - 1)*60 + (60 - sp_m) + wu_m;
        }
        else if(sp_h == wu_h){
            if(sp_m <= wu_m) ans += (wu_m - sp_m);
            else ans += 23*60 + (60 - sp_m) + wu_m;
        }
        else{
            ans += (24 - sp_h - 1)*60 + (60 - sp_m) + wu_h*60 + wu_m;
        }
    }

    cout << ans << endl;
}
0