結果

問題 No.528 10^9と10^9+7と回文
ユーザー 👑 kmjpkmjp
提出日時 2017-06-10 00:12:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 24 ms / 1,000 ms
コード長 1,863 bytes
コンパイル時間 1,407 ms
コンパイル使用メモリ 153,288 KB
実行使用メモリ 16,644 KB
最終ジャッジ日時 2023-10-01 00:55:22
合計ジャッジ時間 2,829 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,860 KB
testcase_01 AC 8 ms
5,960 KB
testcase_02 AC 8 ms
5,912 KB
testcase_03 AC 7 ms
5,912 KB
testcase_04 AC 7 ms
5,920 KB
testcase_05 AC 7 ms
5,852 KB
testcase_06 AC 7 ms
5,904 KB
testcase_07 AC 8 ms
6,048 KB
testcase_08 AC 8 ms
5,844 KB
testcase_09 AC 7 ms
5,860 KB
testcase_10 AC 22 ms
16,524 KB
testcase_11 AC 24 ms
16,644 KB
testcase_12 AC 24 ms
16,536 KB
testcase_13 AC 22 ms
16,532 KB
testcase_14 AC 16 ms
12,348 KB
testcase_15 AC 15 ms
11,576 KB
testcase_16 AC 14 ms
11,216 KB
testcase_17 AC 14 ms
10,136 KB
testcase_18 AC 21 ms
16,224 KB
testcase_19 AC 11 ms
8,860 KB
testcase_20 AC 17 ms
13,248 KB
testcase_21 AC 14 ms
10,292 KB
testcase_22 AC 8 ms
5,868 KB
testcase_23 AC 7 ms
5,876 KB
testcase_24 AC 8 ms
5,960 KB
testcase_25 AC 9 ms
7,040 KB
testcase_26 AC 24 ms
16,520 KB
testcase_27 AC 9 ms
6,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
string S;
ll p10[101010];
ll num[101010];
ll sum[101010];
ll mo;


ll gogo(deque<int>& D,int first=0) {
	int i,j,k,l,r,x,y;
	
	
	if(D.size()<=4) {
		int v=0,x=0;
		FORR(c,D) v=v*10+c;
		for(i=first;i<=v;i++) {
			char buf[10];
			string a,b;
			if(first) {
				sprintf(buf,"%d",i);
				a=buf;
			}
			else {
				sprintf(buf,"%06d",i);
				a=buf;
				a=a.substr(a.size()-D.size());
			}
			b=a;
			reverse(ALL(b));
			if(a==b) x++;
		}
		return x;
	}
	
	ll ret=0;
	
	if(first) {
		ret += 9*sum[D.size()-1];
		(ret += (D[0]-1)*10*num[D.size()-2])%=mo;
	}
	else {
		(ret += D[0]*10*num[D.size()-2])%=mo;
	}
	
	int del=D[0]>D.back();
	D.pop_front();
	D.pop_back();
	for(i=D.size()-1;i>=0&&del;i--) {
		D[i]--;
		if(D[i]>=0) del=0;
		else D[i]=9;
	}
	if(del==0) ret += gogo(D);
	return ret%mo;
}

ll hoge() {
	int i,j,k,l,r,x,y; string s;
	p10[0]=1;
	FOR(i,100001) {
		p10[i+1]=p10[i]*10%mo;
		if(i==0) num[i]=0;
		else num[i]=p10[(i-1)/2]%mo;
		sum[i]=((i==0)?0:sum[i-1])+num[i];
	}
	deque<int> T;
	FORR(c,S) T.push_back(c-'0');
	return gogo(T,1);
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>S;
	N=S.size();
	
	mo=1000000000;
	cout<<hoge()<<endl;
	mo=1000000007;
	cout<<hoge()<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0