結果

問題 No.188 HAPPY DAY
ユーザー tonegawatonegawa
提出日時 2020-08-11 06:04:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,799 bytes
コンパイル時間 895 ms
コンパイル使用メモリ 101,548 KB
実行使用メモリ 4,376 KB
最終ジャッジ日時 2023-07-30 15:56:16
合計ジャッジ時間 1,311 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvvl vector<vvl>
#define vvl vector<vector<ll>>
#define VV(a, b, c, d) vector<vector<d>>(a, vector<d>(b, c))
#define VVV(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef long long int ll;
typedef long double ld;
using namespace std;

namespace D{
  static vll month{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  static ll add(ll y, ll m){
    if(m!=2) return 0;
    if(y%400==0) return 1;
    if(y%100==0) return 0;
    if(y%4==0) return 1;
    return 0;
  }
  struct day{
    ll y, m, d;
    day(){}
    day(string s){
      ll mode = 0;
      string t = "";
      re(i, s.size()){
        if(mode==0&&s[i]=='/') {
          y = stoll(t), t = "", mode = 1;
          continue;
        }
        if(mode==1&&s[i]=='/') {
          m = stoll(t), t = "", mode = 2;
          continue;
        }
        if(!(s[i]=='0'&&t=="")) t+=s[i];
        if(i==s.size()-1) d = stoll(t);
      }
    }
    day(ll Y, ll M, ll D){
      y = Y, m = M, d = D;
    }
    day next(){
      ll X = y, Y = m, Z = d;
      Z++;
      if(Z>month[Y]+add(X, Y)) Y++, Z = 1;
      if(Y>=month.size()) X++, Y = 1;
      return day(X, Y, Z);
    }
    string print_(){
      string a = to_string(y), b = to_string(m), c = to_string(d);
      a += '/';
      if(b.size()==1) a+='0';
      a+=b;
      a+='/';
      if(c.size()==1) a+='0';
      a+=c;
      return a;
    }
  };
  struct calender{
    ll T_y, T_m, T_d;
    day INI;
    vector<day> table;
    map<vll, ll> p;
    calender(day i, ll y=400, ll d = -1){
      T_y = 400, INI = i;
      init(T_y);
      T_d = table.size();
    }
    void init(ll T){
      day now = INI;
      ll c = 0;
      while(now.y!=INI.y+T_y||now.m!=INI.m||now.d!=INI.d){
        table.push_back(now);
        p.emplace(vll{now.y, now.m, now.d}, c);
        now = now.next(), c++;
      }
    }
    day step(ll num){
      day now = table[num%T_d];
      return day(now.y+(num/T_d)*T_y, now.m, now.d);
    }
    ll passd(day now){
      ll py = now.y - INI.y - (now.m==INI.m?now.d>=INI.d?0:1:now.m>INI.m?0:1);
      ll ret = (py/T_y)*T_d;
      day target(now.y - (py/T_y)*T_y, now.m, now.d);
      ret += p.at(vll{target.y, target.m, target.d});
      return ret;
    }
  };
}
using namespace D;

int main(int argc, char const *argv[]) {
  day d = day("2015/01/01");
  ll ans = 0;
  while(d.y==2015){
    //std::cout << d.y << " " << d.m << " " << d.d << '\n';
    if(d.m==d.d%10+d.d/10) ans++;
    d = d.next();
  }
  std::cout << ans << '\n';
}
0