Submission #3444864
Source Code Expand
#include <stdio.h> #include <stdlib.h> #define int long long #define inf (int)(1e18) typedef struct { int L; int R; }pair; signed compair(const void *a, const void *b){ int sub = (((pair *)a)->L + ((pair *)a)->R) - (((pair *)b)->L + ((pair *)b)->R); if(sub > 0){ return -1; } else if(sub == 0){ return 0; } else{ return 1; } } int min(int a, int b){ return a <= b ? a : b; } signed main(){ int N, i, j, k, l; scanf("%lld", &N); pair *ps = (pair *)malloc(sizeof(pair) * N); for(i = 0; i < N; i++){ scanf("%lld%lld", &ps[i].L, &ps[i].R); } qsort(ps, N, sizeof(pair), compair); int ***dp = (int ***)malloc(sizeof(int **) * (N / 2 + 2)); for(i = 0; i <= N / 2 + 1; i++){ dp[i] = (int **)malloc(sizeof(int *) * (N / 2 + 2)); for(j = 0; j <= N / 2 + 1; j++){ dp[i][j] = (int *)malloc(sizeof(int) * (N % 2 + 1)); for(k = 0; k <= N % 2; k++){ dp[i][j][k] = inf; } } } dp[0][0][0] = 0; for(i = 0; i <= N / 2; i++){ for(j = 0; j <= N / 2; j++){ for(k = 0; k <= N % 2; k++){ l = i + j + k; if(l >= N){ continue; } dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k] + i * (ps[l].L + ps[l].R) + ps[l].R); dp[i][j + 1][k] = min(dp[i][j + 1][k], dp[i][j][k] + j * (ps[l].L + ps[l].R) + ps[l].L); if(k == 0 && N % 2 == 1 && l < N){ dp[i][j][1] = min(dp[i][j][1], dp[i][j][0] + (N / 2) * (ps[l].L + ps[l].R)); } } } } /* for(i = 0; i < N; i++){ for(j = 0; j < N; j++){ for(k = 0; k <= N % 2; k++){ printf("dp[%lld][%lld][%lld] = %lld\n", i, j, k, dp[i][j][k]); } } } */ printf("%lld\n", dp[N / 2][N / 2][N % 2]); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Intervals |
User | abc050 |
Language | C (GCC 5.4.1) |
Score | 1000 |
Code Size | 1694 Byte |
Status | AC |
Exec Time | 290 ms |
Memory | 244860 KB |
Compile Error
./Main.c: In function ‘main’: ./Main.c:30:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld", &N); ^ ./Main.c:33:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld%lld", &ps[i].L, &ps[i].R); ^
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 | 286 ms | 244860 KB |
001.txt | AC | 52 ms | 43644 KB |
002.txt | AC | 286 ms | 244860 KB |
003.txt | AC | 246 ms | 183932 KB |
004.txt | AC | 285 ms | 244860 KB |
005.txt | AC | 122 ms | 90236 KB |
006.txt | AC | 285 ms | 244860 KB |
007.txt | AC | 139 ms | 117756 KB |
008.txt | AC | 285 ms | 244860 KB |
009.txt | AC | 26 ms | 21628 KB |
010.txt | AC | 286 ms | 244860 KB |
011.txt | AC | 119 ms | 100860 KB |
012.txt | AC | 285 ms | 244860 KB |
013.txt | AC | 21 ms | 17660 KB |
014.txt | AC | 286 ms | 244860 KB |
015.txt | AC | 60 ms | 44028 KB |
016.txt | AC | 285 ms | 244860 KB |
017.txt | AC | 212 ms | 180348 KB |
018.txt | AC | 285 ms | 244860 KB |
019.txt | AC | 150 ms | 111612 KB |
020.txt | AC | 1 ms | 128 KB |
021.txt | AC | 1 ms | 128 KB |
022.txt | AC | 285 ms | 244860 KB |
023.txt | AC | 286 ms | 244860 KB |
024.txt | AC | 285 ms | 244860 KB |
025.txt | AC | 285 ms | 244860 KB |
026.txt | AC | 285 ms | 244860 KB |
027.txt | AC | 285 ms | 244860 KB |
028.txt | AC | 285 ms | 244860 KB |
029.txt | AC | 285 ms | 244860 KB |
030.txt | AC | 285 ms | 244860 KB |
031.txt | AC | 285 ms | 244860 KB |
032.txt | AC | 287 ms | 244860 KB |
033.txt | AC | 285 ms | 244860 KB |
034.txt | AC | 286 ms | 244860 KB |
035.txt | AC | 285 ms | 244860 KB |
036.txt | AC | 285 ms | 244860 KB |
037.txt | AC | 285 ms | 244860 KB |
038.txt | AC | 290 ms | 244860 KB |
039.txt | AC | 285 ms | 244860 KB |
040.txt | AC | 286 ms | 244860 KB |
041.txt | AC | 285 ms | 244860 KB |
042.txt | AC | 285 ms | 244860 KB |
example0.txt | AC | 1 ms | 128 KB |
example1.txt | AC | 1 ms | 128 KB |