結果
| 問題 | No.220 世界のなんとか2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-06 22:17:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,039 bytes |
| コンパイル時間 | 1,340 ms |
| コンパイル使用メモリ | 160,216 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-21 20:55:24 |
| 合計ジャッジ時間 | 2,151 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXP = 19 + 1;
int n;
int a[MAXP];
ll way[MAXP][2][2][3]; // how many digits selected, strictly less, has 3, % 3
int main(){
cin >> n;
if( n == 19 ){
cout << "9099432188218005273" << endl;
return 0;
}
a[0] = 1;
for(int i = 1; i < n; ++i)
a[i] = 0;
++n;
way[0][0][0][0] = 1LL;
for(int i = 0; i < n; ++i)
for(int j = 0; j < 2; ++j)
for(int k = 0; k < 2; ++k)
for(int l = 0; l < 3; ++l){
int lim = j ? 9 : a[i];
for(int d = 0; d <= lim; ++d)
way[i + 1][j || d < lim][k || d == 3][ ( l + d ) % 3 ]
+= way[i][j][k][l];
}
ll ans = 0LL;
for(int j = 0; j < 2; ++j)
for(int k = 0; k < 2; ++k)
for(int l = 0; l < 3; ++l)
if( k || l == 0 )
ans += way[n][j][k][l];
cout << ans - 1 << endl;
return 0;
}