結果

問題 No.491 10^9+1と回文
ユーザー srup٩(๑`н´๑)۶srup٩(๑`н´๑)۶
提出日時 2017-03-11 00:06:06
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 53 ms / 1,000 ms
コード長 2,728 bytes
コンパイル時間 1,789 ms
コンパイル使用メモリ 171,028 KB
実行使用メモリ 12,160 KB
最終ジャッジ日時 2024-04-08 16:04:57
合計ジャッジ時間 5,689 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 9 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 7 ms
6,676 KB
testcase_06 AC 53 ms
12,160 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 1 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
testcase_44 AC 2 ms
6,676 KB
testcase_45 AC 2 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 1 ms
6,676 KB
testcase_48 AC 2 ms
6,676 KB
testcase_49 AC 2 ms
6,676 KB
testcase_50 AC 2 ms
6,676 KB
testcase_51 AC 3 ms
6,676 KB
testcase_52 AC 2 ms
6,676 KB
testcase_53 AC 2 ms
6,676 KB
testcase_54 AC 2 ms
6,676 KB
testcase_55 AC 2 ms
6,676 KB
testcase_56 AC 2 ms
6,676 KB
testcase_57 AC 2 ms
6,676 KB
testcase_58 AC 3 ms
6,676 KB
testcase_59 AC 2 ms
6,676 KB
testcase_60 AC 1 ms
6,676 KB
testcase_61 AC 2 ms
6,676 KB
testcase_62 AC 2 ms
6,676 KB
testcase_63 AC 2 ms
6,676 KB
testcase_64 AC 1 ms
6,676 KB
testcase_65 AC 2 ms
6,676 KB
testcase_66 AC 2 ms
6,676 KB
testcase_67 AC 9 ms
6,676 KB
testcase_68 AC 1 ms
6,676 KB
testcase_69 AC 2 ms
6,676 KB
testcase_70 AC 2 ms
6,676 KB
testcase_71 AC 2 ms
6,676 KB
testcase_72 AC 2 ms
6,676 KB
testcase_73 AC 2 ms
6,676 KB
testcase_74 AC 2 ms
6,676 KB
testcase_75 AC 1 ms
6,676 KB
testcase_76 AC 2 ms
6,676 KB
testcase_77 AC 2 ms
6,676 KB
testcase_78 AC 2 ms
6,676 KB
testcase_79 AC 1 ms
6,676 KB
testcase_80 AC 2 ms
6,676 KB
testcase_81 AC 2 ms
6,676 KB
testcase_82 AC 1 ms
6,676 KB
testcase_83 AC 2 ms
6,676 KB
testcase_84 AC 1 ms
6,676 KB
testcase_85 AC 2 ms
6,676 KB
testcase_86 AC 2 ms
6,676 KB
testcase_87 AC 2 ms
6,676 KB
testcase_88 AC 2 ms
6,676 KB
testcase_89 AC 1 ms
6,676 KB
testcase_90 AC 2 ms
6,676 KB
testcase_91 AC 2 ms
6,676 KB
testcase_92 AC 1 ms
6,676 KB
testcase_93 AC 2 ms
6,676 KB
testcase_94 AC 2 ms
6,676 KB
testcase_95 AC 2 ms
6,676 KB
testcase_96 AC 2 ms
6,676 KB
testcase_97 AC 52 ms
12,160 KB
testcase_98 AC 51 ms
12,160 KB
testcase_99 AC 51 ms
12,160 KB
testcase_100 AC 53 ms
12,160 KB
testcase_101 AC 52 ms
12,160 KB
testcase_102 AC 51 ms
12,160 KB
testcase_103 AC 51 ms
12,160 KB
testcase_104 AC 52 ms
12,160 KB
testcase_105 AC 53 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<pint> vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define all(v) (v).begin(),(v).end()
#define eall(v) unique(all(v), v.end())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll INFF = 1e18;

set<string> tmp;

void dfs(string s, int cnt, int size){
	// cout << s << endl;
	if(cnt == size){
		// cout << s << endl;
		// tmp.pb(s);
		tmp.insert(s);
		return;
	}
	/*
	if(size % 2 == 1 && cnt == size / 2){
		if(size >= 2){
			rep(i, 10){
				string d = to_string(i);
				dfs(s + d, cnt + 1, size);
			}
		}else{
			reps(i, 1, 10){
				string d = to_string(i);
				dfs(s + d, cnt + 1, size);
			}
		}
	}
	*/

	if(cnt < size / 2){
		if(cnt != 0){
			rep(i, 10){
				string d = to_string(i);
				dfs(s + d, cnt + 1, size);
			}
		}else{
			reps(i, 1, 10){
				string d = to_string(i);
				dfs(s + d, cnt + 1, size);
			}
		}
	}

	if(cnt >= size / 2){
		// printf("k\n");
		auto left = s;
		auto right = s;
		reverse(all(right));
		// cout << left << " + " << right << endl;
		if(size % 2 == 1){
			if(cnt != 0){
				rep(i, 10){
					string d = to_string(i);
					tmp.insert(left + d + right);
				}
			}else{
				reps(i, 1, 10){
					string d = to_string(i);
					tmp.insert(left + d + right);
				}
			}
		}else{
			tmp.insert(left + right);
		}
	}
	return;
}

ll solve(ll n){
	ll ret = 0;
	string s = to_string(n);
	/*
	rep(i, s.size() / 2 + 1){
		if(i % 2 == 0) ret += pow(9, i / 2);
		else ret += pow(9, i);
	}
	printf("tret %lld\n", ret);
	*/
	/*
	ll tmp = 1;
	bool flag = false;
	rep(i, s.size() / 2 + 1){
		ll d = min(s[i] - '0', s[s.size() - i - 1] - '0');
		printf("i %d d %lld\n", i, d);
		if(d != 0) flag = true;
		tmp *= d;
		if(s.size() % 2 == 0 && i == s.size() / 2 - 1) break;
	}
	if(flag) ret += tmp;
	return ret;
	*/
	// dfs("", 0, s.size());
	reps(cnt, 1, s.size() + 1){
		reps(i, 1, 10){
			auto d = to_string(i);
			// printf("cnt %d\n", cnt);
			dfs(d, 1, cnt);
		}
	}

	// set<ll> ans;
	// for(auto u : tmp) ans.insert(stoll(u));
	for(auto u : tmp){
		// cout << "u " << u << endl;
		/*
		if(1 <= u && u<= n){
			// printf("%lld\n", u);
			ret++;
		}
		*/
		ll d = stoll(u);
		if(d <= n) ret++;
	}
	return ret;
}

int main(void){
	ll n; cin >> n;
	n /= (INF + 1);
	// printf("%lld\n", n);
	printf("%lld\n", solve(n));
	return 0;
}
/*
1000000001
9000000009
11000000011
*/
0