結果

問題 No.653 E869120 and Lucky Numbers
ユーザー tetsu
提出日時 2018-02-23 23:20:51
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,850 bytes
コンパイル時間 3,975 ms
コンパイル使用メモリ 78,208 KB
実行使用メモリ 50,928 KB
最終ジャッジ日時 2024-10-10 03:12:31
合計ジャッジ時間 7,303 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class C {

	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner(System.in);
		String p = sc.next();
		int[] ds = new int[20000];
		for(int i=0; i<p.length(); i++) {
			ds[i] = Character.getNumericValue(p.charAt(p.length()-1-i));
		}
		for(int i=0; i<p.length(); i++) {
			if(i==p.length()-1) {
				if(ds[i]==0 || ds[i]==7 || ds[i]==6) {
					System.out.println("Yes");
					return;
				} else {
					System.out.println("No");
					return;
				}
			}
			if(ds[i]==2||ds[i]==3||ds[i]==4) {
				if(ds[i+1]>=1) {
					ds[i+1]--;
				} else {
					boolean f = false;
					int j=i+2;
					while(j<p.length() && ds[j]==0) {
						ds[j]=9;
						j++;
					}
					if(j<p.length()) {
						ds[j]--;
						f = true;
					}
					if(f) {
						ds[i+1]--;
					} else {
						System.out.println("No");
						return;
					}
				}
			} else {
				System.out.println("No");
				return;
			}
		}
	}

	static class MyScanner
	{
		BufferedReader br;
		StringTokenizer st;
		public MyScanner(InputStream s)
		{
			br=new BufferedReader(new InputStreamReader(s));
		}
		public String nextLine() throws IOException
		{
			return br.readLine();
		}
		public String next() throws IOException
		{
			while(st==null || !st.hasMoreTokens())
				st=new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		public int nextInt() throws IOException
		{
			return Integer.parseInt(next());
			
		}
		public double nextDouble() throws IOException
		{
			return Double.parseDouble(next());
		}
		public boolean ready() throws IOException
		{
			return br.ready();
		}
		public long nextLong() throws IOException
		{
			return Long.parseLong(next());
		}
	}
}
0