結果

問題 No.491 10^9+1と回文
ユーザー tekitouktekitouk
提出日時 2017-03-11 07:00:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 1,000 ms
コード長 1,260 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 76,408 KB
実行使用メモリ 45,932 KB
最終ジャッジ日時 2024-04-08 16:13:19
合計ジャッジ時間 10,751 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

typedef long long ll;

int b[10] = { 9,8,7,6,5,4,3,2,1,0 };
int digit(ll a);

vector<string>v[15];

int main() {

	ll N;

	scanf("%lld",&N);

	int i, j, k;

	if (N < 1000000001ll) {
		printf("0\n");
	}
	else {
		int d = digit(N);
		if (d == 19) {
			d = 18;
			N = 999999999999999999ll;
		}
		for (i = 0; i <= 9; i++) {
			v[1].push_back(to_string(i));
		}
		v[2].push_back("00");
		for (i = 11; i <= 99; i++) {
			if (i / 10 == i % 10) {
				v[2].push_back(to_string(i));
			}
		}
		for (i = 3; i <= 11; i++) {
			for (k = 0; k <= 9; k++) {
				for (j = 0; j < v[i - 2].size(); j++) {
					string s = to_string(k);
					s += v[i - 2][j];
					s += to_string(k);
					v[i].push_back(s);
				}
			}
		}

		ll ans = 0ll;

		for (k = 1; k <= d - 9; k++) {
			for (i = 0; i < v[k].size(); i++) {
				string s = v[k][i];
				for (j = 0; j < b[k]; j++) {
					s += to_string(0);
				}
				s += v[k][i];
				if (s[0] == '0') { continue; }
				if (stoll(s) <= N) {
					ans += 1ll;
				}
			}
		}
		printf("%lld\n", ans);
	}

	return 0;
}
int digit(ll a) {
	int ret = 0;
	while (1) {
		if (a == 0ll) { break; }
		ret++;
		a /= 10ll;
	}
	return ret;
}
0