結果
| 問題 |
No.1997 X Lighting
|
| コンテスト | |
| ユーザー |
SSRS
|
| 提出日時 | 2022-07-01 21:44:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 189 ms / 2,000 ms |
| コード長 | 1,546 bytes |
| コンパイル時間 | 1,574 ms |
| コンパイル使用メモリ | 181,540 KB |
| 実行使用メモリ | 15,452 KB |
| 最終ジャッジ日時 | 2024-11-26 04:30:39 |
| 合計ジャッジ時間 | 5,699 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 30 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
long long L, N;
cin >> L >> N;
vector<pair<long long, long long>> A, B;
for (int i = 0; i < N; i++){
long long y, x;
cin >> y >> x;
y--;
x--;
if ((x + y) % 2 == 0){
A.push_back(make_pair(y, x));
} else {
B.push_back(make_pair(y, x));
}
}
int Acnt = A.size();
set<long long> Ax, Ay;
for (int i = 0; i < Acnt; i++){
Ay.insert(A[i].first - A[i].second);
Ax.insert(A[i].first + A[i].second);
}
vector<long long> Ay2;
for (long long y : Ay){
Ay2.push_back(y);
}
long long Aans = 0;
for (long long x : Ax){
Aans += min(x + 1, L * 2 - x - 1);
}
for (long long y : Ay){
Aans += L - abs(y);
}
for (long long x : Ax){
long long ub = min(x, L * 2 - 2 - x);
long long lb = -ub;
Aans -= upper_bound(Ay2.begin(), Ay2.end(), ub) - lower_bound(Ay2.begin(), Ay2.end(), lb);
}
long long Bcnt = B.size();
set<long long> Bx, By;
for (int i = 0; i < Bcnt; i++){
By.insert(B[i].first - B[i].second);
Bx.insert(B[i].first + B[i].second);
}
vector<long long> By2;
for (long long y : By){
By2.push_back(y);
}
long long Bans = 0;
for (long long x : Bx){
Bans += min(x + 1, L * 2 - x - 1);
}
for (long long y : By){
Bans += L - abs(y);
}
for (long long x : Bx){
long long ub = min(x, L * 2 - 2 - x);
long long lb = -ub;
Bans -= upper_bound(By2.begin(), By2.end(), ub) - lower_bound(By2.begin(), By2.end(), lb);
}
cout << Aans + Bans << endl;
}
SSRS