Submission #1964139
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[][] f = new long[n + 1][n + 1]; for (int i = 0; i < f.length; ++i) for (int j = 0; j < f[i].length; ++j) f[i][j] = Long.MAX_VALUE / 3; f[0][0] = 0; for (int i = 0; i < n; ++i) { for (int j = 0; j <= i; ++j) { f[i - j][j + 1] = Math.min(f[i - j][j + 1], f[i - j][j] + a[i][0] + j * (a[i][0] + a[i][1])); f[i - j + 1][j] = Math.min(f[i - j + 1][j], f[i - j][j] + a[i][1] + (i - j) * (a[i][0] + a[i][1])); } } for (int i = 0; i <= n; ++i) { ans = Math.min(ans, f[i][n - i]); } if (n % 2 == 1) { long[][][] g = new long[n + 1][n + 1][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 = 0; j <= i; ++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])); } 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 | G - FESTIVAL |
User | fortoobye |
Language | Java8 (OpenJDK 1.8.0) |
Score | 0 |
Code Size | 2164 Byte |
Status | RE |
Exec Time | 2110 ms |
Memory | 511700 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, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, 050.txt, 051.txt, 052.txt, 053.txt, example0.txt, example1.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | RE | 120 ms | 19412 KB |
001.txt | RE | 96 ms | 19412 KB |
002.txt | RE | 95 ms | 21972 KB |
003.txt | RE | 96 ms | 21204 KB |
004.txt | RE | 96 ms | 20688 KB |
005.txt | RE | 130 ms | 53972 KB |
006.txt | RE | 1302 ms | 199756 KB |
007.txt | TLE | 2110 ms | 511700 KB |
008.txt | RE | 113 ms | 38604 KB |
009.txt | RE | 97 ms | 19668 KB |
010.txt | RE | 95 ms | 18768 KB |
011.txt | RE | 98 ms | 21844 KB |
012.txt | RE | 95 ms | 21844 KB |
013.txt | RE | 97 ms | 23764 KB |
014.txt | RE | 96 ms | 20812 KB |
015.txt | RE | 94 ms | 20180 KB |
016.txt | RE | 97 ms | 18640 KB |
017.txt | RE | 97 ms | 19028 KB |
018.txt | RE | 97 ms | 21076 KB |
019.txt | RE | 97 ms | 19156 KB |
020.txt | RE | 96 ms | 19284 KB |
021.txt | RE | 98 ms | 17620 KB |
022.txt | RE | 101 ms | 21332 KB |
023.txt | RE | 98 ms | 19668 KB |
024.txt | RE | 98 ms | 19284 KB |
025.txt | RE | 96 ms | 18640 KB |
026.txt | RE | 97 ms | 23380 KB |
027.txt | RE | 97 ms | 23124 KB |
028.txt | RE | 97 ms | 21716 KB |
029.txt | RE | 95 ms | 23764 KB |
030.txt | RE | 95 ms | 20948 KB |
031.txt | RE | 95 ms | 19412 KB |
032.txt | RE | 96 ms | 19028 KB |
033.txt | RE | 97 ms | 20820 KB |
034.txt | RE | 97 ms | 21716 KB |
035.txt | RE | 96 ms | 20564 KB |
036.txt | RE | 97 ms | 21204 KB |
037.txt | RE | 96 ms | 18640 KB |
038.txt | RE | 96 ms | 20820 KB |
039.txt | RE | 94 ms | 20684 KB |
040.txt | RE | 101 ms | 19540 KB |
041.txt | RE | 97 ms | 20692 KB |
042.txt | RE | 97 ms | 20564 KB |
043.txt | RE | 96 ms | 20820 KB |
044.txt | RE | 97 ms | 19284 KB |
045.txt | RE | 96 ms | 19668 KB |
046.txt | RE | 98 ms | 23252 KB |
047.txt | RE | 97 ms | 18772 KB |
048.txt | RE | 95 ms | 20692 KB |
049.txt | RE | 94 ms | 19924 KB |
050.txt | RE | 94 ms | 18644 KB |
051.txt | RE | 95 ms | 19668 KB |
052.txt | RE | 97 ms | 21332 KB |
053.txt | RE | 94 ms | 21844 KB |
example0.txt | RE | 96 ms | 21716 KB |
example1.txt | RE | 96 ms | 21204 KB |