結果

問題 No.533 Mysterious Stairs
ユーザー Jumbo_kprJumbo_kpr
提出日時 2019-07-20 04:18:34
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 1,940 bytes
コンパイル時間 973 ms
コンパイル使用メモリ 102,012 KB
実行使用メモリ 34,592 KB
最終ジャッジ日時 2023-08-27 07:39:50
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 9 ms
6,948 KB
testcase_21 AC 10 ms
7,260 KB
testcase_22 AC 27 ms
15,384 KB
testcase_23 AC 66 ms
34,268 KB
testcase_24 AC 65 ms
34,592 KB
testcase_25 AC 10 ms
6,852 KB
testcase_26 AC 57 ms
30,252 KB
testcase_27 AC 18 ms
11,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define m0(x) memset(x,0,sizeof(x))
#define print(x) cout<<x<<'\n';
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
#define ub(v,n) upper_bound(v.begin(), v.end(), n);
#define int long long
//#define int unsigned long long
#define all(x) (x).begin(), (x).end()
#define double long double

using namespace std;

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

int MOD = 1e9 + 7;
const ll INF = 1e17;
const double pi = acos(-1);
const double EPS = 1e-10;
typedef pair<int, int>P;
const int MAX = 200020;


int dp[1000100][4];
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	dp[1][1] = 1;
	dp[2][2] = 1;
	dp[3][3] = 1;
	int N; cin >> N;
	FOR(i, 1, N + 1) {
		dp[i][1] += dp[i - 1][2] + dp[i - 1][3];
		dp[i][1] %= MOD;
		if (i >= 2) {
			dp[i][2] += dp[i - 2][1] + dp[i - 2][3];
			dp[i][2] %= MOD;
		}
		if (i >= 3) {
			dp[i][3] += dp[i - 3][1] + dp[i - 3][2];
			dp[i][3] %= MOD;
		}
	}
	int ans = dp[N][1] + dp[N][2] + dp[N][3];
	ans %= MOD;
	print(ans);
}
0