結果

問題 No.3288 Sloppy Land Grading
ユーザー umimel
提出日時 2025-10-03 21:42:49
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 1,466 bytes
コンパイル時間 1,558 ms
コンパイル使用メモリ 170,980 KB
実行使用メモリ 7,716 KB
最終ジャッジ日時 2025-10-03 21:43:11
合計ジャッジ時間 3,989 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const ll MOD1000000007 = 1000000007;
const ll MOD998244353 = 998244353;
const ll MOD[3] = {999727999, 1070777777, 1000000007};
const ll LINF = 1LL << 60LL;
const int IINF = (1 << 30) - 1;


void solve(){
    ll A, B, C, x, y, z;
    cin >> A >> B >> C >> x >> y >> z;
    
    vector<pair<ll, ll>> vec;
    vec.push_back({A, x});
    vec.push_back({B, y});
    vec.push_back({C, z});
    sort(vec.begin(), vec.end());

    ll ans = LINF;
    // x \in [vec[0].fi, vec[1].fi]
    if(vec[1].se + vec[2].se <= vec[0].se){
        ll x = vec[0].fi;
        ans = min(ans, vec[1].se*(vec[1].fi - x) + vec[2].se*(vec[2].fi - x));
    }else{
        ll x = vec[1].fi;
        ans = min(ans, vec[0].se*(x - vec[0].fi) + vec[2].se*(vec[2].fi - x));
    }

    // x \in [vec[1].fi, vec[2].fi]
    if(vec[0].se + vec[1].se <= vec[2].se){
        ll x = vec[2].fi;
        ans = min(ans, vec[0].se*(x - vec[0].fi) + vec[1].se*(x - vec[1].fi));
    }else{
        ll x = vec[1].fi;
        ans = min(ans, vec[0].se*(x - vec[0].fi) + vec[2].se*(vec[2].fi - x));
    }

    cout << ans << "\n";
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int T=1;
    cin >> T;
    while(T--) solve();
}
0