結果

問題 No.314 ケンケンパ
コンテスト
ユーザー naimonon77
提出日時 2015-12-12 17:42:45
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 5 ms / 1,000 ms
コード長 958 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 587 ms
コンパイル使用メモリ 91,484 KB
実行使用メモリ 11,392 KB
最終ジャッジ日時 2026-04-04 18:46:36
合計ジャッジ時間 1,321 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge5_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long unsigned int) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:54:11:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:216:25: warning: 'rep' may be used uninitialized [-Wmaybe-uninitialized]
  216 |       { return _M_insert(__n); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:37:7: note: 'rep' was declared here
   37 |   ull rep;
      |       ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <cstring>
#include <algorithm>
#include <limits.h>
#include <cmath>
#include <time.h>
#include <functional>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define MOD1 1000000007;
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
/* ここからが本編 */
/*  */
ull dp[1000005];
// dp[i]はiがパーで終わる奴
void solve(int n)
{
  int i;
  dp[0] = 1; //便宜上
  dp[1] = 0;
  dp[2] = 1;
  dp[3] = 1;
  dp[4] = 1;
  for(i=5;i<n+1;i++) {
    dp[i] = (dp[i-2] + dp[i-3])%MOD1 ;
  }
}
int main(void)
{
  int test = 0;
  int i,j,k,l;
  int N;
  ull rep;
  cin >> N;
  solve(N);
  if(test) {
    for(i=0;i<N+1;i++) {
      printf("dp[%d] = %llu\n",i,dp[i]);
    }
  }
  if(N > 2) {
    rep = (dp[N] + dp[N-1] + dp[N-2]) %MOD1;
  }
  else {
    switch(N) {
    case 2: rep = 2;break;
    case 1: rep = 1;break;
    }
  }
  cout << rep << endl;
  return 0;
}
0