結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2014-11-25 01:21:17 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 270 ms / 5,000 ms |
コード長 | 2,982 bytes |
コンパイル時間 | 3,682 ms |
コンパイル使用メモリ | 80,440 KB |
実行使用メモリ | 40,672 KB |
最終ジャッジ日時 | 2024-12-27 11:03:17 |
合計ジャッジ時間 | 10,933 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.BitSet; import java.util.Comparator; import java.util.List; import java.util.TreeSet; public class Main { public static int w; public static int k; public static int n; // public static int[][] dp; public static int[] a; public static int[] b; public static List<double[]> list = new ArrayList<double[]>(); public static TreeSet<Integer> set = new TreeSet<Integer>(); // public static PriorityQueue<Integer> pq = new PriorityQueue<Integer>(); public static void main(String[] args) throws NumberFormatException, IOException{ ContestScanner in = new ContestScanner(); n = in.nextInt(); int[] sushi = new int[n]; long[] dp = new long[1000*100+1]; for(int i=0; i<n; i++){ sushi[i] = in.nextInt(); } dp[sushi[0]] = 1; for(int i=1; i<n; i++){ if(dp[sushi[i]] == 0) dp[sushi[i]] = i+1; int max = 100000 - sushi[i]; for(int j=max; j>=0; j--){ if(dp[j] > 0 && dp[j + sushi[i]] == 0 && dp[j] < i){ dp[j + sushi[i]] = i+1; } } } for(int i=0; i<=10; i++){ System.err.print(dp[i]+" "); } int count = 100000; while(dp[count--] == 0); System.out.println(count+1); } } class Node{ int id; List<Node> edge = new ArrayList<Node>(); public Node(int id){ this.id = id; } public void createEdge(Node node){ edge.add(node); } } class MyMath{ public static long fact(long n){ long res = 1; while(n > 0){ res *= n--; } return res; } public static long[][] pascalT(int n){ long[][] tri = new long[n][]; for(int i=0; i<n; i++){ tri[i] = new long[i+1]; for(int j=0; j<i+1; j++){ if(j == 0 || j == i){ tri[i][j] = 1; }else{ tri[i][j] = tri[i-1][j-1] + tri[i-1][j]; } } } return tri; } } class MyComp implements Comparator<Integer>{ public int compare(Integer arg0, Integer arg1) { return arg0 - arg1; } } // //class MyCompB implements Comparator<int[]>{ // public int compare(int[] arg0, int[] arg1) { // return arg0[1] - arg1[1]; // } //} class ContestScanner{ private BufferedReader reader; private String[] line; private int idx; public ContestScanner() throws FileNotFoundException{ reader = new BufferedReader(new InputStreamReader(System.in)); } public String nextToken() throws IOException{ if(line == null || line.length <= idx){ line = reader.readLine().trim().split(" "); idx = 0; } return line[idx++]; } public long nextLong() throws IOException, NumberFormatException{ return Long.parseLong(nextToken()); } public int nextInt() throws NumberFormatException, IOException{ return (int)nextLong(); } public double nextDouble() throws NumberFormatException, IOException{ return Double.parseDouble(nextToken()); } }