Submission #380458

#TimeUsernameProblemLanguageResultExecution timeMemory
380458PixelCatPalembang Bridges (APIO15_bridge)C++14
22 / 100
46 ms4328 KiB
/*                                                       
  /^--^\                                                 
  \____/                                                 
 /      \ _____  _ __  __ ____  _     ____   ____  _____ 
|        || ()_)| |\ \/ /| ===|| |__ / (__` / () \|_   _|
 \__  __/ |_|   |_|/_/\_\|____||____|\____)/__/\__\ |_|  
|^|^\ \^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|^|
| | |\ \| | | | | | | | | | | | | | | | | | | | | | | | |
#####/ /#################################################
| | |\/ | | | | | | | | | | | | | | | | | | | | | | | | |
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|*/
//#pragma GCC optimize("O4,unroint-loops,no-stack-protector")
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<ll,ll>;
//using pii=pair<int,int>;
#define int ll //__int128
#define double long double

#define For(i,a,b)  for(int i=a;i<=b;i++)
#define Forr(i,a,b) for(int i=a;i>=b;i--)
#define F first
#define S second
#define L(id) (id*2+1)
#define R(id) (id*2+2)
#define LO(x) (x&(-x))

#define eb emplace_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define mkp make_pair

#define MOD (int)(998244353)
#define INF (int)(1e15)
#define EPS (1e-9)

#ifdef LOCALMEOW
#define debug(...) do{\
	cerr << __LINE__ <<\
	" : ("#__VA_ARGS__ << ") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T> void _OUT(T x) { cerr << x << "\n"; }
template<typename T,typename...I>
void _OUT(T x,I ...tail) { cerr << x << ", "; _OUT(tail...); }
#else
#define debug(...)
#endif
inline void NYA(){ ios::sync_with_stdio(false); cin.tie(0); }

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//mt19937 rng((ull)new char);
int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }
int fpow(int b,int p,const int &mod){
	int ans=1,now=b;
	while(p){
		if(p&1) ans=ans*now%mod;
		p/=2; now=now*now%mod;
	}
	return ans;
}
int fpow(int b,int p) { return fpow(b,p,MOD); }
void chmin(int &a,const int &b) { if(b<a) a=b; }
void chmax(int &a,const int &b) { if(b>a) a=b; }

int32_t main(){
	NYA();
	//shinon >/////<
	int K,n; cin>>K>>n;
	assert(K==1);
	vector<int> v;
	char c1,c2;
	int x1,x2;
	int ans=0;
	while(n--){
		cin>>c1>>x1>>c2>>x2;
		if(c1==c2) ans+=abs(x1-x2);
		else{
			v.eb(x1); v.eb(x2);
			ans++;
		}
	}
	sort(all(v));
	int k=v[sz(v)/2];
	for(auto &i:v)
		ans+=abs(k-i);
	cout<<ans<<"\n";
	return 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...