結果
| 問題 |
No.2376 障害物競プロ
|
| コンテスト | |
| ユーザー |
momoyuu
|
| 提出日時 | 2023-07-08 15:34:56 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 4,465 bytes |
| コンパイル時間 | 2,050 ms |
| コンパイル使用メモリ | 153,292 KB |
| 実行使用メモリ | 6,016 KB |
| 最終ジャッジ日時 | 2024-07-22 10:59:17 |
| 合計ジャッジ時間 | 67,387 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 38 WA * 2 |
ソースコード
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<set>
#include<queue>
#include<cassert>
#include<cmath>
#include<iomanip>
using namespace std;
using ll = long long;
using dat = pair<ll,ll>;
template< typename T >
struct edge{
int from,to;
T cost;
edge(int from,int to, T cost):from(from),to(to),cost(cost){};
edge &operator=(const int& x){
to = x;
return *this;
}
};
template< typename T >
struct graph{
int n;
vector<vector<edge<T>>> e;
graph(int n):n(n),e(n){}
void add_edge(int from,int to,T cost){
e[from].emplace_back(from,to,cost);
}
vector<edge<T>> &operator[](int i) {
return e[i];
}
};
template< typename T >
vector<vector<T>> warshallfloyd(graph<T>& g,T const inf = (T)1e9){
int n = g.n;
vector<vector<T>> dist(n,vector<T>(n,inf));
for(int i = 0;i<n;i++){
dist[i][i] = 0;
}
for(int i = 0;i<n;i++){
for(edge<T> e:g[i]){
dist[i][e.to] = e.cost;
}
}
for(int k = 0;k<n;k++){
for(int i = 0;i<n;i++){
for(int j = 0;j<n;j++){
dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
}
}
}
return dist;
}
int ccw(dat a,dat b,dat c){
ll da = b.first - a.first;
ll db = b.second - a.second;
ll dc = c.first - a.first;
ll dd = c.second - a.second;
if(da*dd-db*dc>0) return 1;
if(da*dd-db*dc<0) return -1;
if(da*db+dc*dd<0) return 2;
if(da*da+db*db<dc*dc+dd*dd) return -2;
return 0;
}
bool isok(dat a,dat b,dat c,dat d){
if(ccw(a,b,c)*ccw(a,b,d)<=0&&ccw(c,d,a)*ccw(c,d,b)<=0) return 0;
else return 1;
}
int main(){
int n,m;
cin>>n>>m;
vector<vector<ll>> x(2,vector<ll>(n)),y(2,vector<ll>(n));
for(int i = 0;i<n;i++) for(int j = 0;j<2;j++) cin>>x[j][i]>>y[j][i];
vector<pair<ll,ll>> d;
for(int i = 0;i<n;i++){
for(int j = 0;j<2;j++){
d.push_back(make_pair(x[j][i],y[j][i]));
}
}
set<pair<dat,dat>> s;
sort(d.begin(),d.end());
for(int i = 0;i<n;i++){
dat now = {x[0][i],y[0][i]};
dat nxt = {x[1][i],y[1][i]};
s.insert(make_pair(now,nxt));
s.insert(make_pair(now,nxt));
}
int al = d.size();
graph<double> g(al);
for(int i = 0;i<al;i++){
for(int j = i + 1;j<al;j++){
dat a = d[i];
dat b = d[j];
if(s.count(make_pair(a,b))) continue;
if(s.count(make_pair(b,a))) continue;
bool ok = true;
for(int k = 0;k<n;k++){
dat c = {x[0][k],y[0][k]};
dat dd = {x[1][k],y[1][k]};
if(c==a||c==b||dd==a||dd==b) continue;
if(isok(a,b,c,dd)) continue;
ok = false;
// cout<<a.first<<" "<<a.second<<" "<<b.first<<" "<<b.second<<" "<<k<<endl;
break;
}
if(!ok) continue;
int ni = lower_bound(d.begin(),d.end(),a) - d.begin();
int nj = lower_bound(d.begin(),d.end(),b) - d.begin();
ll dx = a.first - b.first;
ll dy = a.second - b.second;
double now = sqrt(dx*dx+dy*dy);
g.add_edge(ni,nj,now);
g.add_edge(nj,ni,now);
}
}
for(int i = 0;i<n;i++){
dat a = {x[0][i],y[0][i]};
dat b = {x[1][i],y[1][i]};
bool ok = true;
for(int j = 0;j<n;j++){
if(i==j) continue;
dat c = {x[0][j],y[0][j]};
dat dd = {x[1][j],y[1][j]};
if(c==a||c==b||dd==a||dd==c) continue;
if(isok(a,b,c,dd)) continue;
ok = false;
break;
}
if(!ok) continue;
int ni = lower_bound(d.begin(),d.end(),a) - d.begin();
int nj = lower_bound(d.begin(),d.end(),b) - d.begin();
ll dx = a.first - b.first;
ll dy = a.second - b.second;
double now = sqrt(dx*dx+dy*dy);
g.add_edge(ni,nj,now);
g.add_edge(nj,ni,now);
}
auto di = warshallfloyd<double>(g);
cout<<fixed<<setprecision(15);
while(m--){
int i,j,k,l;
cin>>i>>j>>k>>l;
i--;j--;k--;l--;
dat a = {x[j][i],y[j][i]};
dat b = {x[l][k],y[l][k]};
int ni = lower_bound(d.begin(),d.end(),a) - d.begin();
int nj = lower_bound(d.begin(),d.end(),b) - d.begin();
cout<<di[ni][nj]<<endl;
}
}
momoyuu