Submission #1369840
Source Code Expand
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll n, ml, mr, ans, a[100005], b[100005]; multiset<ll> l, r; multiset<ll>::iterator last (multiset<ll> &S) { auto it = S.end(); it--; return it; } int main() { scanf("%lld",&n); for(ll i=1;i<=n;i++) { scanf("%lld%lld",&a[i],&b[i]); } l.insert(0); r.insert(0); ml = b[1]; mr = b[1]; for(ll i=2;i<=n;i++) { ml -= b[i-1] - a[i-1]; mr += b[i] - a[i]; if(ml <= b[i] && b[i] <= mr) { ll GL = b[i] - ml, GR = mr - b[i]; l.insert((*last(l))+GL); r.insert((*last(r))+GR); ml = b[i]; mr = b[i]; } else if(b[i] < ml) { ll G = ml - b[i]; ans += G; r.insert((*last(r))+mr-ml); auto it = last(l); ll V = (*it); l.erase(it); l.insert(V - G); l.insert(V - G); mr = ml; ml = mr - (V - (*last(l))); } else { ll G = b[i] - mr; ans += G; l.insert((*last(l))+mr-ml); auto it = last(r); ll V = (*it); r.erase(it); r.insert(V - G); r.insert(V - G); ml = mr; mr = ml + (V - (*last(r))); } } printf("%lld\n",ans); }
Submission Info
Submission Time | |
---|---|
Task | E - NarrowRectangles |
User | khsoo01 |
Language | C++14 (GCC 5.4.1) |
Score | 1000 |
Code Size | 1108 Byte |
Status | AC |
Exec Time | 85 ms |
Memory | 11136 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:14:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&n); ^ ./Main.cpp:16:32: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld%lld",&a[i],&b[i]); ^
Judge Result
Set Name | Sample | Subtask | All | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 300 / 300 | 700 / 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 | 1 ms | 256 KB |
0_001.txt | AC | 1 ms | 256 KB |
0_002.txt | AC | 1 ms | 256 KB |
0_003.txt | AC | 1 ms | 256 KB |
0_004.txt | AC | 1 ms | 256 KB |
1_005.txt | AC | 1 ms | 256 KB |
1_006.txt | AC | 1 ms | 256 KB |
1_007.txt | AC | 1 ms | 256 KB |
1_008.txt | AC | 1 ms | 256 KB |
1_009.txt | AC | 1 ms | 256 KB |
1_010.txt | AC | 1 ms | 256 KB |
1_011.txt | AC | 1 ms | 256 KB |
1_012.txt | AC | 1 ms | 256 KB |
1_013.txt | AC | 1 ms | 256 KB |
1_014.txt | AC | 1 ms | 256 KB |
1_015.txt | AC | 1 ms | 256 KB |
1_016.txt | AC | 1 ms | 256 KB |
1_017.txt | AC | 1 ms | 256 KB |
2_018.txt | AC | 85 ms | 11136 KB |
2_019.txt | AC | 79 ms | 11136 KB |
2_020.txt | AC | 72 ms | 11136 KB |
2_021.txt | AC | 51 ms | 11136 KB |
2_022.txt | AC | 51 ms | 11136 KB |
2_023.txt | AC | 51 ms | 11136 KB |
2_024.txt | AC | 51 ms | 11136 KB |
2_025.txt | AC | 51 ms | 11136 KB |
2_026.txt | AC | 51 ms | 11136 KB |
2_027.txt | AC | 51 ms | 11136 KB |
2_028.txt | AC | 51 ms | 11136 KB |
2_029.txt | AC | 51 ms | 11136 KB |
2_030.txt | AC | 50 ms | 11136 KB |
2_031.txt | AC | 85 ms | 11136 KB |
2_032.txt | AC | 85 ms | 11136 KB |
2_033.txt | AC | 85 ms | 11136 KB |
2_034.txt | AC | 83 ms | 11136 KB |
2_035.txt | AC | 83 ms | 11136 KB |
2_036.txt | AC | 76 ms | 11136 KB |