Submission #1748661
Source Code Expand
#include <bits/stdc++.h> #define N 200010 #define BD 410 using namespace std; inline int read() { int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();} return x*f; } int n,L[N],R[N],F[N],G[N],len[N]; int main() { n=read(); for(int i=1;i<=n;i++) L[i]=read(), R[i]=read(); for(int i=1;i<=n;i++) if(L[i]>R[i]) swap(L[i],R[i]); for(int i=1;i<=n;i++) len[i]=R[i]-L[i]; for(int i=1;i<=10;i++) G[i]=fabs(L[1]-i); for(int i=2;i<=n;i++) { memset(F,0x3f,sizeof F); for(int j=1;j<=10;j++) { for(int k=1;k<=10;k++) { if(k>j+len[i-1]||k+len[i]<j) continue; else F[k]=min(F[k],G[j]+abs(L[i]-k)); } } for(int i=1;i<=10;i++) G[i]=F[i]; // for(int i=1;i<=10;i++) printf("%d ",F[i]); printf("\n"); } int Ans=0x3fffffff; for(int i=1;i<=10;i++) Ans=min(Ans,G[i]); cout << Ans << endl; return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - NarrowRectangles |
User | wcz111 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 944 Byte |
Status | WA |
Exec Time | 2107 ms |
Memory | 2176 KB |
Judge Result
Set Name | Sample | Subtask | All | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 300 | 0 / 700 | ||||||||||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt |
Subtask | 0_000, 0_001, 0_004, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt |
All | 0_000.txt, 0_001.txt, 0_002.txt, 0_003.txt, 0_004.txt, 1_005.txt, 1_006.txt, 1_007.txt, 1_008.txt, 1_009.txt, 1_010.txt, 1_011.txt, 1_012.txt, 1_013.txt, 1_014.txt, 1_015.txt, 1_016.txt, 1_017.txt, 2_018.txt, 2_019.txt, 2_020.txt, 2_021.txt, 2_022.txt, 2_023.txt, 2_024.txt, 2_025.txt, 2_026.txt, 2_027.txt, 2_028.txt, 2_029.txt, 2_030.txt, 2_031.txt, 2_032.txt, 2_033.txt, 2_034.txt, 2_035.txt, 2_036.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
0_000.txt | AC | 2 ms | 1024 KB |
0_001.txt | AC | 2 ms | 1024 KB |
0_002.txt | WA | 2 ms | 1024 KB |
0_003.txt | WA | 2 ms | 1024 KB |
0_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 17 ms | 1024 KB |
1_006.txt | WA | 17 ms | 1024 KB |
1_007.txt | AC | 17 ms | 1024 KB |
1_008.txt | WA | 17 ms | 1024 KB |
1_009.txt | WA | 17 ms | 1024 KB |
1_010.txt | WA | 17 ms | 1024 KB |
1_011.txt | WA | 17 ms | 1024 KB |
1_012.txt | WA | 17 ms | 1024 KB |
1_013.txt | WA | 17 ms | 1024 KB |
1_014.txt | WA | 17 ms | 1024 KB |
1_015.txt | WA | 17 ms | 1024 KB |
1_016.txt | WA | 17 ms | 1024 KB |
1_017.txt | WA | 17 ms | 1024 KB |
2_018.txt | TLE | 2103 ms | 2176 KB |
2_019.txt | TLE | 2103 ms | 2176 KB |
2_020.txt | TLE | 2103 ms | 2176 KB |
2_021.txt | TLE | 2103 ms | 2176 KB |
2_022.txt | TLE | 2103 ms | 2176 KB |
2_023.txt | TLE | 2103 ms | 2176 KB |
2_024.txt | TLE | 2103 ms | 2176 KB |
2_025.txt | TLE | 2103 ms | 2176 KB |
2_026.txt | TLE | 2103 ms | 2176 KB |
2_027.txt | TLE | 2103 ms | 2176 KB |
2_028.txt | TLE | 2103 ms | 2176 KB |
2_029.txt | TLE | 2103 ms | 2176 KB |
2_030.txt | TLE | 2107 ms | 2176 KB |
2_031.txt | TLE | 2103 ms | 2176 KB |
2_032.txt | TLE | 2103 ms | 2176 KB |
2_033.txt | TLE | 2103 ms | 2176 KB |
2_034.txt | TLE | 2103 ms | 2176 KB |
2_035.txt | TLE | 2103 ms | 2176 KB |
2_036.txt | TLE | 2103 ms | 2176 KB |