結果

問題 No.1997 X Lighting
ユーザー ruthenruthen
提出日時 2022-07-01 22:50:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 1,651 bytes
コンパイル時間 2,322 ms
コンパイル使用メモリ 208,812 KB
実行使用メモリ 7,284 KB
最終ジャッジ日時 2024-05-04 17:14:19
合計ジャッジ時間 4,265 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 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 17 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 29 ms
6,528 KB
testcase_14 AC 40 ms
7,284 KB
testcase_15 AC 15 ms
5,376 KB
testcase_16 AC 19 ms
5,376 KB
testcase_17 AC 42 ms
6,608 KB
testcase_18 AC 25 ms
5,376 KB
testcase_19 AC 49 ms
7,060 KB
testcase_20 AC 55 ms
7,196 KB
testcase_21 AC 55 ms
7,200 KB
testcase_22 AC 50 ms
7,068 KB
testcase_23 AC 29 ms
5,632 KB
testcase_24 AC 3 ms
5,376 KB
testcase_25 AC 53 ms
7,112 KB
testcase_26 AC 46 ms
6,468 KB
testcase_27 AC 46 ms
6,556 KB
testcase_28 AC 17 ms
5,376 KB
testcase_29 AC 16 ms
5,376 KB
testcase_30 AC 52 ms
7,136 KB
testcase_31 AC 35 ms
6,144 KB
testcase_32 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#ifdef _RUTHEN
#include "debug.hpp"
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N, M;
    cin >> N >> M;
    show(N, M);
    V<ll> x(M), y(M);
    rep(i, M) {
        cin >> x[i] >> y[i];
        x[i]--, y[i]--;
    }
    show(x, y);
    V<ll> z(M);
    rep(i, M) z[i] = x[i] + y[i];
    sort(z.begin(), z.end());
    z.erase(unique(z.begin(), z.end()), z.end());
    show(z);
    ll ans = 0;
    V<ll> ze, zo;
    for (auto zi : z) {
        // x+y=kの分
        if (zi < N) {
            ans += zi + 1;
        } else {
            ans += 2 * N - 1 - zi;
        }
        if (zi % 2 == 1) {
            zo.push_back(zi);
        } else {
            ze.push_back(zi);
        }
    }
    show(ans);
    V<ll> w(M);
    rep(i, M) w[i] = y[i] - x[i];
    sort(w.begin(), w.end());
    w.erase(unique(w.begin(), w.end()), w.end());
    for (auto wi : w) {
        wi = abs(wi);
        ans += N - wi;
        if (wi % 2 == 1) {
            // zo
            int ind1 = lower_bound(zo.begin(), zo.end(), wi) - zo.begin();
            int ind2 = upper_bound(zo.begin(), zo.end(), 2 * (N - 1) - wi) - zo.begin();
            ans -= ind2 - ind1;
        } else {
            // ze
            int ind1 = lower_bound(ze.begin(), ze.end(), wi) - ze.begin();
            int ind2 = upper_bound(ze.begin(), ze.end(), 2 * (N - 1) - wi) - ze.begin();
            ans -= ind2 - ind1;
        }
    }
    cout << ans << '\n';
    return 0;
}
0