結果

問題 No.260 世界のなんとか3
ユーザー めうめう🎒めうめう🎒
提出日時 2016-11-20 15:33:00
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,260 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 73,284 KB
実行使用メモリ 11,428 KB
最終ジャッジ日時 2023-08-18 04:21:05
合計ジャッジ時間 4,415 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
8,364 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 6 ms
4,504 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

string a, b;

int saiki(int now, bool isSame, bool has3, int mod3, int mod8){

	if(now == a.size() && (has3 || mod3 == 0) && mod8 != 0) return 1;
	if(now == a.size()) return 0;

	int ret = 0;

	for(int i = 0;i < 10;i++){
		if(isSame && a[now] < ('0' + i)) continue;

		bool nextIsSame;
		if(isSame && a[now] == ('0' + i)) nextIsSame = true;
		else nextIsSame = false;

		bool nextHas3 = (has3 || i == 3);

		int nextMod3 = (mod3 + i) % 3;

		int nextMod8 = (mod8 * 10 + i) % 8;

		ret += saiki(now + 1, nextIsSame, nextHas3, nextMod3, nextMod8);
	}

	return ret;
}

int main() {
	cin >> b >> a;

	for(int i = b.size() - 1;i >= 0;i--){
		if(b[i] == '0'){
			b[i] = '9';
		}else {
			b[i] = (b[i] - 1);
			break;
		}
	}
	if(b[0] == '0' && b.size() != 1) b.erase(0, 1);

	int ans = saiki(0, 1, 0, 0, 0);

	a = b;
	ans -= saiki(0, 1, 0, 0, 0);

	cout << ans << endl;
	return 0;
}
0