結果

問題 No.491 10^9+1と回文
ユーザー 6soukiti296soukiti29
提出日時 2017-03-21 23:36:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,291 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2024-04-08 16:25:20
合計ジャッジ時間 5,774 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def kaibun(y):
	x = len(str(y))
	flag = 0
	X = [9,9]
	i = 2
	while x > i:
		if i % 2 == 0:
			X.append(X[i - 1] * 10)
		else:
			X.append(X[i - 1])
		i = i + 1
	a = sum(X[:x - 1])
	for j in range(1, x // 2 + 1):
		if j == 1:
			a = a + (int(str(y)[j - 1]) - 1) * X[x - 2 * j + 1]//9
		else:
			a = a + (int(str(y)[j - 1])) * X[x - 2 * j + 1] // 9
	if ((str(y)[:x//2][::-1] and str(y)[x//2 + 1:] and int(str(y)[:x//2][::-1]) <= int(str(y)[x//2:])) or (x == 2 and int(str(y)[x//2 - 1]) <= int(str(y)[x//2]))) and x % 2 == 0: 
		a = a + 1
		if (str(y)[:x//2][::-1] and str(y)[x//2 + 1:] and int(str(y)[:x//2][::-1]) == int(str(y)[x//2:])) or (int(str(y)[x//2 - 1]) == int(str(y)[x//2])):
			flag = 1
	elif x % 2 == 1:
		a = a + int(str(y)[x//2])
		if str(y)[:x//2][::-1] and str(y)[x//2 + 1:] and int(str(y)[:x//2][::-1]) <= int(str(y)[x//2 + 1:]):
			a = a + 1
			if int(str(y)[:x//2][::-1]) == int(str(y)[x//2 + 1:]):
				flag = 1
	if x == 1:
		return y,flag
	return a,flag
	# X[i] は i 桁の自然数のうち回文となるものの個数
n = input()
if len(n) < 10:
	print(0)
else:
	ni = n[:-9]
	k = int(ni)
	answer,flag = kaibun(k)
	if len(n) == 10 and int(n) % 10**9 < int(n[0]):
		answer = answer - 1
	if flag == 1 and int(ni[::-1]) > int(n[-9:]):
		answer = answer - 1
	print(answer)
0