結果
問題 | No.258 回転寿司(2) |
ユーザー | 37zigen |
提出日時 | 2020-03-27 20:07:17 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 192 ms / 2,000 ms |
コード長 | 3,245 bytes |
コンパイル時間 | 2,142 ms |
コンパイル使用メモリ | 87,552 KB |
実行使用メモリ | 43,216 KB |
最終ジャッジ日時 | 2024-06-10 16:35:01 |
合計ジャッジ時間 | 16,515 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 184 ms
43,072 KB |
testcase_01 | AC | 190 ms
43,176 KB |
testcase_02 | AC | 166 ms
42,204 KB |
testcase_03 | AC | 115 ms
41,076 KB |
testcase_04 | AC | 158 ms
41,960 KB |
testcase_05 | AC | 161 ms
41,880 KB |
testcase_06 | AC | 180 ms
42,800 KB |
testcase_07 | AC | 132 ms
41,660 KB |
testcase_08 | AC | 156 ms
41,656 KB |
testcase_09 | AC | 136 ms
41,736 KB |
testcase_10 | AC | 125 ms
41,472 KB |
testcase_11 | AC | 142 ms
41,728 KB |
testcase_12 | AC | 160 ms
42,228 KB |
testcase_13 | AC | 131 ms
41,884 KB |
testcase_14 | AC | 181 ms
42,960 KB |
testcase_15 | AC | 142 ms
41,556 KB |
testcase_16 | AC | 138 ms
42,024 KB |
testcase_17 | AC | 134 ms
42,048 KB |
testcase_18 | AC | 181 ms
42,744 KB |
testcase_19 | AC | 106 ms
40,008 KB |
testcase_20 | AC | 175 ms
42,424 KB |
testcase_21 | AC | 187 ms
42,904 KB |
testcase_22 | AC | 116 ms
41,268 KB |
testcase_23 | AC | 105 ms
40,100 KB |
testcase_24 | AC | 109 ms
41,044 KB |
testcase_25 | AC | 111 ms
41,136 KB |
testcase_26 | AC | 167 ms
42,064 KB |
testcase_27 | AC | 147 ms
41,744 KB |
testcase_28 | AC | 186 ms
43,216 KB |
testcase_29 | AC | 139 ms
42,152 KB |
testcase_30 | AC | 121 ms
41,124 KB |
testcase_31 | AC | 114 ms
41,052 KB |
testcase_32 | AC | 137 ms
42,004 KB |
testcase_33 | AC | 176 ms
42,588 KB |
testcase_34 | AC | 161 ms
42,028 KB |
testcase_35 | AC | 159 ms
41,652 KB |
testcase_36 | AC | 121 ms
41,480 KB |
testcase_37 | AC | 122 ms
41,464 KB |
testcase_38 | AC | 152 ms
42,032 KB |
testcase_39 | AC | 139 ms
42,048 KB |
testcase_40 | AC | 178 ms
42,380 KB |
testcase_41 | AC | 175 ms
42,588 KB |
testcase_42 | AC | 152 ms
41,712 KB |
testcase_43 | AC | 125 ms
41,284 KB |
testcase_44 | AC | 177 ms
42,492 KB |
testcase_45 | AC | 178 ms
42,236 KB |
testcase_46 | AC | 100 ms
40,136 KB |
testcase_47 | AC | 172 ms
42,492 KB |
testcase_48 | AC | 124 ms
41,552 KB |
testcase_49 | AC | 131 ms
41,708 KB |
testcase_50 | AC | 104 ms
40,348 KB |
testcase_51 | AC | 167 ms
42,660 KB |
testcase_52 | AC | 159 ms
42,292 KB |
testcase_53 | AC | 129 ms
41,252 KB |
testcase_54 | AC | 168 ms
42,632 KB |
testcase_55 | AC | 192 ms
42,900 KB |
testcase_56 | AC | 168 ms
42,336 KB |
testcase_57 | AC | 126 ms
42,068 KB |
testcase_58 | AC | 161 ms
42,228 KB |
testcase_59 | AC | 179 ms
43,144 KB |
testcase_60 | AC | 119 ms
41,052 KB |
testcase_61 | AC | 169 ms
42,284 KB |
testcase_62 | AC | 143 ms
41,756 KB |
testcase_63 | AC | 166 ms
41,916 KB |
testcase_64 | AC | 181 ms
42,832 KB |
testcase_65 | AC | 171 ms
42,432 KB |
testcase_66 | AC | 112 ms
41,076 KB |
testcase_67 | AC | 172 ms
42,620 KB |
testcase_68 | AC | 172 ms
42,784 KB |
testcase_69 | AC | 170 ms
42,392 KB |
testcase_70 | AC | 133 ms
41,840 KB |
ソースコード
import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.ArrayDeque; import java.util.Arrays; import java.util.NoSuchElementException; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { long t = System.currentTimeMillis(); new Main().run(); System.err.println(System.currentTimeMillis() - t); } final long MOD=(long)1e9+7; void run() { Scanner sc = new Scanner(System.in); int N=sc.nextInt(); int[] V=new int[N]; int[][] max=new int[N][2]; for(int i=0;i<N;++i)V[i]=sc.nextInt(); for(int i=0;i<N;++i) { max[i][0]=Math.max(V[i]+(i>=2?max[i-2][0]:0), (i>0?max[i-1][0]:0)); if(max[i][0]==V[i]+(i>=2?max[i-2][0]:0)){ max[i][1]=i; }else { max[i][1]=max[i-1][1]; } } ArrayDeque<Integer> list=new ArrayDeque<>(); long ans=0; int p=N-1,res=max[p][0]; while(p>=0) { if(max[p][1]!=p||res!=max[p][0]) { --p; continue; } list.addFirst(p+1); ans+=V[p]; res-=V[p]; p-=2; } System.out.println(ans); while(!list.isEmpty()) { System.out.print(list.pollFirst()+(list.isEmpty()?"\n":" ")); } } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } } 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 hasNextByte() { 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 int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;} public boolean hasNext() { skipUnprintable(); return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { return (int)nextLong(); } }