結果

問題 No.45 回転寿司
ユーザー Humming_sangoHumming_sango
提出日時 2023-03-03 18:51:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 1,583 bytes
コンパイル時間 2,109 ms
コンパイル使用メモリ 77,604 KB
実行使用メモリ 53,636 KB
最終ジャッジ日時 2023-10-18 01:12:45
合計ジャッジ時間 5,735 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 56 ms
53,624 KB
testcase_01 AC 58 ms
53,624 KB
testcase_02 AC 58 ms
53,624 KB
testcase_03 AC 58 ms
53,624 KB
testcase_04 AC 59 ms
53,612 KB
testcase_05 AC 56 ms
53,600 KB
testcase_06 AC 58 ms
53,624 KB
testcase_07 AC 59 ms
53,612 KB
testcase_08 AC 56 ms
53,604 KB
testcase_09 AC 59 ms
53,624 KB
testcase_10 AC 57 ms
53,612 KB
testcase_11 AC 56 ms
53,608 KB
testcase_12 AC 59 ms
53,620 KB
testcase_13 AC 55 ms
53,592 KB
testcase_14 AC 54 ms
53,588 KB
testcase_15 AC 57 ms
53,612 KB
testcase_16 AC 56 ms
53,608 KB
testcase_17 AC 56 ms
52,520 KB
testcase_18 AC 58 ms
53,636 KB
testcase_19 AC 58 ms
53,628 KB
testcase_20 AC 56 ms
53,592 KB
testcase_21 AC 55 ms
52,548 KB
testcase_22 AC 55 ms
53,596 KB
testcase_23 AC 56 ms
53,592 KB
testcase_24 AC 55 ms
53,588 KB
testcase_25 AC 55 ms
53,596 KB
testcase_26 AC 57 ms
53,576 KB
testcase_27 AC 59 ms
53,612 KB
testcase_28 AC 56 ms
53,604 KB
testcase_29 AC 58 ms
53,636 KB
testcase_30 AC 58 ms
53,620 KB
testcase_31 AC 56 ms
53,588 KB
testcase_32 AC 57 ms
53,596 KB
testcase_33 AC 60 ms
53,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
 
public class Main {
	
	public static void main(String[] args) {
		FastReader fr = new FastReader();
		int n = fr.nextInt();
		int[] v = new int[n];
		for(int i=0;i<n;i++) {
			v[i] = fr.nextInt();
		}
		int[][] dp = new int[n+1][2];
		for(int i=0;i<n;i++) {
			dp[i+1][1] = Math.max(dp[i+1][1], dp[i][0]+v[i]);
			dp[i+1][0] = Math.max(dp[i+1][0], Math.max(dp[i][0], dp[i][1]));
		}
		System.out.println(Math.max(dp[n][0], dp[n][1]));
	}
	
}

class FastReader {
	private final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in), 0x10000);
	private StringTokenizer tokenizer;
	
	String next() {
		try{
			while(tokenizer==null || !tokenizer.hasMoreTokens()) {
				tokenizer = new StringTokenizer(reader.readLine());
			} 
		}catch(IOException e){
			e.printStackTrace();
		}
		return tokenizer.nextToken();
		
	}
	
	int nextInt() {
		return Integer.parseInt(next());
	}
	
	long nextLong() {
		return Long.parseLong(next());
	}
	
	double nextDouble(){
		return Double.parseDouble(next());
	}
	
	char[] nextCharArray() {
        return next().toCharArray();
    }
	
	char nextSingleChar() { //一文字じゃなかったら' '(空白文字)返す
		char[] c = next().toCharArray();
		if(c.length==1) {
			return c[0]; 
		}else {
			return ' ';
		}
	}
	
	String[] nextStringArray(int n) {
	        String[] s = new String[n];
	        for (int i = 0; i < n; i++) {
	            s[i] = next();
	        }
	        return s;
	    }

}
0