結果

問題 No.220 世界のなんとか2
ユーザー Kmcode1Kmcode1
提出日時 2015-05-29 22:38:17
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,519 bytes
コンパイル時間 1,024 ms
コンパイル使用メモリ 107,880 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 16:29:04
合計ジャッジ時間 1,957 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#include<bitset>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<ctime>
#include<complex>
#include<functional>
#include<climits>
#include<cassert>
#include<iterator>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;
string pluss(string a, string b, bool flag = false){
	if (!flag){
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
	}
	if (a.size() > b.size()){
		swap(a, b);
	}
	string ans;
	ans.clear();
	long long int want = 0;
	for (int i = 0; i < a.size(); i++){
		long long int val = a[i] - '0';
		val += b[i] - '0';
		val += want;
		want = val / 10LL;
		val %= 10LL;
		ans.push_back(val + '0');
	}
	for (int j = a.size(); j < b.size(); j++){
		long long int val = 0;
		val += b[j] - '0';
		val += want;
		want = val / 10LL;
		val %= 10LL;
		ans.push_back(val + '0');
	}
	while (want){
		ans.push_back(want % 10 + '0');
		want /= 10;
	}
	if (!flag){
		reverse(ans.begin(), ans.end());
	}
	return ans;
}
string mult(string a, string b, bool flag = false){
	if (!flag){
		reverse(a.begin(), a.end());
		reverse(b.begin(), b.end());
	}
	string ans = "0";
	string pas;
	string kari;
	pas.clear();
	for (int i = 0; i < b.size(); i++){
		long long int bb = b[i] - '0';
		long long int tmp = 0;
		kari = pas;
		for (int j = 0; j < a.size(); j++){
			long long int val = (long long int)(a[j] - '0')*bb;
			val += tmp;
			tmp = val / 10LL;
			val %= 10LL;
			kari.push_back(val + '0');
		}
		while (tmp){
			kari.push_back((tmp % 10LL) + '0');
			tmp /= 10LL;
		}
		ans = pluss(ans, kari, true);
		//end
		pas.push_back('0');
	}
	if (!flag){
		reverse(ans.begin(), ans.end());
	}
	return ans;
}
string dp[20][4][2][2];
bool use[20][4][2][2];
int p = 0;
int ok = 0;
inline string dfs(int a, int b,int f,int u){
	if (a == p){
		
		if (u&&(b==0||f==1)){
			return "1";
		}
		else{
			return "0";
		}
	}
	if (use[a][b][f][u]){
		return dp[a][b][f][u];
	}
	use[a][b][f][u] = true;
	dp[a][b][f][u] = '0';
	for (int i = 0; i < 10; i++){
		if (i == 3){
			dp[a][b][f][u] = pluss(dp[a][b][f][u], dfs(a + 1, (b + i) % 3, f | 1,1));
		}
		else{
			dp[a][b][f][u] = pluss(dp[a][b][f][u], dfs(a + 1, (b+i)%3, f,i!=0|u));
		}
	}
	return dp[a][b][f][u];
}
int main(){
	cin >> p;
	cout << dfs(0, 0, 0,0) << endl;
	return 0;
}
0