Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

Please spot the error!

Правка en1, от Whitewiz, 2024-07-20 12:33:51

problem

My solution :

include <bits/stdc++.h>

using namespace std;

define rep(i,a,b) for (int i = a; i < b; i++)

define ll long long

template istream& operator>>(istream& fin, vector& v) { for (auto it = v.begin(); it != v.end(); ++it) fin >> *it; return fin; } inline void solve(){ ll n;cin >> n; vector a(n),b(n); cin >> a >> b;

vector<ll> v = {a.front(),b.front(),a.back(),b.back()};
bool done[4] = {0};

ll ans = 0;
rep(i,0,4){
    if(done[i]){
        continue;
    }
    if(i & 1){
        ll mn = 1e10;
        for(auto j : a){
            mn = min(mn,abs(j - v[i]));
        }
        ans += mn;
        rep(j,0,4){
            if(!done[j] && mn == abs(v[j] - v[i])){
                done[j] = 1;
                break;
            }
        }
    }
    else{
        ll mn = 1e10;
        for(auto j : b){
            mn = min(mn,abs(j - v[i]));
        }
        ans += mn;
        rep(j,0,4){
            if(!done[j] && mn == abs(v[j] - v[i])){
                done[j] = 1;
                break;
            }
        }
    }
    done[i] = 1;
}
cout << ans;

} int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; cin >> t; while (t--) { solve(); cout<<endl; } return 0; }

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en3 Английский Whitewiz 2024-07-20 12:39:58 168
en2 Английский Whitewiz 2024-07-20 12:36:04 1485
en1 Английский Whitewiz 2024-07-20 12:33:51 1601 Initial revision (published)