結果

問題 No.1997 X Lighting
ユーザー umimelumimel
提出日時 2022-07-02 12:05:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 1,977 bytes
コンパイル時間 1,626 ms
コンパイル使用メモリ 173,952 KB
実行使用メモリ 7,304 KB
最終ジャッジ日時 2023-08-18 03:04:51
合計ジャッジ時間 4,969 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 29 ms
4,824 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 51 ms
6,244 KB
testcase_14 AC 110 ms
7,088 KB
testcase_15 AC 26 ms
4,380 KB
testcase_16 AC 33 ms
4,708 KB
testcase_17 AC 75 ms
6,992 KB
testcase_18 AC 43 ms
5,244 KB
testcase_19 AC 90 ms
7,132 KB
testcase_20 AC 121 ms
7,148 KB
testcase_21 AC 121 ms
7,284 KB
testcase_22 AC 90 ms
7,304 KB
testcase_23 AC 63 ms
5,440 KB
testcase_24 AC 4 ms
4,376 KB
testcase_25 AC 117 ms
7,272 KB
testcase_26 AC 98 ms
6,532 KB
testcase_27 AC 100 ms
6,728 KB
testcase_28 AC 36 ms
4,632 KB
testcase_29 AC 33 ms
4,380 KB
testcase_30 AC 114 ms
7,184 KB
testcase_31 AC 78 ms
5,696 KB
testcase_32 AC 23 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i)
#define rep(i, n) drep(i, 0, n - 1)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define fi first
#define se second

const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll INF = 1LL << 60;
const ll N_MAX = 2e5;

int main(){
    ll n, m;
    cin >> n >> m;

    vector<ll> x(m), y(m);
    rep(i, m){
        cin >> x[i] >> y[i];
        x[i]--;
        y[i]--;
    }

    vector<ll> rx(m), ry(m);
    rep(i, m){
        rx[i] = x[i] + y[i];
        ry[i] = x[i] - y[i];
    }
    sort(all(rx));
    sort(all(ry));
    rx.erase(unique(all(rx)), rx.end());
    ry.erase(unique(all(ry)), ry.end());

    ll ans = 0;
    rep(i, (ll)rx.size()){
        if(rx[i] <= n-1){
            ans += (rx[i]+1);
        }else{
            ans += 2*n - rx[i] - 1;
        }
    }

    vector<ll> odd, even;
    rep(i, (ll)rx.size()){
        if(rx[i]%2 == 0) even.pb(rx[i]);
        else odd.pb(rx[i]);
    }

    rep(i, (ll)ry.size()){
        if(ry[i]%2 == 0){
            ans += n - abs(ry[i]);
            auto itr1 = lower_bound(all(even), abs(ry[i]));
            ll cnt1 = 0;
            if(itr1 != even.begin()){
                itr1--;
                cnt1 = itr1 - even.begin() + 1;
            }

            auto itr2 = upper_bound(all(even), 2*n-2-abs(ry[i]));
            ll cnt2 = even.end() - itr2;
            ans -= (ll)even.size() - (cnt1 + cnt2);
        }else{
            ans += n - abs(ry[i]);
            auto itr1 = lower_bound(all(odd), abs(ry[i]));
            ll cnt1 = 0;
            if(itr1 != odd.begin()){
                itr1--;
                cnt1 = itr1 - odd.begin() + 1;
            }

            auto itr2 = upper_bound(all(odd), 2*n-2-abs(ry[i]));
            ll cnt2 = odd.end() - itr2;
            ans -= (ll)odd.size() - (cnt1 + cnt2);
        }
    }

    cout << ans << endl;
}
0