Submission #1370055


Source Code Expand

#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>  

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 15;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

multiset <ll> Sx1;
multiset <ll> Sx2;
ll off1, off2;

ll in[100050][2];
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%lld %lld", &in[i][0], &in[i][1]);

	ll ans = 0;
	Sx1.insert(0);
	Sx2.insert(0);
	for (i = 2; i <= N; i++) {
		ll v1 = in[i - 1][0] - in[i][1];
		ll v2 = in[i - 1][1] - in[i][0];

		off1 += v1;
		off2 += v2;
		ans -= (v2 - v1) * (i - 1);

		auto it = Sx2.begin();
		if (*it + off2 <= 0) {
			Sx2.insert(-off2);
			Sx2.insert(-off2);
		}
		else {
			Sx1.insert(-off1);
			Sx1.insert(-off1);
		}

		while (Sx2.size() > Sx1.size()) {
			auto it2 = Sx2.begin();
			ll v = *it2 + off2 - off1;
			Sx2.erase(it2);
			Sx1.insert(v);
		}
		while (Sx1.size() > Sx2.size()) {
			auto it1 = Sx1.end();
			it1--;
			ll v = *it1 + off1 - off2;
			Sx1.erase(it1);
			Sx2.insert(v);
		}
	}
	ll v = *(Sx2.begin()) + off2;
	for (auto it : Sx1) ans += v - (it + off1);
	for (auto it : Sx2) ans += (it + off2) - v;
	ans /= 2;
	return !printf("%lld\n", ans);	
}

Submission Info

Submission Time
Task E - NarrowRectangles
User dotorya
Language C++14 (GCC 5.4.1)
Score 1000
Code Size 2265 Byte
Status AC
Exec Time 106 ms
Memory 11136 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:60:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &N);
                 ^
./Main.cpp:61:67: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  for (i = 1; i <= N; i++) scanf("%lld %lld", &in[i][0], &in[i][1]);
                                                                   ^

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 101 ms 11136 KB
2_019.txt AC 87 ms 11136 KB
2_020.txt AC 104 ms 11136 KB
2_021.txt AC 59 ms 11136 KB
2_022.txt AC 58 ms 11136 KB
2_023.txt AC 59 ms 11136 KB
2_024.txt AC 59 ms 11136 KB
2_025.txt AC 59 ms 11136 KB
2_026.txt AC 59 ms 11136 KB
2_027.txt AC 59 ms 11136 KB
2_028.txt AC 60 ms 11136 KB
2_029.txt AC 58 ms 11136 KB
2_030.txt AC 59 ms 11136 KB
2_031.txt AC 88 ms 11136 KB
2_032.txt AC 88 ms 11136 KB
2_033.txt AC 88 ms 11136 KB
2_034.txt AC 90 ms 11136 KB
2_035.txt AC 84 ms 11136 KB
2_036.txt AC 106 ms 11136 KB