結果

問題 No.491 10^9+1と回文
ユーザー GrenacheGrenache
提出日時 2017-03-11 00:19:15
言語 Java21
(openjdk 21)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,853 bytes
コンパイル時間 7,461 ms
コンパイル使用メモリ 78,696 KB
実行使用メモリ 64,724 KB
最終ジャッジ日時 2024-04-08 16:07:22
合計ジャッジ時間 33,617 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 255 ms
63,468 KB
testcase_01 AC 252 ms
63,468 KB
testcase_02 AC 283 ms
63,628 KB
testcase_03 AC 274 ms
63,820 KB
testcase_04 MLE -
testcase_05 MLE -
testcase_06 AC 255 ms
63,948 KB
testcase_07 AC 264 ms
63,732 KB
testcase_08 AC 247 ms
63,628 KB
testcase_09 AC 283 ms
63,996 KB
testcase_10 MLE -
testcase_11 AC 252 ms
63,636 KB
testcase_12 AC 252 ms
63,644 KB
testcase_13 MLE -
testcase_14 MLE -
testcase_15 MLE -
testcase_16 AC 272 ms
63,724 KB
testcase_17 MLE -
testcase_18 AC 249 ms
63,544 KB
testcase_19 AC 253 ms
63,732 KB
testcase_20 MLE -
testcase_21 AC 257 ms
63,700 KB
testcase_22 MLE -
testcase_23 MLE -
testcase_24 AC 248 ms
62,628 KB
testcase_25 AC 257 ms
63,552 KB
testcase_26 MLE -
testcase_27 AC 249 ms
63,704 KB
testcase_28 AC 248 ms
63,356 KB
testcase_29 AC 252 ms
63,756 KB
testcase_30 MLE -
testcase_31 AC 252 ms
63,080 KB
testcase_32 MLE -
testcase_33 AC 253 ms
63,616 KB
testcase_34 AC 251 ms
63,276 KB
testcase_35 MLE -
testcase_36 MLE -
testcase_37 AC 267 ms
62,792 KB
testcase_38 AC 253 ms
62,200 KB
testcase_39 AC 250 ms
63,284 KB
testcase_40 MLE -
testcase_41 AC 282 ms
63,880 KB
testcase_42 AC 275 ms
63,640 KB
testcase_43 MLE -
testcase_44 AC 274 ms
63,568 KB
testcase_45 MLE -
testcase_46 AC 283 ms
63,208 KB
testcase_47 AC 254 ms
62,788 KB
testcase_48 MLE -
testcase_49 AC 244 ms
61,440 KB
testcase_50 AC 252 ms
63,628 KB
testcase_51 MLE -
testcase_52 MLE -
testcase_53 MLE -
testcase_54 MLE -
testcase_55 MLE -
testcase_56 AC 275 ms
63,620 KB
testcase_57 AC 254 ms
63,736 KB
testcase_58 AC 295 ms
63,788 KB
testcase_59 MLE -
testcase_60 MLE -
testcase_61 AC 269 ms
63,424 KB
testcase_62 AC 278 ms
63,048 KB
testcase_63 MLE -
testcase_64 MLE -
testcase_65 AC 256 ms
61,628 KB
testcase_66 AC 261 ms
63,580 KB
testcase_67 AC 262 ms
63,724 KB
testcase_68 AC 261 ms
63,736 KB
testcase_69 MLE -
testcase_70 MLE -
testcase_71 AC 254 ms
63,884 KB
testcase_72 AC 266 ms
63,764 KB
testcase_73 MLE -
testcase_74 MLE -
testcase_75 AC 250 ms
63,368 KB
testcase_76 MLE -
testcase_77 AC 270 ms
63,528 KB
testcase_78 AC 256 ms
63,316 KB
testcase_79 MLE -
testcase_80 AC 250 ms
63,588 KB
testcase_81 AC 248 ms
63,164 KB
testcase_82 AC 258 ms
63,752 KB
testcase_83 MLE -
testcase_84 MLE -
testcase_85 AC 273 ms
63,784 KB
testcase_86 MLE -
testcase_87 AC 264 ms
63,468 KB
testcase_88 MLE -
testcase_89 MLE -
testcase_90 AC 259 ms
63,448 KB
testcase_91 AC 257 ms
63,668 KB
testcase_92 MLE -
testcase_93 MLE -
testcase_94 AC 259 ms
63,732 KB
testcase_95 AC 245 ms
63,716 KB
testcase_96 AC 251 ms
63,672 KB
testcase_97 AC 252 ms
62,940 KB
testcase_98 MLE -
testcase_99 AC 245 ms
63,584 KB
testcase_100 MLE -
testcase_101 AC 244 ms
63,488 KB
testcase_102 AC 248 ms
63,928 KB
testcase_103 MLE -
testcase_104 MLE -
testcase_105 AC 253 ms
63,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


public class Main_yukicoder491 {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		long n = sc.nextLong();

		long t = 1_000_000_001;

		int ret = 0;
		for (int i = 1; i < 10_000; i++) {
			if (i % 10 == 0) {
				continue;
			}

			StringBuilder tmp = new StringBuilder();
			tmp.append(i);
			if (t * i <= n) {
				if (isPalindrome(tmp)) {
					ret++;
				}
			}

			while (tmp.length() <= 4) {
				int m = tmp.length();

				StringBuilder tmp2 = new StringBuilder();
				for (int j = 0; j < m; j++) {
					tmp2.append(tmp.charAt(m - 1 - j));
				}
				for (int j = 0; j < m; j++) {
					tmp2.append(tmp.charAt(j));
				}
				long ltmp = Long.parseLong(tmp2.toString());
				if (ltmp > 9999 && ltmp < 1_000_000_000 && t * ltmp <= n) {
					ret++;
				}

				for (int c = 0; c < 10; c++) {
					tmp2 = new StringBuilder();
					for (int j = 0; j < m; j++) {
						tmp2.append(tmp.charAt(m - 1 - j));
					}
					tmp2.append((char)('0' + c));
					for (int j = 0; j < m; j++) {
						tmp2.append(tmp.charAt(j));
					}
					ltmp = Long.parseLong(tmp2.toString());
					if (ltmp > 9999 && ltmp < 1_000_000_000 && t * ltmp <= n) {
						ret++;
					}
				}

				tmp.insert(0, '0');
			}
		}

		pr.println(ret);
	}

	private static boolean isPalindrome(StringBuilder str) {
		int n = str.length();

		boolean flag = true;
		for (int i = 0; i < n / 2; i++) {
			if (str.charAt(i) != str.charAt(n - 1 - i)) {
				flag = false;
				break;
			}
		}

		return flag;
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}
0