結果

問題 No.220 世界のなんとか2
ユーザー ooaiu
提出日時 2025-08-17 18:07:56
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 558 bytes
コンパイル時間 3,307 ms
コンパイル使用メモリ 278,672 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-08-17 18:08:00
合計ジャッジ時間 3,582 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace std;
using mint = atcoder::static_modint<9+(int)1e9>;
using ll = long long;
ll dp[22][3][2];
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(nullptr);
	int P;
	cin>>P;
	dp[0][0][0]=1;
	for(int i=0;i<P;i++)for(int r3=0;r3<3;r3++)for(int has3=0;has3<2;has3++){
		for(int d=0;d<=9;d++){
			dp[i+1][(r3+d)%3][has3||d==3]+=dp[i][r3][has3];
		}
	}
	ll ans=0;
	for(int i=0;i<2;i++)ans+=dp[P][0][i];
	for(int i=0;i<3;i++)ans+=dp[P][i][1];
	ans-=dp[P][0][1]+1;
	cout<<ans<<endl;
}
0