結果
問題 | No.31 悪のミックスジュース |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2018-01-05 13:09:11 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 75 ms / 5,000 ms |
コード長 | 2,499 bytes |
コンパイル時間 | 3,412 ms |
コンパイル使用メモリ | 74,376 KB |
実行使用メモリ | 52,480 KB |
最終ジャッジ日時 | 2023-10-12 17:20:03 |
合計ジャッジ時間 | 4,168 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 48 ms
49,468 KB |
testcase_01 | AC | 71 ms
52,168 KB |
testcase_02 | AC | 73 ms
52,480 KB |
testcase_03 | AC | 67 ms
50,656 KB |
testcase_04 | AC | 67 ms
50,632 KB |
testcase_05 | AC | 73 ms
52,092 KB |
testcase_06 | AC | 46 ms
49,548 KB |
testcase_07 | AC | 70 ms
52,416 KB |
testcase_08 | AC | 70 ms
52,052 KB |
testcase_09 | AC | 72 ms
52,288 KB |
testcase_10 | AC | 72 ms
52,444 KB |
testcase_11 | AC | 57 ms
50,336 KB |
testcase_12 | AC | 70 ms
52,000 KB |
testcase_13 | AC | 46 ms
49,504 KB |
testcase_14 | AC | 71 ms
52,224 KB |
testcase_15 | AC | 57 ms
50,552 KB |
testcase_16 | AC | 75 ms
52,212 KB |
ソースコード
import java.io.*; import java.util.*; class Main { static final long I=1L<<62; static final int W=10000; public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); long v=sc.nextInt(); long[]c=new long[n]; for(int i=0;i<n;++i)c[i]=sc.nextInt(); for(int i=1;i<n;++i)c[i]+=c[i-1]; v-=n; long[]dp=new long[W]; Arrays.fill(dp,I); dp[0]=0; for(int i=0;i<n;++i) for(int j=0;j<W-(i+1);++j) dp[j+i+1]=Math.min(dp[j+i+1],dp[j]+c[i]); double max=-1.0/0.0; int maxind=-1; for(int i=0;i<n;++i){ double r=(i+1)/(double)c[i]; if(max<r){ max=r; maxind=i; } } long ans=I; for(int i=0;i<W;++i){ long cor=Math.max(0,(v-i+maxind)/(maxind+1)*c[maxind]); ans=Math.min(ans,dp[i]+cor); } ans+=c[n-1]; out.println(ans); out.close(); } // http://codeforces.com/blog/entry/7018 //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] nextIntArray(int n){ int[]r=new int[n]; for(int i=0;i<n;++i)r[i]=nextInt(); return r; } } }