結果
| 問題 |
No.220 世界のなんとか2
|
| コンテスト | |
| ユーザー |
aim_cpo
|
| 提出日時 | 2017-09-10 23:33:40 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 1,274 bytes |
| コンパイル時間 | 932 ms |
| コンパイル使用メモリ | 91,316 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-07 12:54:12 |
| 合計ジャッジ時間 | 1,765 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;
int n;
string s;
ll dp[30][2][2][3];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.precision(10);
cout<<fixed;
#ifdef LOCAL_DEFINE
freopen("in", "r", stdin);
freopen("out","w",stdout);
#endif
cin>>n;
s="1";
for(int i=0;i<n;i++)s+='0';
n++;
dp[0][0][0][0]=1;
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:s[i]-'0';
for(int d=0;d<lim+1;d++){
dp[i+1][j || d<lim][k || d==3][(10*l+d)%3]+=dp[i][j][k][l];
}
}
}
}
}
ll ans=dp[n][0][0][0]+dp[n][1][0][0];
for(int i=0;i<2;i++){
for(int j=0;j<3;j++){
ans+=dp[n][i][1][j];
}
}
cout<<--ans<<"\n";
#ifdef LOCAL_DEFINE
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
return 0;
}
aim_cpo