제출 #905923

#제출 시각아이디문제언어결과실행 시간메모리
905923Muhammad_AneeqPalembang Bridges (APIO15_bridge)C++17
8 / 100
2059 ms2416 KiB
/* بسم الله الرحمن الرحيم Author: (:Muhammad Aneeq:) */ #include <iostream> #include <vector> #include <algorithm> using namespace std; #define int long long bool comp(pair<int,int>a,pair<int,int>b) { return (b.second>a.second); } void solve() { int k,n; cin>>k>>n; long long ans=0; vector<pair<int,int>>d; int z=0; for (int i=0;i<n;i++) { char a,b; int x,y; cin>>a>>x>>b>>y; if (a==b) ans+=abs(x-y); else { z+=abs(x-y); if (a=='B') swap(x,y); d.push_back({x,y}); } } if (d.size()) { long long f=1e15+10; for (auto i:d) { int z=i.first; long long g=0; for (auto j:d) g+=(abs(j.first-z)+abs(j.second-z))+1; f=min(f,g); g=0; z=i.second; for (auto j:d) g+=(abs(j.first-z)+abs(j.second-z))+1; f=min(f,g); } ans+=f; } cout<<ans<<endl; } signed main() { ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); solve(); }
#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...