結果

問題 No.2032 Let's Write Multiples!!
ユーザー olpheolphe
提出日時 2022-08-05 22:53:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,222 bytes
コンパイル時間 1,415 ms
コンパイル使用メモリ 126,992 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-14 00:29:27
合計ジャッジ時間 6,104 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
int N, M, K, T, H, W, L, R;

constexpr int SMALL = 10000;

int by[10000][10];
int ten[9];

long long func(int a, int b) {
	if (a < b)return 0;
	int mx = a / b;
	mx--;
	long long ret = 0;
	{
		int add = b % SMALL;
		int c = 0;
		for (int i = 0; i < SMALL; i++) {
			c += add;
			if (c >= SMALL) {
				c -= SMALL;
			}
			if (i <= mx % SMALL) {
				ret += (1 + mx / SMALL) * by[c][N];
			}
			else {
				ret += (0 + mx / SMALL) * by[c][N];
			}
		}
	}
	{
		{
			int num = (N + 0) * (ten[8]) - 1;
			ret += min(a, num + ten[8]) / b;
			ret -= min(a, num) / b;
		}
		for (int i = 0; i < 10; i++) {
			int num = i * ten[8] + (N + 0) * (ten[7]) - 1;
			ret += min(a, num + ten[7]) / b;
			ret -= min(a, num) / b;
		}
		for (int i = 0; i < 100; i++) {
			int num = i * ten[7] + (N + 0) * (ten[6]) - 1;
			ret += min(a, num + ten[6]) / b;
			ret -= min(a, num) / b;
		}
		for (int i = 0; i < 1000; i++) {
			int num = i * ten[6] + (N + 0) * (ten[5]) - 1;
			ret += min(a, num + ten[5]) / b;
			ret -= min(a, num) / b;
		}
		for (int i = 0; i < 10000; i++) {
			int num = i * ten[5] + (N + 0) * (ten[4]) - 1;
			if (num >= a)break;
			ret += min(a, num + ten[4]) / b;
			ret -= min(a, num) / b;
		}
	}
	return ret;
}

void Solve() {
	//cin >> L >> R >> K >> N;
	L = 1333, R = 999999999, K = 1234567, N = 5;
	cout << func(R, K) - func(L - 1, K) << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	for (int i = 0; i < 10000; i++) {
		for (int j = 1; j < 10; j++) {
			int box = i;
			while (box) {
				by[i][j] += box % 10 == j;
				box /= 10;
			}
		}
	}
	ten[0] = 1;
	for (int i = 1; i < 9; i++) {
		ten[i] = ten[i - 1] * 10;
	}
	cin >> T;
	while (T--) {
		Solve();
	}
}
0