結果

問題 No.1997 X Lighting
ユーザー MasKoaTSMasKoaTS
提出日時 2022-04-23 15:55:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 264 ms / 2,000 ms
コード長 1,133 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 98,956 KB
実行使用メモリ 14,392 KB
最終ジャッジ日時 2023-09-07 08:40:29
合計ジャッジ時間 6,332 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 5 ms
4,376 KB
testcase_06 AC 29 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 3 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 50 ms
4,500 KB
testcase_14 AC 167 ms
14,336 KB
testcase_15 AC 39 ms
6,236 KB
testcase_16 AC 60 ms
7,292 KB
testcase_17 AC 166 ms
12,288 KB
testcase_18 AC 79 ms
8,496 KB
testcase_19 AC 204 ms
13,760 KB
testcase_20 AC 257 ms
14,196 KB
testcase_21 AC 264 ms
14,392 KB
testcase_22 AC 209 ms
13,820 KB
testcase_23 AC 111 ms
8,932 KB
testcase_24 AC 5 ms
4,376 KB
testcase_25 AC 257 ms
13,960 KB
testcase_26 AC 199 ms
12,348 KB
testcase_27 AC 201 ms
12,560 KB
testcase_28 AC 51 ms
6,592 KB
testcase_29 AC 48 ms
6,448 KB
testcase_30 AC 225 ms
13,804 KB
testcase_31 AC 143 ms
10,172 KB
testcase_32 AC 31 ms
5,308 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <queue>
#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()
using namespace std;
using ll = long long;
template <class T>
using V = vector<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));
	}

	ll ans = 0;
	V<deque<ll> > que(2, deque<ll>({}));
	itrep(itr, xst) {
		ll x = *itr;
		ans += min(x, n - 1) - max(-n + 1 + x, 0ll) + 1;
		que[x & 1].push_back(x);
	}

	V<ll> yv = {};
	itrep(itr, yst) {
		yv.push_back(abs(*itr));
	}
	sort(all(yv));
	for (auto y : yv) {
		ll lv = y, rv = 2 * (n - 1) - y;
		int b = abs(y) & 1;
		ans += min(n - 1 + y, n - 1) - max(y, 0ll) + 1;
		while (que[b].empty() == false and que[b].back() > rv) {
			que[b].pop_back();
		}
		while (que[b].empty() == false and que[b].front() < lv) {
			que[b].pop_front();
		}
		ans -= que[b].size();
	}

	cout << ans << endl;

	return 0;
}
0