# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
302738 | 2020-09-19T06:26:21 Z | anishrajeev | Prosjek (COCI18_prosjek) | Java 11 | 90 ms | 10592 KB |
import java.io.*; import java.util.*; public class prosjek { static int N; public static void main(String[] args) throws IOException { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); //BufferedReader bf = new BufferedReader(new FileReader("tester.in")); PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out)); N = Integer.parseInt(bf.readLine()); ArrayList<Double> arr = new ArrayList<>(); for(int i = 0; i < N; i++)arr.add(Double.parseDouble(bf.readLine())); ArrayList<Double>[] dp = new ArrayList[N+1]; for(int i = 0; i <= N; i++)dp[i] = new ArrayList<>(); dp[N] = new ArrayList<>(arr); for(int i = N-1; i >= 1; i--){ ArrayList<Double> arrList = new ArrayList<>(dp[i + 1]); ArrayList<Double> answer = new ArrayList<>(); double minaverage = Double.MAX_VALUE; for(int p1 = 0; p1 <= i; p1++){ for(int p2 = 0; p2 < p1; p2++){ ArrayList<Double> temp = new ArrayList<>(dp[i + 1]); double avrge = (arrList.get(p1)+arrList.get(p2))/2.0; if(avrge < minaverage){ temp.remove(p1); temp.remove(p2); temp.add(avrge); answer = new ArrayList<>(temp); minaverage = avrge; } } } dp[i] = answer; } pw.println(dp[1].get(0)); pw.close(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 88 ms | 10472 KB | Output is correct |
2 | Correct | 82 ms | 10472 KB | Output is correct |
3 | Correct | 83 ms | 10344 KB | Output is correct |
4 | Correct | 89 ms | 10356 KB | Output is correct |
5 | Correct | 82 ms | 10248 KB | Output is correct |
6 | Correct | 81 ms | 10360 KB | Output is correct |
7 | Correct | 87 ms | 10484 KB | Output is correct |
8 | Correct | 87 ms | 10592 KB | Output is correct |
9 | Correct | 90 ms | 10432 KB | Output is correct |
10 | Correct | 86 ms | 10508 KB | Output is correct |