Submission #2668058


Source Code Expand

// atcoder arc70
#include <bits/stdc++.h>
#define debug 0

using namespace std;

typedef long long ll;

/*
for every number, find the left and right bound
*/

priority_queue<ll> l;
priority_queue<ll, vector<ll>, greater<ll>> r;

ll lo = 0;
ll ro = 0;
void printpq(){
	vector<ll> temp;
	printf("L: ");
	while(!l.empty()){
		temp.push_back(l.top());
		printf("%d ", l.top()-lo);
		l.pop();
	}
	printf("\n");
	for(auto i : temp) l.push(i);
	temp.clear();
	printf("R: ");
	while(!r.empty()){
		temp.push_back(r.top());
		printf("%d ", r.top()+ro);
		r.pop();
	}
	for(auto i : temp) r.push(i);
	temp.clear();
	printf("\n");
	printf("\n");
}
ll n;
int main(){
	if(debug) freopen("narrowrectangles.in", "r", stdin);
	cin >> n;
	ll a,b; cin >> a >> b;
	l.push(a);
	r.push(a);
	ll prvlen = b-a;
	ll ans = 0;
	for(ll i = 1; i<n; i++){
		cin >> a >> b;
		ll len = b-a;
		lo += len;
		ro += prvlen;
		if(a <= l.top()-lo){
			ans += l.top()-lo -a;
			l.push(a+lo);
			l.push(a+lo);
			r.push(l.top()-lo-ro);
			l.pop();
		}else if(a >= r.top()+ro){	
			ans +=a-(r.top()+ro);
			r.push(a-ro);
			r.push(a-ro);
			l.push(r.top()+ro+lo);
			r.pop();
		}else{
			l.push(a+lo);
			r.push(a-ro);
		}
		prvlen = len;
		if(debug) printpq();
	}
	cout << ans;
}

Submission Info

Submission Time
Task E - NarrowRectangles
User tch1001
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 1313 Byte
Status AC
Exec Time 94 ms
Memory 2036 KB

Compile Error

./Main.cpp: In function ‘void printpq()’:
./Main.cpp:23:27: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
   printf("%d ", l.top()-lo);
                           ^
./Main.cpp:32:27: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=]
   printf("%d ", r.top()+ro);
                           ^
./Main.cpp: In function ‘int main()’:
./Main.cpp:42:54: warning: ignoring return value of ‘FILE* freopen(const char*, const char*, FILE*)’, declared with attribute warn_unused_result [-Wunused-result]
  if(debug) freopen("narrowrectangles.in", "r", stdin);
                                                      ^

Judge Result

Set Name Sample Subtask All
Score / Max Score 0 / 0 300 / 300 700 / 700
Status
AC × 5
AC × 13
AC × 37
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 73 ms 2036 KB
2_019.txt AC 66 ms 2036 KB
2_020.txt AC 66 ms 2036 KB
2_021.txt AC 91 ms 1984 KB
2_022.txt AC 91 ms 1976 KB
2_023.txt AC 91 ms 1980 KB
2_024.txt AC 91 ms 1948 KB
2_025.txt AC 91 ms 1976 KB
2_026.txt AC 91 ms 1884 KB
2_027.txt AC 91 ms 2036 KB
2_028.txt AC 90 ms 1928 KB
2_029.txt AC 91 ms 1976 KB
2_030.txt AC 91 ms 1972 KB
2_031.txt AC 93 ms 1980 KB
2_032.txt AC 93 ms 1984 KB
2_033.txt AC 93 ms 1976 KB
2_034.txt AC 94 ms 1980 KB
2_035.txt AC 89 ms 2036 KB
2_036.txt AC 86 ms 2036 KB