結果

問題 No.2213 Neq Move
ユーザー Jeroen Op de Beek
提出日時 2023-02-10 22:36:36
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 1,710 ms
コンパイル使用メモリ 193,032 KB
最終ジャッジ日時 2025-02-10 13:04:32
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x),end(x)
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; }
#define debug(a) cerr << "(" << #a << ": " << a << ")\n";
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pi;
const int mxN = 1e5+1, oo = 1e9;
ll solve(ll a, ll b, ll c, ll d) {
    if(a>c) return 1+solve(0,b,c,d);
    if(b>d) return 1+solve(a,0,c,d);
    if(a==0 and b==0) return c+d;
    if((a<b)==(c<d)) return c-a+d-b;
    if(a==0 and b==1) return solve(b,a,d,c);
    if(a==1 and b==0) {
        return 1+solve(a+1,b,c,d);
    }
    return max(a,b)+c-a+d-b+1;
}
int main() {
    int t; cin >> t;
    while(t--) {
        ll a,b,c,d; cin >> a >> b >> c >> d;
        cout << solve(a,b,c,d) << '\n';
    }
}
0