結果

問題 No.1997 X Lighting
ユーザー otoshigootoshigo
提出日時 2023-02-20 19:57:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 1,455 bytes
コンパイル時間 982 ms
コンパイル使用メモリ 94,336 KB
実行使用メモリ 15,724 KB
最終ジャッジ日時 2023-09-28 16:07:35
合計ジャッジ時間 7,469 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 18 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 31 ms
4,648 KB
testcase_14 AC 127 ms
15,568 KB
testcase_15 AC 38 ms
6,492 KB
testcase_16 AC 56 ms
7,716 KB
testcase_17 AC 160 ms
13,312 KB
testcase_18 AC 76 ms
8,952 KB
testcase_19 AC 195 ms
14,844 KB
testcase_20 AC 216 ms
15,700 KB
testcase_21 AC 219 ms
15,724 KB
testcase_22 AC 197 ms
14,836 KB
testcase_23 AC 94 ms
9,528 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 213 ms
15,012 KB
testcase_26 AC 176 ms
13,364 KB
testcase_27 AC 173 ms
13,556 KB
testcase_28 AC 44 ms
6,756 KB
testcase_29 AC 43 ms
6,676 KB
testcase_30 AC 196 ms
14,776 KB
testcase_31 AC 122 ms
10,976 KB
testcase_32 AC 27 ms
5,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<set>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

ll f(ll N,ll x,ll y){
    return max(0LL,min(N-x,N-y)-max(1-x,1-y)+1);
}

ll g(ll N,ll x,ll y){
    return max(0LL,min(N-x,y-1)-max(1-x,y-N)+1);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N;
    int M;
    cin>>N>>M;
    vector<ll>X(M),Y(M);
    ll ans=0;
    set<ll>sf,sg;
    vector<vector<ll>>vf(2),vg(2);
    rep(i,M){
        cin>>X[i]>>Y[i];
        ll z=X[i]+Y[i];
        if(!sf.count(X[i]-Y[i])){
            sf.insert(X[i]-Y[i]);
            vf[z%2].push_back(X[i]-Y[i]);
            ans+=f(N,X[i],Y[i]);
        }
        if(!sg.count(X[i]+Y[i])){
            sg.insert(X[i]+Y[i]);
            vg[z%2].push_back(X[i]+Y[i]);
            ans+=g(N,X[i],Y[i]);
        }
    }
    rep(t,2){
        sort(all(vf[t]));
        sort(all(vg[t]));
        int l=vf[t].size();
        rep(i,l){
            ll l=2+abs(vf[t][i]),r=2*N-abs(vf[t][i]);
            ans-=lower_bound(all(vg[t]),r+1)-lower_bound(all(vg[t]),l);
        }
    }
    cout<<ans<<"\n";
}
0