結果

問題 No.533 Mysterious Stairs
ユーザー mMqrMruYrNII4TdmMqrMruYrNII4Td
提出日時 2017-06-26 19:05:02
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 11 ms / 5,000 ms
コード長 1,138 bytes
コンパイル時間 507 ms
コンパイル使用メモリ 66,536 KB
実行使用メモリ 27,088 KB
最終ジャッジ日時 2024-04-15 01:54:29
合計ジャッジ時間 1,346 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 1 ms
6,944 KB
testcase_19 AC 1 ms
6,940 KB
testcase_20 AC 3 ms
7,376 KB
testcase_21 AC 4 ms
6,944 KB
testcase_22 AC 6 ms
12,972 KB
testcase_23 AC 11 ms
26,580 KB
testcase_24 AC 11 ms
27,088 KB
testcase_25 AC 3 ms
6,940 KB
testcase_26 AC 10 ms
23,972 KB
testcase_27 AC 4 ms
10,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;

#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)

long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}

long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }

typedef long long ll;
 
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

ll c[1000001][3];

int main(){
	ll n;
	
	cin >> n;
	
	c[0][0] = 0; c[0][1] = 0; c[0][2] = 0;
	c[1][0] = 1; c[1][1] = 0; c[1][2] = 0;
	c[2][0] = 0; c[2][1] = 1; c[2][2] = 0;
	c[3][0] = 1; c[3][1] = 1; c[3][2] = 1;
	
	FOR(i,4,n+1){
		c[i][0] = (c[i-1][1] + c[i-1][2])%MOD;
		c[i][1] = (c[i-2][0] + c[i-2][2])%MOD;
		c[i][2] = (c[i-3][0] + c[i-3][1])%MOD;
	}
	
	printf("%lld\n", (c[n][0]+c[n][1]+c[n][2])%MOD);
	
	return 0;
}
0