結果

問題 No.372 It's automatic
ユーザー tsukiotsukio
提出日時 2016-06-18 14:12:13
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 1,120 ms / 6,000 ms
コード長 699 bytes
コンパイル時間 601 ms
コンパイル使用メモリ 63,456 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 02:50:08
合計ジャッジ時間 15,157 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1,108 ms
5,376 KB
testcase_05 AC 1,110 ms
5,376 KB
testcase_06 AC 1,105 ms
5,376 KB
testcase_07 AC 1,116 ms
5,376 KB
testcase_08 AC 1,120 ms
5,376 KB
testcase_09 AC 1,112 ms
5,376 KB
testcase_10 AC 1,113 ms
5,376 KB
testcase_11 AC 1,109 ms
5,376 KB
testcase_12 AC 1,115 ms
5,376 KB
testcase_13 AC 1,100 ms
5,376 KB
testcase_14 AC 1,112 ms
5,376 KB
testcase_15 AC 1,110 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 55 ms
5,376 KB
testcase_22 AC 53 ms
5,376 KB
testcase_23 AC 52 ms
5,376 KB
testcase_24 AC 52 ms
5,376 KB
testcase_25 AC 52 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
using namespace std;

typedef long long ll;
const ll mod = 1e9 + 7;

int main() {
	string s;
	int m;
	cin >> s >> m;

	vector<int> nums(s.length());
	for (int i = 0; i < s.length(); i++) {
		nums[i] = s[i] - '0';
	}

	vector<ll> curr(m, 0);
	vector<ll> next(m, 0);
	ll zero_count = 0;
	for (int i = 0; i < nums.size(); i++) {
		for (int k = 0; k < m; k++) {
			int state = (k * 10 + nums[i]) % m;
			next[state] += curr[k];
			next[state] %= mod;
		}

		if (nums[i] == 0) {
			zero_count++;
		}
		else {
			next[nums[i] % m]++;
			next[nums[i] % m] %= mod;
		}

		curr = next;
	}

	cout << (curr[0] + zero_count) % mod << endl;
	
	return 0;
}
0