# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1069510 | 2024-08-22T04:13:38 Z | Luvidi | Palembang Bridges (APIO15_bridge) | C++17 | 2 ms | 348 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define pll pair<ll, ll> #define pii pair<int, int> #define fs first #define sc second #define pb push_back void solve() { freopen("in","r",stdin); freopen("out","w",stdout); int br,n; cin>>br>>n; vector<pll> seg; ll sum=0; while(n--){ char x,y; ll a,b; cin>>x>>a>>y>>b; if(a>b)swap(a,b); if(x==y)sum+=b-a; else{ seg.pb({a,b}); sum++; } } n=seg.size(); if(!n){ cout<<sum; return; } if(br==1){ ll ans=1e18; for(int i=0;i<n;i++){ ll s=0; for(int j=0;j<n;j++){ s+=abs(seg[j].fs-seg[i].fs)+abs(seg[i].fs-seg[j].sc); } ans=min(ans,s); } cout<<sum+ans; }else{ ll ans=1e18; for(int i=0;i<n;i++){ for(int j=i+1;j<n;j++){ ll s=0; for(int k=0;k<n;k++){ s+=min(abs(seg[k].fs-seg[i].fs)+abs(seg[i].fs-seg[k].sc),abs(seg[k].fs-seg[j].fs)+abs(seg[j].fs-seg[k].sc)); } ans=min(ans,s); } } cout<<sum+ans; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 344 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |