結果

問題 No.491 10^9+1と回文
ユーザー maroon_kuri
提出日時 2017-03-10 23:30:00
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 2,203 bytes
コンパイル時間 1,409 ms
コンパイル使用メモリ 162,952 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-01 08:20:24
合計ジャッジ時間 3,878 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 103
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘ll read()’:
main.cpp:38:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   38 |         scanf("%lld",&i);
      |         ~~~~~^~~~~~~~~~~
main.cpp: In function ‘std::string readString()’:
main.cpp:60:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   60 |         scanf("%s",buf);
      |         ~~~~~^~~~~~~~~~
main.cpp: In function ‘char* readCharArray()’:
main.cpp:68:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   68 |         scanf("%s",ret);
      |         ~~~~~^~~~~~~~~~

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll=long long;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%lld",&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(int x,int suc=1){
	printf("%lld",x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341919];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341919];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(a>b)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

const int inf=LLONG_MAX/3;

int Kyuri(int x){
	int res=0;
	while(x){
		res++;
		x/=10;
	}
	return res;
}

int reverse(int x){
	vi d;
	while(x){
		d.PB(x%10);
		x/=10;
	}
	int res=0;
	for(auto v:d){
		res*=10;
		res+=v;
	}
	return res;
}

int pow10(int x){
	int res=1;
	while(x--)res*=10;
	return res;
}

int check(int i,int h,int x,int d){
	int t=i*pow10(d-h);
	if(h>d-h)i/=10;
	return t+reverse(i)<=x;
}

int Wafrelka(int x){
	if(x<=0)return 0;
	int d=Kyuri(x);
	int h=(d+1)/2,g=pow10(h);
	int res=0;
	int l=pow10(h-1)-1,r=g;
	while(r-l>1){
		const int mid=(l+r)/2;
		if(check(mid,h,x,d))
			l=mid;
		else
			r=mid;
	}
	res+=l-(pow10(h-1)-1);
	FOR(e,1,d)
		res+=pow10((e+1)/2)-pow10((e+1)/2-1);
	return res;
}

signed main(){
	int n=read();
	int x=n/1000000000;
	if(x*1000000000+reverse(x)>n)x--;
	cout<<Wafrelka(x)<<endl;
}
0