結果

問題 No.70 睡眠の重要性!
ユーザー ut0sut0s
提出日時 2019-09-10 14:30:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,196 bytes
コンパイル時間 1,718 ms
コンパイル使用メモリ 172,656 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 13:04:18
合計ジャッジ時間 2,338 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

/**
  @file 070.cpp
  @title  No.70 睡眠の重要性! - yukicoder
  @url https://yukicoder.me/problems/no/70
**/

#include <bits/stdc++.h>
using namespace std;

typedef long long LL;
#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, N) for (int i = 0; i < (N); ++i)

vector<string> split(string S) {
  auto separator        = string(":");
  auto separator_length = separator.length();

  auto list = vector<string>();

  auto offset = string::size_type(0);
  while (1) {
    auto pos = S.find(separator, offset);
    if (pos == string::npos) {
      list.push_back(S.substr(offset));
      break;
    }
    list.push_back(S.substr(offset, pos - offset));
    offset = pos + separator_length;
  }

  return list;
}

int main() {
  int N;
  cin >> N;
  vector<pair<string, string>> time(N, make_pair("", ""));
  REP(i, N) {
    cin >> time[i].first >> time[i].second;
  }

  LL sleep{0};
  REP(i, N) {
    auto neru  = split(time[i].first);
    auto okiru = split(time[i].second);

    LL s0 = (stoi(neru[0]) * 60 + stoi(neru[1]));
    LL s1 = (stoi(okiru[0]) * 60 + stoi(okiru[1]));
    sleep += s1 - s0 >= 0 ? s1 - s0 : s1 + 24 * 60 - s0;
  }

  cout << sleep << endl;
  return 0;
}
0