結果

問題 No.372 It's automatic
ユーザー kotatsugamekotatsugame
提出日時 2020-03-04 14:03:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,341 ms / 6,000 ms
コード長 588 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 65,688 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 01:37:24
合計ジャッジ時間 17,059 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1,341 ms
6,940 KB
testcase_05 AC 1,287 ms
6,940 KB
testcase_06 AC 1,273 ms
6,944 KB
testcase_07 AC 1,285 ms
6,940 KB
testcase_08 AC 1,298 ms
6,940 KB
testcase_09 AC 1,276 ms
6,940 KB
testcase_10 AC 1,283 ms
6,940 KB
testcase_11 AC 1,275 ms
6,944 KB
testcase_12 AC 1,288 ms
6,940 KB
testcase_13 AC 1,260 ms
6,944 KB
testcase_14 AC 1,293 ms
6,944 KB
testcase_15 AC 1,300 ms
6,944 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 2 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 AC 65 ms
6,944 KB
testcase_22 AC 67 ms
6,940 KB
testcase_23 AC 64 ms
6,944 KB
testcase_24 AC 65 ms
6,940 KB
testcase_25 AC 67 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
const long mod=1e9+7;
long dp[2][2][20000];
string s;
int M;
main()
{
	cin>>s>>M;
	int now=0;
	dp[now][0][0]=1;
	int zc=0;
	for(int i=0;i<s.size();i++)
	{
		int c=s[i]-'0';
		for(int j=0;j<M;j++)dp[1-now][0][j]=dp[1-now][1][j]=0;
		if(c==0)zc++;
		else dp[1-now][1][c%M]+=dp[now][0][0];
		for(int j=0;j<M;j++)
		{
			dp[1-now][1][(j*10+c)%M]+=dp[now][1][j];
			dp[1-now][0][j]+=dp[now][0][j];
			dp[1-now][1][j]+=dp[now][1][j];
		}
		now=1-now;
		for(int j=0;j<M;j++)dp[now][0][j]%=mod,dp[now][1][j]%=mod;
	}
	cout<<(dp[now][1][0]+zc)%mod<<endl;
}
0