結果

問題 No.1997 X Lighting
ユーザー milanis48663220milanis48663220
提出日時 2022-07-01 22:30:28
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 173 ms / 2,000 ms
コード長 2,491 bytes
コンパイル時間 1,320 ms
コンパイル使用メモリ 127,456 KB
実行使用メモリ 14,980 KB
最終ジャッジ日時 2023-08-17 09:58:47
合計ジャッジ時間 4,942 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 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,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 16 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 2 ms
4,376 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 27 ms
4,376 KB
testcase_14 AC 120 ms
14,980 KB
testcase_15 AC 30 ms
6,360 KB
testcase_16 AC 44 ms
7,580 KB
testcase_17 AC 129 ms
12,716 KB
testcase_18 AC 56 ms
8,632 KB
testcase_19 AC 161 ms
14,392 KB
testcase_20 AC 173 ms
14,968 KB
testcase_21 AC 172 ms
14,852 KB
testcase_22 AC 159 ms
14,308 KB
testcase_23 AC 66 ms
9,308 KB
testcase_24 AC 3 ms
4,376 KB
testcase_25 AC 165 ms
14,584 KB
testcase_26 AC 132 ms
12,804 KB
testcase_27 AC 138 ms
13,268 KB
testcase_28 AC 31 ms
6,632 KB
testcase_29 AC 31 ms
6,388 KB
testcase_30 AC 161 ms
14,304 KB
testcase_31 AC 93 ms
10,744 KB
testcase_32 AC 19 ms
5,344 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll n; int m; cin >> n >> m;
    vector<set<ll>> sums(2), diffs(2);
    for(int i = 0; i < m; i++){
        ll x, y; cin >> x >> y; x--; y--;
        int parity = (x%2) == (y%2) ? 0 : 1; 
        sums[parity].insert(x+y);
        diffs[parity].insert(x-y);
    }
    vector<vector<ll>> sum_v(2), diff_v(2);
    for(int i = 0; i < 2; i++){
        for(ll x: sums[i]) sum_v[i].push_back(x);
        for(ll x: diffs[i]) diff_v[i].push_back(x);
    }
    auto calc = [&](int parity){
        auto sums = sum_v[parity];
        auto diffs = diff_v[parity];
        ll ans = 0;
        for(ll sum: sums){
            if(sum <= n-1) ans += sum+1;
            else ans += (2*n-1)-sum;
        }
        for(ll diff: diffs){
            if(diff <= 0) ans += diff+n;
            else ans += n-diff;
        }
        for(ll sum: sums){
            ll l = max(-sum, sum-(2*n-2));
            ll r = min(sum, 2*n-2-sum);
            auto pl = lower_bound(diffs.begin(), diffs.end(), l);
            auto pr = upper_bound(diffs.begin(), diffs.end(), r);
            ans -= (pr-pl);
        }
        return ans;
    };
    ll ans = 0;
    for(int i = 0; i < 2; i++){
        ans += calc(i);
    }
    cout << ans << endl;
}
0