Submission #414464

#TimeUsernameProblemLanguageResultExecution timeMemory
414464grtPalembang Bridges (APIO15_bridge)C++17
8 / 100
2079 ms2700 KiB
#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back

using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;

const int nax = 100 * 1000 + 10;
const ll INF = 1e18;
int n, m, k;
int opn[nax], clo[nax];
vi all;
ll add = 0;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> k >> n;
	for(int i = 0; i < n; ++i) {
		char t1, t2;
		int d1, d2;
		cin >> t1 >> d1 >> t2 >> d2;
		add += abs(d1 - d2);
		if(t1 != t2) {
			opn[m] = min(d1, d2);
			clo[m] = max(d1, d2);
			all.PB(d1);
			all.PB(d2);
			m++;
		}
	}
	sort(all.begin(), all.end());
	//sort(opn, opn + m);
	//sort(clo, clo + m);
	if(k == 1) {
		int ptr = 0, ptr2 = 0;
		ll Lsum = 0, Rsum = 0;
		if(m == 0) {
			cout << add << "\n";
			return 0;
		}
		ll ans = INF;
		for(int i = 0; i < m; ++i) Rsum += opn[i];
		for(int x : all) {
			//while(ptr2 < m && clo[ptr2] < x) {
				//Lsum += clo[ptr2];
				//ptr2++;
			//}
			//while(ptr < m && opn[ptr] < x) {
				//Rsum -= opn[ptr];
				//ptr++;
			//}
			//ll d = (ll)x * ptr2 - Lsum - (ll)x * (m - ptr) + Rsum;
			//ans = min(ans, d);
			ll d = 0;
			for(int i = 0; i < m; ++i) {
				if(opn[i] <= x && x <= clo[i]) continue;
				d += min(abs(x - opn[i]), abs(x - clo[i]));
			}
			ans = min(ans, d);
		}
		cout << ans * 2 + add + m << "\n";
	} else {
		
		
	}
	
}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:39:7: warning: unused variable 'ptr' [-Wunused-variable]
   39 |   int ptr = 0, ptr2 = 0;
      |       ^~~
bridge.cpp:39:16: warning: unused variable 'ptr2' [-Wunused-variable]
   39 |   int ptr = 0, ptr2 = 0;
      |                ^~~~
bridge.cpp:40:6: warning: unused variable 'Lsum' [-Wunused-variable]
   40 |   ll Lsum = 0, Rsum = 0;
      |      ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...