結果

問題 No.220 世界のなんとか2
ユーザー 37zigen37zigen
提出日時 2020-03-27 16:28:04
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 1,000 ms
コード長 3,330 bytes
コンパイル時間 4,282 ms
コンパイル使用メモリ 75,304 KB
実行使用メモリ 56,116 KB
最終ジャッジ日時 2023-08-30 16:27:18
合計ジャッジ時間 8,502 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,884 KB
testcase_01 AC 126 ms
55,568 KB
testcase_02 AC 126 ms
55,608 KB
testcase_03 AC 127 ms
55,588 KB
testcase_04 AC 126 ms
55,884 KB
testcase_05 AC 126 ms
56,116 KB
testcase_06 AC 128 ms
55,368 KB
testcase_07 AC 126 ms
55,504 KB
testcase_08 AC 126 ms
55,640 KB
testcase_09 AC 126 ms
55,812 KB
testcase_10 AC 126 ms
55,948 KB
testcase_11 AC 126 ms
55,684 KB
testcase_12 AC 127 ms
55,536 KB
testcase_13 AC 129 ms
55,408 KB
testcase_14 AC 125 ms
53,936 KB
testcase_15 AC 125 ms
55,864 KB
testcase_16 AC 126 ms
55,400 KB
testcase_17 AC 123 ms
55,540 KB
testcase_18 AC 123 ms
55,688 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {
		long t = System.currentTimeMillis();
		new Main().run();
		System.err.println(System.currentTimeMillis() - t);
	}
	
	long pow(long a,long n) {
		long ret=1;
		for(;n>0;n>>=1,a*=a)if(n%2==1)ret*=a;
		return ret;
	}
	
	long comb(long n,long k) {
		if(n<0||k<0||n-k<0)return 0;
		long ret=1;
		for(long i=n;i>=n-k+1;--i)ret*=i;
		for(long i=k;i>=1;--i)ret/=i;
		return ret;
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		int N=sc.nextInt();
		long[][][] dp=new long[N+1][3][2];
		dp[0][0][0]=1;
		for(int i=0;i<N;++i) {
			for(int used3=0;used3<=1;++used3) {
				for(int cur_sum=0;cur_sum<3;++cur_sum) {
					for(int add=0;add<=9;++add) {
						int next_sum=(cur_sum+add)%3;
						int next_used3=used3|(add==3?1:0);
						dp[i+1][next_sum][next_used3]+=dp[i][cur_sum][used3];
					}
				}
			}
		}
		long ans=0;
		for(int i=0;i<3;++i) {
			for(int j=0;j<=1;++j) {
				if(i!=0&&j!=1)continue;
				ans+=dp[N][i][j];
			}
		}
		System.out.println(ans-1);
	}
	
	static void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

}
	
	
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    
    public int nextInt() {
    	return (int)nextLong();
    }
}
0