結果

問題 No.1997 X Lighting
ユーザー 👑 Nachia
提出日時 2022-07-01 21:52:13
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,476 bytes
コンパイル時間 3,428 ms
コンパイル使用メモリ 119,304 KB
最終ジャッジ日時 2025-01-30 02:44:37
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <atcoder/modint>

using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(int)(n); i++)


const i64 INF = 1001001001001001001;
using modint = atcoder::static_modint<998244353>;


i64 solveEdge(i64 N, vector<i64>& X, vector<i64>& Y){
	sort(Y.begin(), Y.end());
	i64 ans = 0;
	for(auto x : X){
		auto itr = lower_bound(Y.begin(), Y.end(), N-1-x);
		ans += (i64)(itr - Y.begin());
	}
	return ans;
}


int main(){
	i64 N; cin >> N;
	int M; cin >> M;
	vector<i64> X[2];
	vector<i64> Y[2];
	rep(i,M){
		i64 x; cin >> x; x--;
		i64 y; cin >> y; y--;
		X[(x+y+N)%2].push_back(x + y);
		Y[(x+y+N)%2].push_back(N - 1 + x - y);
	}

	rep(t,2){ sort(X[t].begin(), X[t].end()); X[t].erase(unique(X[t].begin(), X[t].end()), X[t].end()); }
	rep(t,2){ sort(Y[t].begin(), Y[t].end()); Y[t].erase(unique(Y[t].begin(), Y[t].end()), Y[t].end()); }


	i64 ans = 0;
	rep(t,2){
		for(i64 x : X[t]) ans += N - abs(N-1-x);
		for(i64 x : Y[t]) ans += N - abs(N-1-x);
		ans -= (i64)X[t].size() * Y[t].size();
	}

	rep(t,2){
		rep(s,4){
			ans += solveEdge(N, X[t], Y[t]);
			swap(X[t], Y[t]);
			for(auto& x : X[t]) x = 2*N-2-x;
		}
	}

	cout << ans << '\n';
    return 0;
}


struct ios_do_not_sync{
    ios_do_not_sync(){
        std::ios::sync_with_stdio(false);
        std::cin.tie(nullptr);
    }
} ios_do_not_sync_instance;


0