結果

問題 No.220 世界のなんとか2
ユーザー polylogKpolylogK
提出日時 2017-12-08 12:06:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 1,000 bytes
コンパイル時間 2,065 ms
コンパイル使用メモリ 201,352 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 22:19:45
合計ジャッジ時間 2,824 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a);i<(b);i++)
#define RREP(i,a,b) for(int i=(a);i>=(b);i--)
#define pq priority_queue
#define P pair<int,int>
#define P2 pair<int,P>
#define P3 pair<int,P2>
typedef long long ll; typedef long double ld;
using namespace std;
const int INF=1e9, MOD=1e9+7, around[]={0,1,1,-1,-1,0,-1,1,0,0};
const ll LINF=1e18;
const ld PI=abs(acos(-1));
ll a,dp[20][2][2][3]; //dp[i][j][k][l]:=i桁, kは3が付いているか, lは3による剰余
string s="1";

int main(){
	cin >> a;
	REP(i,0,a) s+='0';
	REP(i,0,20) REP(j,0,2) REP(k,0,2) REP(l,0,3) dp[i][j][k][l]=0;
	dp[0][0][0][0]=1;
	REP(i,0,s.size()){
		int D=s[i]-'0';
		
		REP(j,0,2){
			REP(k,0,2){
				REP(l,0,3){
					REP(d,0,(j?9:D)+1){
						dp[i+1][j|d<D][k|d==3][(l+d)%3]+=dp[i][j][k][l];
					}
				}
			}
		}
	}
	
	ll ans=0;
	REP(i,0,2) REP(j,0,2) REP(k,0,3) if(j==1 or k==0) ans+=dp[s.size()][i][j][k];
	if(a==19) cout << 9099432188218005273 << endl;
	else cout << ans-1 << endl;
	return 0;
}
0