結果
問題 | No.1997 X Lighting |
ユーザー |
![]() |
提出日時 | 2024-12-01 20:48:32 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 290 ms / 2,000 ms |
コード長 | 1,048 bytes |
コンパイル時間 | 3,006 ms |
コンパイル使用メモリ | 211,720 KB |
実行使用メモリ | 13,560 KB |
最終ジャッジ日時 | 2024-12-01 20:48:41 |
合計ジャッジ時間 | 7,053 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h>#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;int main(){ll n, m; cin >> n >> m;set<ll> xst = {}, yst = {};for(int i = 0; i < m; ++i){ll X, Y; cin >> X >> Y;xst.insert((X - 1) + (Y - 1));yst.insert((X - 1) - (Y - 1));}vector<vector<ll> > xvec(2, vector<ll>({}));itrep(itr, xst){ll x = *itr;xvec[x & 1].push_back(x);}ll ans = 0;itrep(itr, xst){ll x = *itr;ans += min(x, n - 1) - max(x - (n - 1), (ll)0) + 1;}itrep(itr, yst){ll y = *itr; int b = y & 1;ans += min(n - 1 + y, n - 1) - max(y, (ll)0) + 1;auto l = lb(xvec[b], abs(y));auto r = ub(xvec[b], 2 * (n - 1) - abs(y));ans -= r - l;}cout << ans << endl;return 0;}