結果

問題 No.70 睡眠の重要性!
ユーザー f843nmfwisfeuwf843nmfwisfeuw
提出日時 2020-07-29 20:39:50
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,594 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 96,792 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-12 15:32:20
合計ジャッジ時間 1,487 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>

using namespace std;

// 00:00からの差が何分かを考える
// 日またぎ
// 起きた時間 <= 寝た時間
// 日またぎしない

// 1日は24*60分
// 起きた時間 >= 寝た時間

int asMinute(int h, int m) {
    return h * 60 + m;
}

vector<string> split(string s, const string &delimiter) {
    size_t pos_start = 0, pos_end, delim_len = delimiter.length();
    string token;
    vector<string> res;

    while ((pos_end = s.find(delimiter, pos_start)) != string::npos) {
        token = s.substr(pos_start, pos_end - pos_start);
        pos_start = pos_end + delim_len;
        res.push_back(token);
    }

    res.push_back(s.substr(pos_start));
    return res;
}

int main() {

    int N;
    cin >> N;
    int result = 0;
    for (int i = 0; i < N; ++i) {
        string S1, S2;
        cin >> S1 >> S2;

        vector<string> ss1 = split(S1, ":");
        vector<string> ss2 = split(S2, ":");
        int H = stoi(ss1[0]);
        int M = stoi(ss1[1]);
        int h = stoi(ss2[0]);
        int m = stoi(ss2[1]);

        int sleep = asMinute(H, M);
        int wakeUp = asMinute(h, m);

        if (sleep < wakeUp) {
            result += (wakeUp - sleep);
        } else if (wakeUp == sleep) {
            continue;
        } else {
            result += ((wakeUp + 24 * 60) - sleep);
        }
    }

    cout << result << endl;

    return 0;
}
0