結果

問題 No.528 10^9と10^9+7と回文
ユーザー kotatsugamekotatsugame
提出日時 2020-03-27 03:17:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 32 ms / 1,000 ms
コード長 683 bytes
コンパイル時間 497 ms
コンパイル使用メモリ 65,024 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-10-01 01:00:33
合計ジャッジ時間 1,961 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,464 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 32 ms
4,380 KB
testcase_11 AC 31 ms
4,380 KB
testcase_12 AC 31 ms
4,376 KB
testcase_13 AC 31 ms
4,380 KB
testcase_14 AC 20 ms
4,500 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 16 ms
4,504 KB
testcase_17 AC 14 ms
4,376 KB
testcase_18 AC 30 ms
4,376 KB
testcase_19 AC 10 ms
4,376 KB
testcase_20 AC 22 ms
4,380 KB
testcase_21 AC 14 ms
4,432 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 5 ms
4,380 KB
testcase_26 AC 31 ms
4,380 KB
testcase_27 AC 24 ms
4,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:41:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   41 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
string N;
long dp[2][50505];
int calc(const long mod)
{
	long ans=0,p=9;
	for(int i=1;i<N.size();i++)
	{
		(ans+=p)%=mod;
		if(i%2==0)p=p*10%mod;
	}
	for(int i=0;i<50505;i++)dp[0][i]=dp[1][i]=0;
	dp[0][0]=1;
	int i;
	for(i=0;i*2<N.size();i++)
	{
		for(int j=0;j<2;j++)
		{
			int lim=j?9:N[i]-'0';
			for(int k=!i;k<=lim;k++)
			{
				(dp[j||k<lim][i+1]+=dp[j][i])%=mod;
			}
		}
	}
	ans+=dp[1][i];
	bool ok=true;
	for(;i<N.size();i++)
	{
		if(N[i]>N[N.size()-i-1])break;
		else if(N[i]<N[N.size()-i-1])
		{
			ok=false;
			break;
		}
	}
	ans+=ok;
	return (ans+mod)%mod;
}
main()
{
	cin>>N;
	cout<<calc(1e9)<<endl;
	cout<<calc(1e9+7)<<endl;
}
0