結果

問題 No.791 うし数列
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-22 21:53:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 2,116 ms
コンパイル使用メモリ 75,080 KB
実行使用メモリ 54,272 KB
最終ジャッジ日時 2024-05-04 01:58:19
合計ジャッジ時間 4,612 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 93 ms
52,720 KB
testcase_01 AC 94 ms
53,068 KB
testcase_02 AC 103 ms
54,080 KB
testcase_03 AC 106 ms
53,456 KB
testcase_04 AC 116 ms
54,152 KB
testcase_05 AC 103 ms
52,808 KB
testcase_06 AC 99 ms
53,912 KB
testcase_07 AC 116 ms
53,920 KB
testcase_08 AC 112 ms
53,832 KB
testcase_09 AC 97 ms
52,680 KB
testcase_10 AC 97 ms
52,888 KB
testcase_11 AC 108 ms
54,272 KB
testcase_12 AC 108 ms
54,072 KB
testcase_13 AC 107 ms
54,088 KB
testcase_14 AC 106 ms
53,944 KB
testcase_15 AC 100 ms
52,720 KB
testcase_16 AC 100 ms
52,860 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static public void main(String[]args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		printAns(n);
	}

	static void printAns(String s) throws Exception {
		if( isValid(s) ) {
			int ans = s.length() -1;
			System.out.println(ans);
		} else {
			System.out.println(-1);
		}
	}

	static boolean isValid(String s) throws Exception {

		if(s.charAt(0) != '1') return false;

		if(!s.contains("3")) return false;

		for(int i=1; i<s.length(); i++) {
			char c = s.charAt(i);
			if( c != '3') return false;
		}

		return true;
	}
}
0