結果

問題 No.1997 X Lighting
ユーザー milanis48663220milanis48663220
提出日時 2022-07-01 22:30:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 2,491 bytes
コンパイル時間 1,390 ms
コンパイル使用メモリ 129,256 KB
実行使用メモリ 15,144 KB
最終ジャッジ日時 2024-05-04 16:48:33
合計ジャッジ時間 4,343 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 15 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 26 ms
5,376 KB
testcase_14 AC 99 ms
15,008 KB
testcase_15 AC 26 ms
6,272 KB
testcase_16 AC 36 ms
7,552 KB
testcase_17 AC 98 ms
12,708 KB
testcase_18 AC 47 ms
8,576 KB
testcase_19 AC 143 ms
14,420 KB
testcase_20 AC 169 ms
15,136 KB
testcase_21 AC 132 ms
15,144 KB
testcase_22 AC 123 ms
14,352 KB
testcase_23 AC 55 ms
9,344 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 120 ms
14,496 KB
testcase_26 AC 106 ms
12,844 KB
testcase_27 AC 128 ms
13,124 KB
testcase_28 AC 29 ms
6,656 KB
testcase_29 AC 28 ms
6,528 KB
testcase_30 AC 134 ms
14,268 KB
testcase_31 AC 99 ms
10,752 KB
testcase_32 AC 18 ms
5,376 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