結果
問題 | No.31 悪のミックスジュース |
ユーザー | 夕叢霧香(ゆうむらきりか) |
提出日時 | 2018-01-05 13:08:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 119 ms / 5,000 ms |
コード長 | 2,500 bytes |
コンパイル時間 | 2,244 ms |
コンパイル使用メモリ | 74,452 KB |
実行使用メモリ | 52,784 KB |
最終ジャッジ日時 | 2023-10-12 17:19:57 |
合計ジャッジ時間 | 4,875 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
51,824 KB |
testcase_01 | AC | 105 ms
52,508 KB |
testcase_02 | AC | 105 ms
51,980 KB |
testcase_03 | AC | 106 ms
52,212 KB |
testcase_04 | AC | 107 ms
52,156 KB |
testcase_05 | AC | 112 ms
52,404 KB |
testcase_06 | AC | 60 ms
50,364 KB |
testcase_07 | AC | 108 ms
52,212 KB |
testcase_08 | AC | 108 ms
52,280 KB |
testcase_09 | AC | 119 ms
52,440 KB |
testcase_10 | AC | 107 ms
52,176 KB |
testcase_11 | AC | 81 ms
52,188 KB |
testcase_12 | AC | 98 ms
52,224 KB |
testcase_13 | AC | 59 ms
50,172 KB |
testcase_14 | AC | 110 ms
52,260 KB |
testcase_15 | AC | 78 ms
52,152 KB |
testcase_16 | AC | 95 ms
52,784 KB |
ソースコード
import java.io.*; import java.util.*; class Main { static final long I=1L<<62; static final int W=100000; 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; } } }