結果

問題 No.87 Advent Calendar Problem
ユーザー kk
提出日時 2020-10-14 19:55:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,115 bytes
コンパイル時間 2,088 ms
コンパイル使用メモリ 199,020 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 00:45:07
合計ジャッジ時間 3,433 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:53:14: 警告: ‘block’ may be used uninitialized [-Wmaybe-uninitialized]
   53 |     ret += t * block;
      |            ~~^~~~~~~
main.cpp:36:13: 備考: ‘block’ はここで定義されています
   36 |   long long block;
      |             ^~~~~
main.cpp:52:12: 警告: ‘cyc’ may be used uninitialized [-Wmaybe-uninitialized]
   52 |     y += t * cyc;
      |          ~~^~~~~
main.cpp:35:13: 備考: ‘cyc’ はここで定義されています
   35 |   long long cyc;
      |             ^~~

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for (int i=(int)(b); i<(int)(e); i++)
#define ALL(x) (x).begin(), (x).end()

const double PI = acos(-1);

int zeller(long long y, int m, int d) {
  if (m == 1 || m == 2) {
    m += 12;
    --y;
  }
  int h = (d + (13 * (m + 1)) / 5 + y + y / 4 - y / 100 + y / 400) % 7;
  return h;
}

long long dp[400][7];
long long sum[400][7];

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  
  long long n;
  cin >> n;

  ++n;
  int h0 = zeller(2014, 7, 23);
  long long ret = 0;
  
  long long y;
  long long cyc;
  long long block;

  for (y = 2015; y < n; y++) {
    int h = zeller(y, 7, 23);
    ret += h == h0;
    if (dp[y%400][h]) {
      cyc = y - dp[y%400][h];
      block = ret - sum[y%400][h];
      break;
    }
    dp[y%400][h] = y;
    sum[y%400][h] = ret;
  }

  if (y < n) {
    long long t = (n - y) / cyc;
    y += t * cyc;
    ret += t * block;
    
    while (y < n) {
      if (zeller(y, 7, 23) == h0)
        ++ret;
      ++y;
    }
  }
  
  cout << ret << endl;

  return 0;
}
0