Submission #1087125
Source Code Expand
#include<stdio.h> #include<algorithm> using namespace std; struct point { int b, e; bool operator<(const point &p)const{ return e-b<p.e-p.b; } }w[5010]; int n; long long Res, D[5010][5010][2]; int main(){ int i, j, k; scanf("%d",&n); for(i=1;i<=n;i++){ scanf("%d%d",&w[i].b,&w[i].e); w[i].b = -w[i].b; } sort(w+1,w+n+1); Res = 1e18; for(i=0;i<=n;i++)for(j=0;i+j<=n;j++)for(k=0;k<2;k++)D[i][j][k]=1e18; D[0][0][0] = 0; for(i=0;i<n;i++){ for(j=0;j+i<n;j++){ int x = n-i-j; if(w[x].e-w[x].b == w[1].e-w[1].b){ D[i][j][1] = min(D[i][j][1], D[i][j][0] + 1ll*(n/2)*(w[x].e-w[x].b)); } for(k=0;k<2;k++){ int x = n-i-j-k; D[i+1][j][k] = min(D[i+1][j][k], D[i][j][k] + w[x].e + 1ll*(w[x].e-w[x].b)*i); D[i][j+1][k] = min(D[i][j+1][k], D[i][j][k] + -w[x].b + 1ll*(w[x].e-w[x].b)*j); } } } if(n%2==0){ for(i=0;i<=n;i++)Res = min(Res, D[i][n-i][0]); printf("%lld\n",Res); } else{ printf("%lld\n",D[n/2][n/2][1]); } }
Submission Info
Submission Time | |
---|---|
Task | F - Intervals |
User | ainta |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1202 Byte |
Status | WA |
Exec Time | 331 ms |
Memory | 215040 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:14:19: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:16:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d",&w[i].b,&w[i].e); ^
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 | 321 ms | 215040 KB |
001.txt | AC | 66 ms | 43136 KB |
002.txt | AC | 321 ms | 215040 KB |
003.txt | WA | 245 ms | 164224 KB |
004.txt | AC | 319 ms | 215040 KB |
005.txt | AC | 127 ms | 84224 KB |
006.txt | AC | 320 ms | 215040 KB |
007.txt | AC | 162 ms | 107776 KB |
008.txt | AC | 321 ms | 215040 KB |
009.txt | AC | 36 ms | 23168 KB |
010.txt | AC | 322 ms | 215040 KB |
011.txt | AC | 141 ms | 93312 KB |
012.txt | AC | 321 ms | 215040 KB |
013.txt | AC | 30 ms | 19456 KB |
014.txt | AC | 321 ms | 215040 KB |
015.txt | AC | 66 ms | 43520 KB |
016.txt | AC | 321 ms | 215040 KB |
017.txt | AC | 241 ms | 161152 KB |
018.txt | AC | 321 ms | 215040 KB |
019.txt | AC | 155 ms | 102528 KB |
020.txt | AC | 1 ms | 128 KB |
021.txt | AC | 1 ms | 128 KB |
022.txt | AC | 331 ms | 215040 KB |
023.txt | AC | 320 ms | 215040 KB |
024.txt | AC | 321 ms | 215040 KB |
025.txt | AC | 321 ms | 215040 KB |
026.txt | AC | 321 ms | 215040 KB |
027.txt | AC | 320 ms | 215040 KB |
028.txt | AC | 321 ms | 215040 KB |
029.txt | AC | 320 ms | 215040 KB |
030.txt | AC | 321 ms | 215040 KB |
031.txt | AC | 320 ms | 215040 KB |
032.txt | AC | 320 ms | 215040 KB |
033.txt | AC | 319 ms | 215040 KB |
034.txt | AC | 321 ms | 215040 KB |
035.txt | AC | 321 ms | 215040 KB |
036.txt | AC | 320 ms | 215040 KB |
037.txt | AC | 322 ms | 215040 KB |
038.txt | AC | 322 ms | 215040 KB |
039.txt | AC | 320 ms | 215040 KB |
040.txt | AC | 321 ms | 215040 KB |
041.txt | AC | 320 ms | 215040 KB |
042.txt | AC | 321 ms | 215040 KB |
example0.txt | AC | 1 ms | 128 KB |
example1.txt | AC | 1 ms | 256 KB |