結果

問題 No.491 10^9+1と回文
ユーザー tekitouktekitouk
提出日時 2017-03-11 03:23:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,520 bytes
コンパイル時間 986 ms
コンパイル使用メモリ 77,940 KB
実行使用メモリ 46,612 KB
最終ジャッジ日時 2023-09-06 17:29:14
合計ジャッジ時間 11,668 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
41,032 KB
testcase_01 AC 54 ms
43,004 KB
testcase_02 AC 52 ms
41,520 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 52 ms
41,648 KB
testcase_09 AC 49 ms
40,784 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 51 ms
41,244 KB
testcase_12 AC 51 ms
40,696 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 54 ms
45,620 KB
testcase_17 AC 50 ms
41,988 KB
testcase_18 AC 53 ms
40,840 KB
testcase_19 AC 52 ms
42,292 KB
testcase_20 AC 55 ms
44,544 KB
testcase_21 AC 53 ms
43,576 KB
testcase_22 AC 51 ms
41,608 KB
testcase_23 WA -
testcase_24 AC 54 ms
41,800 KB
testcase_25 AC 50 ms
41,616 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 53 ms
42,024 KB
testcase_28 AC 53 ms
45,276 KB
testcase_29 AC 54 ms
41,224 KB
testcase_30 WA -
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 51 ms
41,160 KB
testcase_34 AC 52 ms
40,904 KB
testcase_35 WA -
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 53 ms
42,608 KB
testcase_38 AC 52 ms
41,612 KB
testcase_39 AC 55 ms
43,832 KB
testcase_40 AC 2 ms
4,376 KB
testcase_41 AC 51 ms
43,900 KB
testcase_42 AC 52 ms
42,208 KB
testcase_43 AC 54 ms
46,388 KB
testcase_44 AC 53 ms
44,672 KB
testcase_45 AC 52 ms
42,952 KB
testcase_46 AC 52 ms
41,396 KB
testcase_47 AC 54 ms
46,268 KB
testcase_48 AC 51 ms
41,160 KB
testcase_49 AC 2 ms
4,376 KB
testcase_50 AC 54 ms
44,300 KB
testcase_51 WA -
testcase_52 AC 55 ms
41,320 KB
testcase_53 AC 2 ms
4,376 KB
testcase_54 AC 54 ms
42,416 KB
testcase_55 AC 54 ms
41,608 KB
testcase_56 AC 51 ms
41,236 KB
testcase_57 AC 51 ms
41,592 KB
testcase_58 WA -
testcase_59 AC 52 ms
42,380 KB
testcase_60 AC 50 ms
40,888 KB
testcase_61 AC 53 ms
43,936 KB
testcase_62 AC 52 ms
44,420 KB
testcase_63 WA -
testcase_64 AC 52 ms
43,920 KB
testcase_65 AC 52 ms
40,780 KB
testcase_66 AC 57 ms
44,116 KB
testcase_67 WA -
testcase_68 AC 54 ms
42,180 KB
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 52 ms
41,392 KB
testcase_71 WA -
testcase_72 AC 50 ms
40,772 KB
testcase_73 AC 54 ms
41,228 KB
testcase_74 AC 52 ms
43,920 KB
testcase_75 AC 53 ms
42,880 KB
testcase_76 AC 54 ms
45,252 KB
testcase_77 AC 58 ms
40,868 KB
testcase_78 AC 50 ms
41,612 KB
testcase_79 AC 53 ms
42,660 KB
testcase_80 AC 1 ms
4,380 KB
testcase_81 AC 50 ms
41,268 KB
testcase_82 AC 52 ms
43,908 KB
testcase_83 AC 53 ms
42,468 KB
testcase_84 AC 50 ms
40,588 KB
testcase_85 AC 50 ms
40,692 KB
testcase_86 AC 53 ms
40,952 KB
testcase_87 AC 53 ms
42,868 KB
testcase_88 AC 1 ms
4,380 KB
testcase_89 AC 50 ms
40,592 KB
testcase_90 AC 50 ms
41,844 KB
testcase_91 AC 51 ms
42,228 KB
testcase_92 AC 51 ms
41,748 KB
testcase_93 AC 53 ms
45,556 KB
testcase_94 WA -
testcase_95 AC 54 ms
43,552 KB
testcase_96 AC 51 ms
41,028 KB
testcase_97 WA -
testcase_98 WA -
testcase_99 WA -
testcase_100 WA -
testcase_101 WA -
testcase_102 WA -
testcase_103 WA -
testcase_104 WA -
testcase_105 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

typedef long long ll;

ll a[15];
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;

	a[1] = 9ll;
	a[2] = 9ll;

	for (i = 3; i < 12; i+=2) {
		a[i] = (a[i - 1] + 1ll) * 9ll;
		a[i + 1] = a[i];
	}

	if (N < 1000000001ll) {
		printf("0\n");
	}
	else {
		ll sum = 0ll;
		int d = digit(N);
		if (d == 19) {
			d = 18;
			N = 999999999999999999ll;
		}
		for (i = 10; i < d; i++) {
			sum += a[i - 9];
		}
		for (i = 1; i <= 9; i++) {
			v[1].push_back(to_string(i));
		}
		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 = 1; k <= 9; k++) {
				string ss = to_string(k);
				for (j = 0; j < i - 2; j++) {
					ss += to_string(0);
				}
				ss += to_string(k);
				v[i].push_back(ss);
			}
			for (k = 1; 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);
				}
			}
		}
		for (i = 0; i < v[d - 9].size(); i++) {
			string s = v[d - 9][i];
			for (j = 0; j < b[d - 9]; j++) {
				s += to_string(0);
			}
			s += v[d - 9][i];
			if (stoll(s) <= N) {
				sum += 1ll;
			}
		}
		printf("%lld\n",sum);
	}

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