結果
| 問題 | No.220 世界のなんとか2 |
| コンテスト | |
| ユーザー |
uenoku
|
| 提出日時 | 2017-01-31 01:58:44 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,031 bytes |
| 記録 | |
| コンパイル時間 | 859 ms |
| コンパイル使用メモリ | 84,964 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-24 00:09:31 |
| 合計ジャッジ時間 | 1,945 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 9 WA * 9 RE * 1 |
ソースコード
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long int lli;
lli MOD = 1000000007;
int main()
{
int p;
cin >> p;
string s = "1";
int n = p + 1;
rep(i, p) s += "0";
lli dp[20][2][3][2] = {}; //pos,less,mod,has3
dp[0][0][0][0] = 1;
rep(i, p + 1) rep(j, 2) rep(k, 3) rep(l, 2)
{
int lim = j ? 9 : s[i] - '0';
rep(m, lim + 1)
{
dp[i + 1][j || m < lim][(k + m) % 3][l || m == 3] += dp[i][j][k][l];
dp[i + 1][j || m < lim][(k + m) % 3][l || m == 3] %= MOD;
}
}
lli a = 0;
rep(j, 2)
{
rep(l, 2)
{
rep(k, 3)
{
if (l || k == 0)
a += dp[p + 1][j][k][l];
}
}
}
cout << (a - 1 + MOD) % MOD << endl;
}
uenoku