結果

問題 No.1595 The Final Digit
ユーザー tentententen
提出日時 2021-07-12 12:20:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,844 bytes
コンパイル時間 2,705 ms
コンパイル使用メモリ 74,572 KB
実行使用メモリ 49,492 KB
最終ジャッジ日時 2023-09-14 20:32:48
合計ジャッジ時間 4,600 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,492 KB
testcase_01 AC 43 ms
49,292 KB
testcase_02 AC 42 ms
49,296 KB
testcase_03 AC 44 ms
49,452 KB
testcase_04 AC 44 ms
49,324 KB
testcase_05 AC 42 ms
47,520 KB
testcase_06 AC 44 ms
49,400 KB
testcase_07 AC 42 ms
49,360 KB
testcase_08 AC 43 ms
49,300 KB
testcase_09 AC 43 ms
49,384 KB
testcase_10 AC 43 ms
49,348 KB
testcase_11 AC 44 ms
49,296 KB
testcase_12 AC 43 ms
49,348 KB
testcase_13 AC 44 ms
49,368 KB
testcase_14 AC 43 ms
49,392 KB
testcase_15 AC 44 ms
49,304 KB
testcase_16 AC 43 ms
49,444 KB
testcase_17 AC 43 ms
49,280 KB
testcase_18 AC 44 ms
49,340 KB
testcase_19 AC 43 ms
49,400 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int current = sc.nextInt() % 10 * 100 + sc.nextInt() % 10 * 10 + sc.nextInt() % 10;
        long k = sc.nextLong();
        int[] place = new int[1000];
        int count = 0;
        int interval = 0;
        for (int i = 4; i <= 1004; i++) {
            if (i == k) {
                System.out.println((current / 100 + current % 100 / 10 + current % 10) % 10);
                return;
            }
             if (place[current] != 0) {
                count = place[current];
                interval = i - place[current];
                break;
            }
            
            place[current] = i;
            current = getNext(current);
        }
        long mod = (k - count) % interval;
        int ans = 0;
        for (int i = 0; i < 1000; i++) {
            if (count + mod == place[i]) {
                System.out.println((i / 100 + i % 100 / 10 + i % 10) % 10);
                return;
            }
        }
    }
    
    static int getNext(int x) {
        int count = x / 100 + x % 100 / 10 + x % 10;
        count %= 10;
        return (x * 10 + count) % 1000;
    }
}
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public String next() throws Exception {
        if (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
}
0