Submission #1144696

#TimeUsernameProblemLanguageResultExecution timeMemory
1144696SmuggingSpunPalembang Bridges (APIO15_bridge)C++20
22 / 100
27 ms1476 KiB
#include<bits/stdc++.h>
#define taskname "C"
using namespace std;
typedef long long ll;
int k, n;
namespace sub12{
	void solve(){
		ll ans = 0;
		vector<int>p;
		for(int i = 0; i < n; i++){
			char a, b;
			int xa, xb;
			cin >> a >> xa >> b >> xb;
			if(a == b){
				ans += abs(xa - xb);
			}
			else{
				p.emplace_back(xa);
				p.emplace_back(xb);
				ans++;
			}
		}
		if(!p.empty()){
			sort(p.begin(), p.end());
			int median = p[int(p.size()) >> 1];
			for(int& x : p){
				ans += abs(median - x);
			}
		}
		cout << ans;
	}
}
namespace sub345{
	void solve(){
		
	}
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen(taskname".inp", "r")){
		freopen(taskname".inp", "r", stdin);
	}
	cin >> k >> n;
	if(k == 1){
		sub12::solve();
	}
	else{
		sub345::solve();
	}
}

Compilation message (stderr)

bridge.cpp: In function 'int main()':
bridge.cpp:41:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |                 freopen(taskname".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...