結果
問題 | No.220 世界のなんとか2 |
ユーザー | Ryu |
提出日時 | 2018-02-18 16:16:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 1,145 bytes |
コンパイル時間 | 853 ms |
コンパイル使用メモリ | 84,008 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-24 14:08:15 |
合計ジャッジ時間 | 1,560 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 19 |
ソースコード
#include <iostream> #include <algorithm> #include <vector> #include <map> #include <string> #include <numeric> #include <cstring> #include <cmath> #include <set> #include <queue> #include <stack> const int MOD = 1e9 + 7; const int iINF = 1000000000; const long long int llINF = 1000000000000000000; #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long int; using P = pair<int, int>; using edge = struct { int to; int cost; }; int main() { int P; cin >> P; ll dp[30][2][2][3]; memset(dp, 0, sizeof(dp)); dp[0][0][0][0] = 1; rep(i, P + 1) { rep(j, 2) { int lim; if (j == 1) lim = 9; else if (j == 0 && i == 0) lim = 1; else lim = 0; rep(k, 2) rep(l, 3) rep(d, lim + 1) dp[i + 1][j || d < lim][k || d == 3][(l + d) % 3] += dp[i][j][k][l]; } } ll ans = 0; rep(j, 2) rep(k, 2) rep(l, 3) { if(k == 1 || l == 0) ans += dp[P + 1][j][k][l]; } printf("%lld\n", ans - 1); }