結果

問題 No.509 塗りつぶしツール
ユーザー OlderInvestor
提出日時 2017-10-30 21:23:01
言語 Java
(openjdk 23)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 3,651 ms
コンパイル使用メモリ 79,468 KB
実行使用メモリ 41,368 KB
最終ジャッジ日時 2024-11-22 10:56:23
合計ジャッジ時間 8,392 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class No509 {
    char[] nC;
    HashSet<Character> more1 = new HashSet<>();

    public static void main(String[] args) {
        No509 main = new No509();
        main.run();
    }

    private void run() {
        String n = new Scanner(System.in).next();
        nC = n.toCharArray();
        more1.addAll(Arrays.asList('0', '4', '6', '9'));

        int res, res2;
        if((res= p1()) < (res2 = p2())) {
            System.out.println(res);
        } else {
            System.out.println(res2);
        }
    }

    private int p1() {
        int cnt = nC.length + 1;
        for(char each : nC) {
            if( more1.contains(each) ) cnt++;
            if(each == '8') cnt += 2;
        }
        return cnt + nC.length;
    }

    private int p2() {
        int cnt = 1;
        for(char each : nC) {
            if( more1.contains(each) ) cnt++;
            if(each == '8') cnt += 2;
        }
        cnt += nC.length + 1;
        for(char each : nC) {
            if( more1.contains(each) ) cnt++;
            if(each == '8') cnt += 2;
        }
        return cnt;
    }
}
0