QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473421 | #22. Power plants | Mathias | 0 | 3ms | 7736kb | C++20 | 2.0kb | 2024-07-12 03:24:50 | 2024-07-12 03:24:50 |
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define fi first
#define sc second
#define vi vector<int>
#define pii pair<int,int>
const ll INF = 1e18+7;
const int MAXN = 1e5+7;
pii t[MAXN]; bool vis[MAXN],k[MAXN],xd; pii p; int depth[MAXN],v1[MAXN],v2[MAXN];
vi g[MAXN]; int usu,n,rv1,rv2,rp;
struct str{int fi,sc,th;};
str pkt[MAXN];
bool comp(str a,str b){
if(a.fi==b.fi) return a.sc<b.sc;
else return a.fi<b.fi;
}
set<pii>s;
ll d(int x,int y){
ll w1=t[x].fi, w2=t[x].sc, w3=t[y].fi, w4=t[y].sc;
return (w1-w3)*(w1-w3)+(w2-w4)*(w2-w4);
}
bool DFS(int x,int f){
k[x]=1-k[f], vis[x]=1, depth[x]=depth[f]+1;
for(auto s1:g[x]) if(vis[s1]==1 and s1!=f and (depth[x]-depth[s1])%2==0 and k[s1]==k[x]) return 0;
for(auto s1:g[x]) if(vis[s1]==0) return DFS(s1,x);
return 1;
}
bool f(ll mid){
xd=1; usu=0; int x,y;
for(int i=0;i<rp;i++){
x=pkt[i].fi, y=pkt[i].sc;
while(pkt[usu].fi<x-mid) s.erase({pkt[usu].sc,pkt[usu].th}), usu++;
p={max((ll)0,y-mid),0};
auto it=s.lower_bound(p);
for(auto curr=it;curr!=s.end();curr++){
p=*curr;
if(p.fi>y+mid) break;
if(d(p.sc,pkt[i].th)<mid) g[pkt[i].th].pb(p.sc), g[p.sc].pb(pkt[i].th);
}
s.insert({y,pkt[i].th});
}
s.clear();
for(int i=1;i<=n;i++) if(vis[i]==0) xd=min(xd,DFS(i,0));
for(int i=0;i<rp;i++) g[pkt[i].th].clear(), vis[pkt[i].th]=0;
if(xd==1){
rv1=rv2=0;
for(int i=1;i<=n;i++) if(k[i]) v1[++rv1]=i; else v2[++rv2]=i;
}
return xd;
}
void solve(){
ll b=0,e=INF,mid,r=0;
cin>>n;
for(int i=1;i<=n;i++) cin>>t[i].fi>>t[i].sc, pkt[rp++]={t[i].fi,t[i].sc,i};
sort(pkt,pkt+rp,comp);
while(b<=e){
mid=(b+e)/2;
if(f(mid)) r=mid, b=mid+1; else e=mid-1;
}
cout<<r<<'\n'<<rv1<<'\n';
for(int i=1;i<=rv1;i++) cout<<v1[i]<<' '; cout<<'\n'<<rv2<<'\n';
for(int i=1;i<=rv2;i++) cout<<v2[i]<<' '; cout<<'\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int tt=1;
while(tt--) solve();
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 3ms
memory: 5840kb
input:
100 387 501 90 108 273 76 754 365 121 556 102 401 831 215 841 829 424 690 17 35 10 980 34 917 948 478 766 818 55 588 510 772 16 511 499 323 632 554 461 454 281 247 720 575 994 720 739 30 989 992 507 557 665 621 356 398 161 822 906 556 189 835 208 500 628 829 402 969 804 155 697 581 107 630 102 568 3...
output:
425 94 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 76 77 78 79 80 81 82 83 85 86 87 88 89 90 91 93 94 95 96 98 99 100 6 40 49 75 84 92 97
result:
ok
Test #2:
score: -10
Wrong Answer
time: 3ms
memory: 7736kb
input:
95 298 129 485 422 97 190 732 393 73 529 920 101 94 150 806 369 223 653 572 820 985 456 109 602 329 669 670 742 9 999 410 14 854 791 450 635 223 973 14 923 626 891 367 443 226 524 899 949 558 195 556 825 775 987 976 264 32 627 776 194 986 118 427 216 816 477 538 159 674 325 516 388 519 250 10 850 30...
output:
1193 83 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 41 42 45 47 48 49 52 53 54 55 56 57 58 59 60 61 62 63 64 66 67 68 69 70 71 73 74 75 76 77 78 79 80 81 82 83 85 86 87 89 91 92 93 94 95 12 26 40 43 44 46 50 51 65 72 84 88 90
result:
wrong answer
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%