結果

問題 No.45 回転寿司
ユーザー CavasiroCavasiro
提出日時 2020-05-02 18:34:24
言語 Java21
(openjdk 21)
結果
AC  
実行時間 46 ms / 5,000 ms
コード長 3,325 bytes
コンパイル時間 2,561 ms
コンパイル使用メモリ 74,984 KB
実行使用メモリ 50,436 KB
最終ジャッジ日時 2023-08-29 06:51:09
合計ジャッジ時間 6,118 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
49,804 KB
testcase_01 AC 44 ms
50,204 KB
testcase_02 AC 44 ms
49,960 KB
testcase_03 AC 44 ms
49,888 KB
testcase_04 AC 44 ms
49,908 KB
testcase_05 AC 42 ms
49,368 KB
testcase_06 AC 45 ms
50,040 KB
testcase_07 AC 43 ms
49,892 KB
testcase_08 AC 44 ms
49,432 KB
testcase_09 AC 46 ms
49,956 KB
testcase_10 AC 45 ms
49,876 KB
testcase_11 AC 43 ms
49,196 KB
testcase_12 AC 46 ms
49,948 KB
testcase_13 AC 43 ms
49,176 KB
testcase_14 AC 43 ms
49,384 KB
testcase_15 AC 46 ms
49,916 KB
testcase_16 AC 44 ms
49,268 KB
testcase_17 AC 45 ms
49,996 KB
testcase_18 AC 44 ms
49,276 KB
testcase_19 AC 45 ms
50,128 KB
testcase_20 AC 44 ms
49,300 KB
testcase_21 AC 43 ms
49,200 KB
testcase_22 AC 42 ms
49,288 KB
testcase_23 AC 43 ms
49,380 KB
testcase_24 AC 44 ms
49,236 KB
testcase_25 AC 43 ms
49,300 KB
testcase_26 AC 46 ms
49,832 KB
testcase_27 AC 45 ms
50,004 KB
testcase_28 AC 45 ms
49,912 KB
testcase_29 AC 45 ms
50,436 KB
testcase_30 AC 44 ms
49,712 KB
testcase_31 AC 42 ms
49,352 KB
testcase_32 AC 43 ms
49,484 KB
testcase_33 AC 46 ms
50,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.NoSuchElementException;

class Main implements Runnable {
	private final FastScanner sc;
	private final PrintWriter out;
	//private final long MOD = 1000000007;
	//private final int[] d8x = {-1,0,1,1,1,0,-1,-1};
	//private final int[] d8y = {-1,-1,-1,0,1,1,1,0};
	//private final int[] d4x = {0,1,0,-1};
	//private final int[] d4y = {-1,0,1,0};
	int n;
	int[] v;

	public static void main(String[] args) {
		new Thread(null, new Main(), "", 16L * 1024 * 1024).start();
	}

	Main() {
		sc = new FastScanner();
		out = new PrintWriter(System.out);
	}

	private void init() throws Exception {
		n = sc.nextInt();
		v = new int[n];
		for(int i = 0;i<n;i++){
			v[i] = sc.nextInt();
		}
	}

	private void solve() throws Exception{
		int[] dp = new int[n+1];
		dp[0] = 0;
		dp[1] = v[0];
		for(int i=2;i<=n;i++){
			dp[i] = Math.max(dp[i-1], dp[i-2] + v[i-1]);
		}
		out.println(dp[n]);
	}

	public void run() {
		try {
			init();
			sc.close();
			solve();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
		out.flush();
		out.close();
	}
}

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 read() {
		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 boolean hasNext() {
		while (read() && !isVisibleChar(buffer[ptr]))
			ptr++;
		return read();
	}

	private int getNextChar() {
		if (read()) {
			ptr++;
			return buffer[ptr - 1];
		} else {
			return -1;
		}
	}

	private static boolean isVisibleChar(int code) {
		return code >= 33 && code <= 126;
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = getNextChar();
		while (isVisibleChar(b)) {
			sb.appendCodePoint(b);
			b = getNextChar();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean sign = true;
		int b = getNextChar();
		if (b == '-') {
			sign = false;
			b = getNextChar();
		}
		if (b < '0' || b > '9') {
			throw new NumberFormatException();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isVisibleChar(b)) {
				return sign ? n : -n;
			} else {
				throw new NumberFormatException();
			}
			b = getNextChar();
		}
	}

	public int nextInt() {
		long n = nextLong();
		if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) n;
	}

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

	public void close() {
		try {
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

class IntQueue {
	protected int[] a;
	protected int head, tail;

	public IntQueue(int max) {
		a = new int[max];
	}

	public void offer(int x) {
		a[tail++] = x;
	}

	public int poll() {
		return a[head++];
	}

	public int peek() {
		return a[head];
	}
	
	public int size() {
		return tail - head;
	}
}
0