Submission #1964167
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 / 2 + 10][n / 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 / 10; g[0][0][0] = 0; for (int i = 0; i < n; ++i) { for (int k = 0; k <= 1; ++k) { for (int j = Math.max(0, -n / 2 - k + i); j <= i - k && j <= n / 2; ++j) { g[k][i - j - k][j + 1] = Math.min(g[k][i - j - k][j + 1], g[k][i - j][j] + a[i][0] + j * (a[i][0] + a[i][1])); g[k][i - j - k + 1][j] = Math.min(g[k][i - j - k + 1][j], g[k][i - j - k][j] + a[i][1] + (i - j - k) * (a[i][0] + a[i][1])); } } if (n % 2 == 1) { for (int j = Math.max(0, -n / 2 + i); j <= Math.min(n / 2, i); ++j) { g[1][i - j][j] = Math.min(g[1][i - j][j], g[0][i - j][j] + (n - 1) / 2 * (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 | 1000 |
Code Size | 1901 Byte |
Status | AC |
Exec Time | 684 ms |
Memory | 161140 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1000 / 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 | 684 ms | 156044 KB |
001.txt | AC | 310 ms | 47968 KB |
002.txt | AC | 631 ms | 156648 KB |
003.txt | AC | 627 ms | 117720 KB |
004.txt | AC | 635 ms | 156968 KB |
005.txt | AC | 402 ms | 67868 KB |
006.txt | AC | 626 ms | 159460 KB |
007.txt | AC | 417 ms | 72980 KB |
008.txt | AC | 636 ms | 160132 KB |
009.txt | AC | 247 ms | 36520 KB |
010.txt | AC | 633 ms | 156848 KB |
011.txt | AC | 405 ms | 71960 KB |
012.txt | AC | 627 ms | 156316 KB |
013.txt | AC | 223 ms | 35084 KB |
014.txt | AC | 640 ms | 156524 KB |
015.txt | AC | 363 ms | 49908 KB |
016.txt | AC | 633 ms | 155068 KB |
017.txt | AC | 547 ms | 119496 KB |
018.txt | AC | 614 ms | 157388 KB |
019.txt | AC | 449 ms | 68984 KB |
020.txt | AC | 99 ms | 19924 KB |
021.txt | AC | 96 ms | 19284 KB |
022.txt | AC | 590 ms | 157296 KB |
023.txt | AC | 634 ms | 158876 KB |
024.txt | AC | 619 ms | 159228 KB |
025.txt | AC | 628 ms | 158304 KB |
026.txt | AC | 640 ms | 157720 KB |
027.txt | AC | 622 ms | 156224 KB |
028.txt | AC | 623 ms | 157608 KB |
029.txt | AC | 614 ms | 159648 KB |
030.txt | AC | 631 ms | 155540 KB |
031.txt | AC | 632 ms | 155952 KB |
032.txt | AC | 625 ms | 157784 KB |
033.txt | AC | 578 ms | 156552 KB |
034.txt | AC | 614 ms | 159584 KB |
035.txt | AC | 624 ms | 156596 KB |
036.txt | AC | 625 ms | 156292 KB |
037.txt | AC | 620 ms | 157172 KB |
038.txt | AC | 621 ms | 157452 KB |
039.txt | AC | 634 ms | 157060 KB |
040.txt | AC | 619 ms | 157380 KB |
041.txt | AC | 637 ms | 156776 KB |
042.txt | AC | 634 ms | 161140 KB |
example0.txt | AC | 98 ms | 18640 KB |
example1.txt | AC | 99 ms | 20812 KB |