結果

問題 No.791 うし数列
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2019-02-22 21:53:22
言語 Java21
(openjdk 21)
結果
AC  
実行時間 118 ms / 2,000 ms
コード長 610 bytes
コンパイル時間 2,029 ms
コンパイル使用メモリ 71,980 KB
実行使用メモリ 56,260 KB
最終ジャッジ日時 2023-08-16 18:21:55
合計ジャッジ時間 5,023 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 118 ms
54,260 KB
testcase_01 AC 114 ms
55,752 KB
testcase_02 AC 115 ms
55,764 KB
testcase_03 AC 115 ms
54,052 KB
testcase_04 AC 115 ms
56,260 KB
testcase_05 AC 115 ms
55,808 KB
testcase_06 AC 116 ms
55,756 KB
testcase_07 AC 117 ms
56,168 KB
testcase_08 AC 118 ms
55,852 KB
testcase_09 AC 117 ms
55,916 KB
testcase_10 AC 117 ms
56,084 KB
testcase_11 AC 117 ms
56,156 KB
testcase_12 AC 116 ms
56,172 KB
testcase_13 AC 115 ms
55,732 KB
testcase_14 AC 117 ms
56,020 KB
testcase_15 AC 115 ms
55,848 KB
testcase_16 AC 116 ms
55,764 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