結果

問題 No.70 睡眠の重要性!
ユーザー not_522not_522
提出日時 2015-07-14 20:21:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 2,520 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 143,724 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-22 15:45:18
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

namespace arithmetic {
  template<typename T> class Addition {
  public:
    template<typename V> T operator+(const V& v) const {
      T res(static_cast<const T&>(*this));
      return res += static_cast<T>(v);
    }
  };

  template<typename T> class Subtraction {
  public:
    template<typename V> T operator-(const V& v) const {
      T res(static_cast<const T&>(*this));
      return res -= static_cast<T>(v);
    }
  };

  template<typename T> class Multiplication {
  public:
    template<typename V> T operator*(const V& v) const {
      T res(static_cast<const T&>(*this));
      return res *= static_cast<T>(v);
    }
  };

  template<typename T> class Division {
  public:
    template<typename V> T operator/(const V& v) const {
      T res(static_cast<const T&>(*this));
      return res /= static_cast<T>(v);
    }
  };

  template<typename T> class Modulus {
  public:
    template<typename V> T operator%(const V& v) const {
      T res(static_cast<const T&>(*this));
      return res %= static_cast<T>(v);
    }
  };
}

template<typename T> class IndivisibleArithmetic : public arithmetic::Addition<T>, public arithmetic::Subtraction<T>, public arithmetic::Multiplication<T> {};

template<typename T> class Arithmetic : public IndivisibleArithmetic<T>, public arithmetic::Division<T> {};

struct Time : public arithmetic::Addition<Time>, public arithmetic::Subtraction<Time> {
  int hour, minute, second;

  Time() : hour(0), minute(0), second(0) {}

  Time(int hour, int minute, int second) : hour(hour), minute(minute), second(second) {}

  int toMinutes() const {
    return hour * 60 + minute;
  }

  int toSeconds() {
    return toMinutes() * 60 + second;
  }

  void normalize() {
    if (second < 0) {
      --minute;
      second += 60;
    }
    if (minute < 0) {
      --hour;
      minute += 60;
    }
  }

  Time operator+=(const Time& time) {
    hour += time.hour;
    minute += time.minute;
    second += time.second;
    normalize();
    return *this;
  }

  Time operator-=(const Time& time) {
    hour -= time.hour;
    minute -= time.minute;
    second -= time.second;
    normalize();
    return *this;
  }
};

int main() {
  int n, res = 0;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    Time t1, t2;
    cin >> t1.hour;
    cin.ignore();
    cin >> t1.minute >> t2.hour;
    cin.ignore();
    cin >> t2.minute;
    t2 -= t1;
    if (t2.toMinutes() < 0) t2 += Time(24, 0, 0);
    res += t2.toMinutes();
  }
  cout << res << endl;
}
0