結果

問題 No.528 10^9と10^9+7と回文
ユーザー 👑 kmjpkmjp
提出日時 2017-06-09 23:09:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,148 bytes
コンパイル時間 3,304 ms
コンパイル使用メモリ 168,648 KB
実行使用メモリ 20,052 KB
最終ジャッジ日時 2023-10-24 00:52:05
合計ジャッジ時間 3,151 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
6,212 KB
testcase_01 AC 7 ms
6,212 KB
testcase_02 AC 8 ms
6,212 KB
testcase_03 AC 8 ms
6,212 KB
testcase_04 AC 7 ms
6,212 KB
testcase_05 AC 8 ms
6,212 KB
testcase_06 AC 8 ms
6,212 KB
testcase_07 AC 8 ms
6,212 KB
testcase_08 AC 8 ms
6,212 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 9 ms
6,192 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘ll gogo(std::deque<int>&, int)’:
main.cpp:34:48: warning: ‘__builtin___sprintf_chk’ may write a terminating nul past the end of the destination [-Wformat-overflow=]
   34 |                                 sprintf(buf,"%d",i);
      |                                                ^
In file included from /usr/include/stdio.h:894,
                 from /usr/include/c++/11/cstdio:42,
                 from /usr/include/x86_64-linux-gnu/c++/11/bits/stdc++.h:46,
                 from main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:38:34: note: ‘__builtin___sprintf_chk’ output between 2 and 11 bytes into a destination of size 10
   38 |   return __builtin___sprintf_chk (__s, __USE_FORTIFY_LEVEL - 1,
      |          ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   39 |                                   __glibc_objsize (__s), __fmt,
      |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   40 |                                   __va_arg_pack ());
      |                                   ~~~~~~~~~~~~~~~~~

ソースコード

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; string s;
	
	
	if(D.size()<=4) {
		int v=0,x=0;
		
		if(first) {
			FORR(c,D) v=v*10+c;
			for(i=1;i<=v;i++) {
				char buf[10];
				sprintf(buf,"%d",i);
				string s=buf;
				x++;
				FOR(j,s.size()) if(s[j]!=s[s.size()-1-j]) {
					x--;
					break;
				}
			}
		}
		else {
			string s;
			FORR(c,D) s+=(char)(c+'0');
			FOR(i,10000) {
				char buf[10];
				sprintf(buf,"%06d",i);
				string t=buf;
				t=t.substr(t.size()-s.size());
				x++;
				FOR(j,t.size()) if(t[j]!=t[t.size()-1-j]) {
					x--;
					break;
				}
				if(t==s) break;
			}
		}
		return x;
	}
	
	ll ret=0;
	
	if(first) {
		ret += sum[D.size()-1];
		(ret += (D[0]-1)*num[D.size()-2])%=mo;
	}
	else {
		(ret += D[0]*num[D.size()-2])%=mo;
	}
	
	int del=D[0]>D.back();
	D.pop_front();
	D.pop_back();
	if(del) {
		for(i=D.size()-1;i>=0;i--) {
			D[i]--;
			if(D[i]>=0) break;
			D[i]=9;
		}
		if(i<0) goto out;
	}
	
	ret += gogo(D);
	
	out:
	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;
		if(i==1) num[i]=9;
		if(i>=2) num[i]=9*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