結果
| 問題 |
No.220 世界のなんとか2
|
| コンテスト | |
| ユーザー |
nenuon
|
| 提出日時 | 2017-07-22 15:05:57 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 882 bytes |
| コンパイル時間 | 863 ms |
| コンパイル使用メモリ | 91,420 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-10-09 09:52:30 |
| 合計ジャッジ時間 | 1,691 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
typedef long long ll;
ll dp[100][2][2][3]; // みた桁数、小さいことが確定してるか、3がつくか、3の倍数か
int main()
{
int P;
cin>>P;
string s('0',P);
s = '1' + s;
int len = P + 1;
dp[0][0][0][0] = 1;
FOR(i,0,len) FOR(j,0,2) FOR(k,0,2) FOR(l,0,3) {
int lim = j ? 9 : s[i] - '0';
FOR(d,0,lim+1) {
dp[i+1][j||d<lim][k||d==3][(l+d)%3] += dp[i][j][k][l];
}
}
ll ans = 0;
FOR(j,0,2) FOR(k,0,2) FOR(l,0,3){
if(k || l==0)
ans += dp[len][j][k][l];
}
cout << ans - 1 << endl;
return 0;
}
nenuon