Submission #1360828


Source Code Expand

import java.util.Scanner;


public class Main {
	
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        
        int[] count = new int[26];
        System.out.println();
        
        char[] input = new char[line.length()];
        line.getChars(0, line.length(), input, 0);
        
        /*
        // アルファベットの数をカウント
        for (int i = 0; i < input.length; i++) {
			count[input[i]-'a']++;
		}
        
        // 一番多いアルファベットのカウントを調べる
        int max_count = 0;
        for (int i = 0; i < count.length; i++) {
        	if (max_count < count[i]) {
        		max_count = count[i];
        	}
//			System.out.println('a'+i+": " + count[i]);
		}
        
        
        */
        
        int seq_max_best = 100;
        // 一番多いアルファベットに対して、トライ
        for (int i = 0; i < count.length; i++) {
        	//System.out.println("try" + i);
//        	if (count[i] == max_count) {
	        	int seq_max = simulate('a' + i, input);
	        	if (seq_max_best > seq_max) {
	        		seq_max_best = seq_max;
	        	}
//        	}
		}
        
        
        
        System.out.println(seq_max_best);
        
        
	}
	
	public static int simulate(int max, char[] input) {
        int seq_max = 0;
        int seq = 0;
        // maxまでの文字数が一番長いものをカウント
        for (int i = 0; i < input.length; i++) {
			if (input[i] == max) {
				// 最長を見つけたらseq_maxにセットして、seqをリセット
				if (seq_max <= seq) {
					seq_max = seq;
					seq = 0;
				}
			} else {
				seq++;
			}
		}
        
        // 最後がmaxで終わらない文字列の時
		if (seq_max < seq) {
			seq_max = seq;
			seq = 0;
		}
		
		return seq_max;
	}
	

}

Submission Info

Submission Time
Task A - Shrinking
User tosi
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1962 Byte
Status WA
Exec Time 103 ms
Memory 23764 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 4
AC × 7
WA × 7
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 0_03.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt
Case Name Status Exec Time Memory
0_00.txt AC 102 ms 23764 KB
0_01.txt AC 103 ms 17364 KB
0_02.txt AC 96 ms 18900 KB
0_03.txt AC 89 ms 20688 KB
1_00.txt AC 91 ms 21332 KB
1_01.txt AC 90 ms 18644 KB
1_02.txt AC 89 ms 21844 KB
1_03.txt WA 89 ms 19668 KB
1_04.txt WA 89 ms 21204 KB
1_05.txt WA 91 ms 18644 KB
1_06.txt WA 97 ms 21844 KB
1_07.txt WA 89 ms 20560 KB
1_08.txt WA 88 ms 18772 KB
1_09.txt WA 89 ms 21844 KB