結果

問題 No.528 10^9と10^9+7と回文
ユーザー chocoruskchocorusk
提出日時 2019-09-04 13:34:58
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 1,000 ms
コード長 1,191 bytes
コンパイル時間 712 ms
コンパイル使用メモリ 98,296 KB
実行使用メモリ 5,980 KB
最終ジャッジ日時 2023-10-01 01:00:38
合計ジャッジ時間 2,096 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 3 ms
4,920 KB
testcase_03 AC 3 ms
4,904 KB
testcase_04 AC 3 ms
4,916 KB
testcase_05 AC 3 ms
4,964 KB
testcase_06 AC 3 ms
4,912 KB
testcase_07 AC 3 ms
4,972 KB
testcase_08 AC 3 ms
4,964 KB
testcase_09 AC 3 ms
4,960 KB
testcase_10 AC 19 ms
5,952 KB
testcase_11 AC 18 ms
5,912 KB
testcase_12 AC 19 ms
5,900 KB
testcase_13 AC 19 ms
5,980 KB
testcase_14 AC 12 ms
5,624 KB
testcase_15 AC 11 ms
5,440 KB
testcase_16 AC 10 ms
5,392 KB
testcase_17 AC 9 ms
5,324 KB
testcase_18 AC 18 ms
5,876 KB
testcase_19 AC 7 ms
5,480 KB
testcase_20 AC 14 ms
5,696 KB
testcase_21 AC 10 ms
5,380 KB
testcase_22 AC 3 ms
4,960 KB
testcase_23 AC 2 ms
4,920 KB
testcase_24 AC 3 ms
4,988 KB
testcase_25 AC 4 ms
5,068 KB
testcase_26 AC 19 ms
5,972 KB
testcase_27 AC 19 ms
5,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
ll MOD;
ll solve(string s){
	int n=s.size();
	if(n==1) return s[0]-'0';
	ll dp[2][100010]={};
	dp[0][0]=1, dp[1][0]=s[0]-'0'-1;
	for(int i=1; i<n; i++){
		(dp[1][i]+=dp[1][i-1]*10)%=MOD;
		(dp[0][i]+=dp[0][i-1])%=MOD;
		(dp[1][i]+=dp[0][i-1]*(s[i]-'0'))%=MOD;
	}
	ll ans=dp[1][(n-1)/2];
	bool nuo=1;
	for(int i=(n-1)/2+1; i<n; i++){
		if(s[i]>s[n-1-i]) break;
		else if(s[i]<s[n-1-i]){
			nuo=0; break;
		}
	}
	if(nuo) ans=(ans+1)%MOD;
	ll p[100010];
	p[0]=1;
	for(int i=1; i<=n; i++) p[i]=p[i-1]*10%MOD;
	for(int i=1; i<n; i++){
		(ans+=(p[(i+1)/2]-p[(i-1)/2]+MOD))%=MOD;
	}
	return ans;
}
int main()
{
	string s; cin>>s;
	MOD=1e9;
	cout<<solve(s)<<endl;
	MOD=1e9+7;
	cout<<solve(s)<<endl;
	return 0;
}
0