結果
| 問題 | No.3842 マス目分割 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-12-01 10:16:12 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 80 ms / 2,000 ms |
| + 614µs | |
| コード長 | 1,603 bytes |
| 記録 | |
| コンパイル時間 | 5,239 ms |
| コンパイル使用メモリ | 384,480 KB |
| 実行使用メモリ | 18,956 KB |
| 最終ジャッジ日時 | 2026-12-01 10:16:24 |
| 合計ジャッジ時間 | 11,217 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 50 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
struct Interval {
int l, r, id;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<vector<int>> obs(n+1);
for(int i=0; i<n; i++){
int a,b;
cin >> a >> b;
obs[a].push_back(b);
}
dsu uf(2*n);
vector<Interval> prev,cur;
int cnt=0;
int components=0;
for(int i=1; i<=n; i++){
sort(obs[i].begin(),obs[i].end());
// 番兵
obs[i].push_back(n+1);
cur.clear();
// 空き区間の生成
int l=1;
for(int b:obs[i]){
if(l<b){
cur.push_back({l,b-1,cnt++});
components++;
}
l=b+1;
}
// 前の行との連結判定
int p=0,q=0;
while(p<(int)prev.size() &&
q<(int)cur.size()){
auto [l1,r1,id1]=prev[p];
auto [l2,r2,id2]=cur[q];
// 区間が重なっている場合
if(max(l1,l2)<=min(r1,r2)){
if(!uf.same(id1,id2)){
uf.merge(id1,id2);
components--;
}
}
// 右端が小さい方を進める
if(r1<r2){
p++;
}
else if(r1>r2){
q++;
}
else{
p++;
q++;
}
}
swap(prev,cur);
}
cout << (components==2 ? "Yes" : "No") << '\n';
}