結果

問題 No.528 10^9と10^9+7と回文
ユーザー beetbeet
提出日時 2017-06-09 23:03:56
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 1,000 ms
コード長 1,630 bytes
コンパイル時間 1,255 ms
コンパイル使用メモリ 147,744 KB
実行使用メモリ 5,552 KB
最終ジャッジ日時 2023-10-01 00:53:15
合計ジャッジ時間 2,682 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
5,184 KB
testcase_01 AC 6 ms
5,248 KB
testcase_02 AC 5 ms
5,100 KB
testcase_03 AC 5 ms
5,356 KB
testcase_04 AC 5 ms
5,192 KB
testcase_05 AC 5 ms
5,248 KB
testcase_06 AC 5 ms
5,188 KB
testcase_07 AC 5 ms
5,412 KB
testcase_08 AC 5 ms
5,360 KB
testcase_09 AC 5 ms
5,120 KB
testcase_10 AC 19 ms
5,552 KB
testcase_11 AC 19 ms
5,280 KB
testcase_12 AC 19 ms
5,284 KB
testcase_13 AC 19 ms
5,312 KB
testcase_14 AC 14 ms
5,400 KB
testcase_15 AC 12 ms
5,248 KB
testcase_16 AC 12 ms
5,316 KB
testcase_17 AC 11 ms
5,252 KB
testcase_18 AC 18 ms
5,316 KB
testcase_19 AC 9 ms
5,180 KB
testcase_20 AC 15 ms
5,284 KB
testcase_21 AC 11 ms
5,300 KB
testcase_22 AC 5 ms
5,132 KB
testcase_23 AC 5 ms
5,088 KB
testcase_24 AC 5 ms
5,196 KB
testcase_25 AC 6 ms
5,248 KB
testcase_26 AC 19 ms
5,264 KB
testcase_27 AC 12 ms
5,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
int MOD1=1000000000;
int MOD2=1000000007;
string s,t;
int dp1[114514];
int dp2[114514];
int calc2_1(int x,int mod){
  t="";
  int res=0;
  int y=(x+1)/2;
  for(int i=0;i<y;i++){
    t+=s[i];
    for(int j=0;j<10;j++){
      if(i==0&&j==0) continue;
      //cout<<i<<":"<<j<<":"<<s[i]<<":"<<y<<":"<<dp1[y-(i+1)]<<":"<<res<<endl;
      if(s[i]>('0'+j)) (res+=dp1[y-(i+1)])%=mod;
      if(i==y-1&&s[i]=='0'+j){
	string u=t;
	reverse(u.begin(),u.end());
	if(x&1) t.pop_back();
	t+=u;
	//cout<<s<<" "<<t<<endl;
	if(s.compare(t)>=0) res++;
      }
    }
    res%=mod;
  }
  return res;
}

int calc2_2(int x,int mod){
  t="";
  int res=0;
  int y=(x+1)/2;
  for(int i=0;i<y;i++){
    t+=s[i];
    for(int j=0;j<10;j++){
      if(i==0&&j==0) continue;
      //cout<<i<<":"<<j<<":"<<s[i]<<":"<<y<<":"<<dp2[y-(i+1)]<<":"<<res<<endl;
      if(s[i]>('0'+j)) (res+=dp2[y-(i+1)])%=mod;
      if(i==y-1&&s[i]=='0'+j){
	string u=t;
	reverse(u.begin(),u.end());
	if(x&1) t.pop_back();
	t+=u;
	//cout<<s<<" "<<t<<endl;
	if(s.compare(t)>=0) res++;
      }
    }
    res%=mod;
  }
  return res;
}
signed main(){
  cin>>s;
  int ans1=0,ans2=0;
  dp1[0]=dp2[0]=1;
  for(int i=1;i<114514;i++){
    (dp1[i]=dp1[i-1]*10)%=MOD1;
    (dp2[i]=dp2[i-1]*10)%=MOD2;
    //if(i<100) cout<<dp1[i]<<" "<<dp2[i]<<endl;
  }
  //cout<<dp1[0]<<" "<<dp2[0]<<endl;
  for(int i=1;i<(int)s.size();i++){
    (ans1+=9*dp1[(i+1)/2-1])%=MOD1;
    (ans2+=9*dp2[(i+1)/2-1])%=MOD2;
  }
  (ans1+=calc2_1(s.size(),MOD1))%=MOD1;
  (ans2+=calc2_2(s.size(),MOD2))%=MOD2;
  cout<<ans1<<endl<<ans2<<endl;
  return 0;
}
0