結果

問題 No.1136 Four Points Tour
ユーザー RISE70226821RISE70226821
提出日時 2020-09-29 16:32:23
言語 Java21
(openjdk 21)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 2,695 bytes
コンパイル時間 2,034 ms
コンパイル使用メモリ 74,420 KB
実行使用メモリ 65,308 KB
最終ジャッジ日時 2023-09-17 02:37:04
合計ジャッジ時間 5,774 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
49,764 KB
testcase_01 AC 38 ms
49,872 KB
testcase_02 AC 37 ms
49,532 KB
testcase_03 AC 35 ms
49,784 KB
testcase_04 AC 36 ms
49,388 KB
testcase_05 AC 37 ms
49,444 KB
testcase_06 AC 36 ms
49,368 KB
testcase_07 AC 73 ms
56,228 KB
testcase_08 AC 36 ms
49,880 KB
testcase_09 AC 37 ms
49,556 KB
testcase_10 AC 83 ms
60,168 KB
testcase_11 AC 39 ms
49,884 KB
testcase_12 AC 51 ms
49,840 KB
testcase_13 AC 36 ms
49,412 KB
testcase_14 AC 51 ms
49,956 KB
testcase_15 AC 38 ms
49,524 KB
testcase_16 AC 50 ms
49,796 KB
testcase_17 AC 52 ms
49,804 KB
testcase_18 AC 80 ms
60,116 KB
testcase_19 AC 97 ms
65,308 KB
testcase_20 AC 47 ms
49,596 KB
testcase_21 AC 82 ms
59,832 KB
01_Sample03_evil.txt RE -
04_Rnd_large_evil1.txt RE -
04_Rnd_large_evil2.txt RE -
04_Rnd_large_evil3.txt RE -
04_Rnd_large_evil4.txt RE -
04_Rnd_large_evil5.txt RE -
04_Rnd_large_evil6.txt RE -
04_Rnd_large_evil7.txt RE -
04_Rnd_large_evil8.txt RE -
04_Rnd_large_evil9.txt RE -
04_Rnd_large_evil10.txt RE -
05_Rnd_huge_evil1.txt RE -
05_Rnd_huge_evil2.txt RE -
05_Rnd_huge_evil3.txt RE -
05_Rnd_huge_evil4.txt RE -
05_Rnd_huge_evil5.txt RE -
05_Rnd_huge_evil6.txt RE -
05_Rnd_huge_evil7.txt RE -
99_evil_01.txt RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		// 入力
		FastScanner sc = new FastScanner(System.in);
		int N = sc.nextInt();
		int[][] dp = new int[4][N+10];
		int DIV = 1000000007;
		
		// DP表の作成
		dp[0][0] = 1;
		dp[1][0] = 0;
		dp[1][0] = 0;
		dp[1][0] = 0;
		for(int i = 0; i < N; i++){
			dp[0][i+1] = mod(dp[1][i], dp[2][i], dp[3][i], DIV);
			dp[1][i+1] = mod(dp[0][i], dp[2][i], dp[3][i], DIV);
			dp[2][i+1] = mod(dp[0][i], dp[1][i], dp[3][i], DIV);
			dp[3][i+1] = mod(dp[0][i], dp[1][i], dp[2][i], DIV);
		}
		
		// 出力
		System.out.println(dp[0][N]);
	}
	
	// 3数の和を指定数で割った余りを求める関数
	public static int mod(int a, int b, int c, int DIV){
		int result = (a + b) % DIV;
		result = (result + c) % DIV;
		return result;
	}


	// 高速スキャナー
    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
             return Double.parseDouble(next());
         }

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        } 
    }
}

0