結果

問題 No.1034 テスターのふっぴーさん
ユーザー Re_code_ARe_code_A
提出日時 2021-04-18 12:40:19
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,511 bytes
コンパイル時間 1,443 ms
コンパイル使用メモリ 166,208 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-04 04:26:25
合計ジャッジ時間 2,518 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#include <atcoder/all>
//using namespace atcoder;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

template<typename T>
ostream& operator<<(ostream& os,const vector<T>& v){
    if(v.empty()){
        os<<"{ }";
        return os;
    }
    os<<"{"<<v.front();
    for(auto itr=++v.begin();itr!=v.end();itr++){
        os<<", "<<*itr;
    }
    os<<"}";
    return os;
}

template<typename T_first,typename T_second>
ostream& operator<<(ostream& os,const pair<T_first,T_second>& P){
    os<<"("<<P.first;
    os<<", "<<P.second;
    os<<")";
    return os;
}

ll solve(ll n,ll i,ll j){
    bool u=false,d=false,l=false,r=false;
    ll mn=min(min(i,n-1-i),min(j,n-1-j));
    if(i==mn) u=true;
    if(n-1-i==mn) d=true;
    if(j==mn) l=true;
    if(n-1-j==mn) r=true;

    ll ans=n*n-(n-2*mn)*(n-2*mn);
    if(u){
        ans+=j-mn;
        return ans;
    }
    if(d){
        ans+=(n-2*mn-1)*2+(n-1-mn-j);
        return ans;
    }
    if(l){
        ans+=(n-2*mn-1)*3+(n-1-mn-i);
        return ans;
    }
    if(r){
        ans+=(n-2*mn-1)+i-mn;
        return ans;
    }
    return ans;
}

int main(){
    ll q; cin>>q;
    rep(i,q){
        ll n,I,J; cin>>n>>I>>J;
        cout<<solve(n,I,J)<<"\n";
    }
}
0