結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-04-16 13:36:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 185 ms / 2,000 ms
コード長 1,102 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 88,956 KB
実行使用メモリ 13,468 KB
最終ジャッジ日時 2023-08-26 17:49:57
合計ジャッジ時間 4,980 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 29 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 50 ms
4,376 KB
testcase_14 AC 163 ms
13,468 KB
testcase_15 AC 39 ms
6,048 KB
testcase_16 AC 52 ms
6,956 KB
testcase_17 AC 126 ms
11,648 KB
testcase_18 AC 68 ms
7,844 KB
testcase_19 AC 150 ms
13,024 KB
testcase_20 AC 185 ms
13,464 KB
testcase_21 AC 185 ms
13,384 KB
testcase_22 AC 152 ms
12,980 KB
testcase_23 AC 90 ms
8,560 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 177 ms
13,220 KB
testcase_26 AC 147 ms
11,896 KB
testcase_27 AC 150 ms
11,864 KB
testcase_28 AC 49 ms
6,188 KB
testcase_29 AC 46 ms
6,164 KB
testcase_30 AC 172 ms
13,084 KB
testcase_31 AC 111 ms
9,464 KB
testcase_32 AC 30 ms
5,112 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#define rep(i, l, n) for (int i = (l); i < (n); i++)
#define itrep(itr, st) for(auto itr = st.begin(); itr != st.end(); itr++)
#define all(x) x.begin(), x.end()
#define lb(A, x) (lower_bound(all(A), x) - A.begin())
#define ub(A, x) (upper_bound(all(A), x) - A.begin())
using namespace std;
using ll = long long;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T> >;


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

	set<ll> xst = {}, yst = {};
	rep(i, 0, m) {
		ll X, Y;	cin >> X >> Y;
		xst.insert((X - 1) + (Y - 1));
		yst.insert((X - 1) - (Y - 1));
	}

	VV<ll> xv(2, V<ll>({}));
	itrep(itr, xst) {
		ll x = *itr;
		xv[x & 1].push_back(x);
	}

	ll ans = 0;
	itrep(itr, xst) {
		ll x = *itr;
		ans += min(x, n - 1) - max(-n + 1 + x, (ll)0) + 1;
	}
	itrep(itr, yst) {
		ll y = *itr;	int b = abs(y) & 1;
		ans += min(n - 1 + y, n - 1) - max(y, (ll)0) + 1;
		auto l = lb(xv[b], max(y, -y));
		auto r = ub(xv[b], min(2 * (n - 1) - y, 2 * (n - 1) + y));
		ans -= r - l;
	}

	cout << ans << endl;

	return 0;
}
0