結果

問題 No.491 10^9+1と回文
ユーザー tekitouktekitouk
提出日時 2017-03-11 02:30:00
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,517 bytes
コンパイル時間 769 ms
コンパイル使用メモリ 77,112 KB
実行使用メモリ 65,420 KB
最終ジャッジ日時 2023-09-06 15:10:30
合計ジャッジ時間 15,911 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 117 ms
63,300 KB
testcase_02 MLE -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 MLE -
testcase_07 MLE -
testcase_08 MLE -
testcase_09 MLE -
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 MLE -
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 MLE -
testcase_16 WA -
testcase_17 AC 115 ms
62,184 KB
testcase_18 MLE -
testcase_19 MLE -
testcase_20 AC 113 ms
59,484 KB
testcase_21 MLE -
testcase_22 AC 113 ms
59,844 KB
testcase_23 WA -
testcase_24 AC 114 ms
60,628 KB
testcase_25 AC 114 ms
60,628 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 114 ms
61,684 KB
testcase_28 AC 115 ms
59,476 KB
testcase_29 MLE -
testcase_30 WA -
testcase_31 AC 1 ms
4,380 KB
testcase_32 WA -
testcase_33 AC 114 ms
61,956 KB
testcase_34 MLE -
testcase_35 WA -
testcase_36 AC 1 ms
4,376 KB
testcase_37 MLE -
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 2 ms
4,376 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 MLE -
testcase_45 WA -
testcase_46 WA -
testcase_47 AC 113 ms
61,588 KB
testcase_48 AC 112 ms
61,016 KB
testcase_49 AC 1 ms
4,380 KB
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 AC 1 ms
4,380 KB
testcase_54 AC 114 ms
61,984 KB
testcase_55 AC 114 ms
61,568 KB
testcase_56 AC 114 ms
61,204 KB
testcase_57 MLE -
testcase_58 WA -
testcase_59 MLE -
testcase_60 WA -
testcase_61 AC 114 ms
59,788 KB
testcase_62 MLE -
testcase_63 WA -
testcase_64 MLE -
testcase_65 MLE -
testcase_66 MLE -
testcase_67 WA -
testcase_68 WA -
testcase_69 AC 2 ms
4,376 KB
testcase_70 AC 114 ms
60,188 KB
testcase_71 WA -
testcase_72 WA -
testcase_73 WA -
testcase_74 MLE -
testcase_75 MLE -
testcase_76 AC 114 ms
61,340 KB
testcase_77 MLE -
testcase_78 WA -
testcase_79 AC 113 ms
61,872 KB
testcase_80 AC 1 ms
4,376 KB
testcase_81 AC 114 ms
62,172 KB
testcase_82 MLE -
testcase_83 MLE -
testcase_84 MLE -
testcase_85 MLE -
testcase_86 AC 114 ms
60,912 KB
testcase_87 WA -
testcase_88 AC 1 ms
4,380 KB
testcase_89 WA -
testcase_90 WA -
testcase_91 MLE -
testcase_92 AC 113 ms
60,404 KB
testcase_93 WA -
testcase_94 WA -
testcase_95 AC 114 ms
63,248 KB
testcase_96 WA -
testcase_97 MLE -
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 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);
		for (i = 10; i < d; i++) {
			sum += a[i - 9];
		}
		for (i = 1; i <= 9; i++) {
			string s = to_string(i);
			for (j = 1; j <= 8; j++) {
				s += to_string(0);
			}
			s += to_string(i);
			v[1].push_back(s);
		}
		for (i = 11; i <= 99; i++) {
			if (i / 10 == i % 10) {
				string s = to_string(i);
				for (j = 1; j <= 7; j++) {
					s += to_string(0);
				}
				s += to_string(i);
				v[2].push_back(s);
			}
		}
		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++) {
			if (stoll(v[d - 9][i])<=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