結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2016-05-09 01:57:39 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 442 ms / 5,000 ms |
コード長 | 1,010 bytes |
コンパイル時間 | 3,994 ms |
コンパイル使用メモリ | 78,136 KB |
実行使用メモリ | 49,792 KB |
最終ジャッジ日時 | 2024-12-27 13:29:04 |
合計ジャッジ時間 | 9,579 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.util.*; import java.lang.*; import java.io.*; class Ideone{ public static void main(String[] args) throws Exception{ // your code goes here BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); String[] prm = br.readLine().split(" "); ArrayList<Integer> dish = new ArrayList<Integer>(); for(String st:prm){ dish.add(Integer.parseInt(st)); } calc(0,0,dish); System.out.println(max); } private static int max = 0; private static HashMap<Integer,Integer> map = new HashMap<Integer,Integer>(); private static void calc(int ans,int idx,ArrayList<Integer> dish){ if(map.containsKey(idx) && map.get(idx) > ans){ return; } map.put(idx,ans); if(idx >= dish.size()){ max = Math.max(ans,max); return; } calc(ans+dish.get(idx),idx+2,dish); calc(ans,idx+1,dish); return; } }