結果

問題 No.1136 Four Points Tour
ユーザー RISE70226821
提出日時 2020-09-29 16:32:23
言語 Java
(openjdk 23)
結果
AC  
実行時間 107 ms / 2,000 ms
コード長 2,695 bytes
コンパイル時間 1,987 ms
コンパイル使用メモリ 77,104 KB
実行使用メモリ 55,228 KB
最終ジャッジ日時 2024-07-04 00:31:28
合計ジャッジ時間 5,511 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 22 RE * 19
権限があれば一括ダウンロードができます

ソースコード

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