提出 #306357


ソースコード 拡げる

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
		try {
			Scanner sc = new Scanner(System.in);
			int n;
			n = sc.nextInt();
			final int max = (int) Math.pow(10, n);
			int num = 0;
			int[] counter = new int[n];
			for (int i=0; i<n; i++) counter[i] = 0;
			final List<Integer> list = new ArrayList<Integer>();
			while(true) {
				list.add(num);
				int j = 0;
				for (; j < n && counter[j] == 9; j++) {}
				int tmp = (int) Math.pow(10, j);
				int theDigit = calcTheDigit(num, j);
				num += (tmp * (theDigit == 9 ? -9 : 1));
				if (num >= max) break;
				counter[j] += 1;
				if (j-- == 0) continue;
				for (; j >= 0; j--) { counter[j] = 0; }
			}
			System.out.println(list.size() - 1);
			final String format = "%0" + n + "d";
			for (int i = 0; i < list.size(); i++) {
				System.out.println(String.format(format, list.get(i)));
			}
			sc.close();
		} catch (Exception e){
			System.err.println("Error");
		}
	}

	private static int calcTheDigit(int num, int pos) {
		int len = String.valueOf(num).length();
		int d = (int)Math.pow(10, len - 1);
		if (num < Math.pow(10, pos)) return 0;

		for (int i = len - 1; i > pos; i--) {
			num %= d;
			d /= 10;
		}
		return num / d;
	}
}

提出情報

提出日時
問題 A - Lock
ユーザ tomohiron
言語 Java (OpenJDK 1.7.0)
得点 100
コード長 1342 Byte
結果 AC
実行時間 2505 ms
メモリ 50192 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 100 / 100
結果
AC × 2
AC × 5
セット名 テストケース
Sample subtask0_sample_01.txt, subtask0_sample_02.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt
ケース名 結果 実行時間 メモリ
subtask0_sample_01.txt AC 516 ms 23292 KiB
subtask0_sample_02.txt AC 508 ms 23440 KiB
subtask1_01.txt AC 643 ms 25460 KiB
subtask1_02.txt AC 1555 ms 47636 KiB
subtask1_03.txt AC 2505 ms 50192 KiB