Submission #1964147
Source Code Expand
import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; class Main { public void run() { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); long[][] a = new long[n][2]; for (int i = 0; i < n; ++i) { a[i][0] = sc.nextLong(); a[i][1] = sc.nextLong(); } Arrays.sort(a, new Comparator<long[]>() { @Override public int compare(long[] arg0, long[] arg1) { return -Long.compare(arg0[0] + arg0[1], arg1[0] + arg1[1]); } }); long ans = Long.MAX_VALUE / 3; long[][][] g = new long[(n + 1) / 2 + 10][(n + 1) / 2 + 10][2]; for (int i = 0; i < g.length; ++i) for (int j = 0; j < g[i].length; ++j) for (int k = 0; k < g[i][j].length; ++k) g[i][j][k] = Long.MAX_VALUE / 3; g[0][0][0] = 0; for (int i = 0; i < n; ++i) { for (int j = Math.max(0, i - (n + 1) / 2); j <= Math.min(i, (n + 1) / 2); ++j) { for (int k = 0; k <= 1; ++k) { g[i - j][j + 1][k] = Math.min(g[i - j][j + 1][k], g[i - j][j][k] + a[i][0] + j * (a[i][0] + a[i][1])); g[i - j + 1][j][k] = Math.min(g[i - j + 1][j][k], g[i - j][j][k] + a[i][1] + (i - j) * (a[i][0] + a[i][1])); if (k == 0) { g[i - j][j][1] = Math.min(g[i - j][j][1], g[i - j][j][0] + (n - 1) * (a[i][0] + a[i][1])); } } } } for (int i = 0; i < g.length; ++i) for (int j = 0; j < g[i].length; ++j) for (int k = 0; k < g[i][j].length; ++k) if (i + j + k == n) ans = Math.min(ans, g[i][j][k]); System.out.println(ans); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } public static void main(String[] args) throws FileNotFoundException { new Main().run(); } }
Submission Info
Submission Time | |
---|---|
Task | F - Intervals |
User | fortoobye |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 1782 Byte |
Status | WA |
Exec Time | 2063 ms |
Memory | 293116 KB |
Judge Result
Set Name | Sample | All | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1000 | ||||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | MLE | 1959 ms | 287668 KB |
001.txt | AC | 486 ms | 78548 KB |
002.txt | MLE | 1953 ms | 293116 KB |
003.txt | WA | 1857 ms | 211136 KB |
004.txt | MLE | 1967 ms | 290560 KB |
005.txt | WA | 896 ms | 123404 KB |
006.txt | MLE | 1977 ms | 283336 KB |
007.txt | AC | 1281 ms | 158704 KB |
008.txt | MLE | 1985 ms | 288620 KB |
009.txt | AC | 268 ms | 52140 KB |
010.txt | MLE | 1972 ms | 285996 KB |
011.txt | AC | 1230 ms | 160964 KB |
012.txt | MLE | 1956 ms | 288420 KB |
013.txt | AC | 282 ms | 52004 KB |
014.txt | MLE | 1964 ms | 289136 KB |
015.txt | WA | 480 ms | 81184 KB |
016.txt | MLE | 1966 ms | 287128 KB |
017.txt | AC | 1731 ms | 216616 KB |
018.txt | MLE | 1942 ms | 291664 KB |
019.txt | WA | 1253 ms | 158212 KB |
020.txt | AC | 95 ms | 19412 KB |
021.txt | AC | 98 ms | 23508 KB |
022.txt | MLE | 1931 ms | 292104 KB |
023.txt | MLE | 1974 ms | 285376 KB |
024.txt | MLE | 1955 ms | 284896 KB |
025.txt | MLE | 1973 ms | 286900 KB |
026.txt | TLE | 2006 ms | 277052 KB |
027.txt | MLE | 1943 ms | 292448 KB |
028.txt | TLE | 2063 ms | 287044 KB |
029.txt | MLE | 1971 ms | 285608 KB |
030.txt | MLE | 1952 ms | 286640 KB |
031.txt | MLE | 1979 ms | 288752 KB |
032.txt | MLE | 1945 ms | 285484 KB |
033.txt | TLE | 2004 ms | 286580 KB |
034.txt | MLE | 1948 ms | 286044 KB |
035.txt | MLE | 1930 ms | 291520 KB |
036.txt | MLE | 1965 ms | 291220 KB |
037.txt | MLE | 1958 ms | 287148 KB |
038.txt | MLE | 1949 ms | 287948 KB |
039.txt | MLE | 1998 ms | 287420 KB |
040.txt | MLE | 1977 ms | 285992 KB |
041.txt | MLE | 1945 ms | 288528 KB |
042.txt | TLE | 2019 ms | 291464 KB |
example0.txt | AC | 99 ms | 21332 KB |
example1.txt | AC | 99 ms | 19412 KB |