結果

問題 No.220 世界のなんとか2
ユーザー startcppstartcpp
提出日時 2015-06-02 17:58:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 745 bytes
コンパイル時間 637 ms
コンパイル使用メモリ 58,864 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-20 18:50:52
合計ジャッジ時間 1,584 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

//なぜかサンプル合わない
#include<iostream>
#include<cmath>
#define int long long
using namespace std;

int dp[21][3];

//今下からp(>=1)桁目を見ている
int func(int p, int mod3) {
	if (p == 0) {
		return (mod3 == 0);
	}
	if (dp[p][mod3] > 0) {
		return dp[p][mod3];
	}
	
	int ret = 0; double eps = 1e-10;
	for (int i = 0; i < 10; i++) {
		if (i == 3) {	//3が出てきた時点でそれより下は全て世界のほげ。簡単のため、ここで3が出てくる形は全部計算する。
			ret += pow(10, (double)p-1) + eps;
		}
		else {
			ret += func(p-1, (mod3+i)%3 );
		}
	}
	return (dp[p][mod3] = ret);
}

signed main() {
	int p;
	cin >> p;
	cout << func(p, 0) - 1 << endl;	//0を除くので-1する
	return 0;
}
0