Submission #1964149
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[2][(n + 1) / 2 + 10][(n + 1) / 2 + 10]; 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 k = 0; k <= 1; ++k) { 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) { g[k][i - j][j + 1] = Math.min(g[k][i - j][j + 1], g[k][i - j][j] + a[i][0] + j * (a[i][0] + a[i][1])); g[k][i - j + 1][j] = Math.min(g[k][i - j + 1][j], g[k][i - j][j] + a[i][1] + (i - j) * (a[i][0] + a[i][1])); if (k == 0) { g[1][i - j][j] = Math.min(g[1][i - j][j], g[0][i - j][j] + (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 | 709 ms |
Memory | 161044 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 | AC | 680 ms | 158004 KB |
001.txt | AC | 308 ms | 52676 KB |
002.txt | AC | 662 ms | 155064 KB |
003.txt | WA | 576 ms | 120628 KB |
004.txt | AC | 672 ms | 158464 KB |
005.txt | WA | 374 ms | 71568 KB |
006.txt | AC | 672 ms | 160740 KB |
007.txt | AC | 423 ms | 75100 KB |
008.txt | AC | 671 ms | 156432 KB |
009.txt | AC | 249 ms | 36868 KB |
010.txt | AC | 674 ms | 157208 KB |
011.txt | AC | 413 ms | 68704 KB |
012.txt | AC | 668 ms | 159428 KB |
013.txt | AC | 243 ms | 32624 KB |
014.txt | AC | 698 ms | 159960 KB |
015.txt | WA | 295 ms | 50912 KB |
016.txt | AC | 683 ms | 156704 KB |
017.txt | AC | 562 ms | 118192 KB |
018.txt | AC | 647 ms | 160524 KB |
019.txt | WA | 400 ms | 69528 KB |
020.txt | AC | 97 ms | 18768 KB |
021.txt | AC | 97 ms | 21204 KB |
022.txt | AC | 708 ms | 157072 KB |
023.txt | AC | 684 ms | 156384 KB |
024.txt | AC | 682 ms | 156496 KB |
025.txt | AC | 664 ms | 159740 KB |
026.txt | AC | 662 ms | 156220 KB |
027.txt | AC | 668 ms | 157708 KB |
028.txt | AC | 681 ms | 158256 KB |
029.txt | AC | 624 ms | 157352 KB |
030.txt | AC | 694 ms | 159256 KB |
031.txt | AC | 686 ms | 159324 KB |
032.txt | AC | 698 ms | 156704 KB |
033.txt | AC | 665 ms | 154892 KB |
034.txt | AC | 687 ms | 159464 KB |
035.txt | AC | 644 ms | 161044 KB |
036.txt | AC | 709 ms | 159620 KB |
037.txt | AC | 694 ms | 156484 KB |
038.txt | AC | 667 ms | 160040 KB |
039.txt | AC | 680 ms | 155500 KB |
040.txt | AC | 684 ms | 156596 KB |
041.txt | AC | 671 ms | 154104 KB |
042.txt | AC | 671 ms | 156808 KB |
example0.txt | AC | 95 ms | 21844 KB |
example1.txt | AC | 100 ms | 21588 KB |