結果

問題 No.2213 Neq Move
ユーザー Jeroen Op de BeekJeroen Op de Beek
提出日時 2023-02-10 22:36:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 5 ms / 2,000 ms
コード長 1,149 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 197,472 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-21 23:47:03
合計ジャッジ時間 2,678 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 4 ms
4,376 KB
testcase_02 AC 5 ms
4,376 KB
testcase_03 AC 5 ms
4,376 KB
testcase_04 AC 5 ms
4,380 KB
testcase_05 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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