QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#154174 | #6406. Stage Clear | qzez | WA | 660ms | 268632kb | C++14 | 3.1kb | 2023-08-31 14:28:40 | 2023-08-31 14:28:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
template<typename T>
ostream& operator << (ostream &out,const vector<T>&x){
if(x.empty())return out<<"[]";
out<<'['<<x[0];
for(int len=x.size(),i=1;i<len;i++)out<<','<<x[i];
return out<<']';
}
template<typename T>
vector<T> ary(const T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
template<typename T>
void debug(T x){
cerr<<x<<'\n';
}
template<typename T,typename ...S>
void debug(T x,S ...y){
cerr<<x<<' ',debug(y...);
}
int n,m;
namespace Solve1{
const int N=26,M=1<<N;
const ll INF=1e18;
ll f[M],sum[M],a[N],b[N];
int U,to[N];
void solve(){
U=(1<<n)-1;
for(int i=1;i<n;i++)cin>>a[i]>>b[i];
for(int u,v;m--;){
cin>>u>>v,u--,v--;
to[u]|=1<<v,to[v]|=1<<u;
}
fill(f,f+1+U,INF);
f[1]=0;
for(int S=1;S<U;S++){
int i=__builtin_ctz(S);
sum[S]=sum[S^(1<<i)]-a[i]+b[i];
}
for(int S=1;S<U;S+=2){
int i=__builtin_ctz(S);
sum[S]=sum[S^(1<<i)]-a[i]+b[i];
for(int v=0;v<n;v++)if(~S>>v&1){
if(S&to[v]){
int T=S|(1<<v);
f[T]=min(f[T],max(f[S],a[v]-sum[S]));
}
}
}
cout<<f[U]<<endl;
}
}
namespace Solve2{
const int N=72,M=72;
const ll INF=1e18;
struct edges{
int u,v;
}e[M];
struct zj{
ll a,b;
zj operator + (const zj &x)const{
if(x.a>b)return {a+x.a-b,x.b};
return {a,b+x.b-x.a};
}
bool operator < (const zj &x)const{
int t1=a<=b,t2=x.a<=x.b;
if(t1^t2)return t1;
if(t1)return a<x.a;
return b>x.b;
}
}a[N];
struct tree{
zj x;
int ls,rs,dis;
}t[N];
void merge(int &x,int y){
if(!x||!y){
x|=y;return;
}
if(t[y].x<t[x].x)swap(x,y);
merge(t[x].rs,y);
if(t[t[x].ls].dis<t[t[x].rs].dis)swap(t[x].ls,t[x].rs);
t[x].dis=t[t[x].rs].dis+1;
}
void pop(int &x){
int r1=t[x].ls,r2=t[x].rs;
merge(x=r1,r2);
}
int root[N];
vector<int>to[N];
void dfs(int u,int fa=0){
for(int v:to[u])if(v^fa){
dfs(v,u);
merge(root[u],root[v]);
}
if(u==1)return;
for(;root[u]&&t[root[u]].x<a[u];pop(root[u])){
a[u]=a[u]+t[root[u]].x;
}
t[u]={a[u],0,0,1},merge(root[u],u);
}
ll calc(){
for(int i=1;i<=n;i++){
root[i]=0;
}
dfs(1);
zj ans={0,0};
for(;root[1];pop(root[1]))ans=ans+t[root[1]].x;
return ans.a;
}
int fa[N],siz[N];
int find(int x){
return fa[x]==x?x:find(fa[x]);
}
ll ans;
bool Dfs(int i,int cnt=n){
if(cnt==1)return ans=min(ans,calc()),1;
if(i>m)return 0;
int u=e[i].u,v=e[i].v;
int x=find(u),y=find(v);
if(x^y){
to[u].push_back(v),to[v].push_back(u);
if(siz[x]>siz[y])swap(x,y);
siz[y]+=siz[x],fa[x]=y;
bool flag=Dfs(i+1,cnt-1);
siz[y]-=siz[x],fa[x]=x;
to[u].pop_back(),to[v].pop_back();
if(flag)flag|=Dfs(i+1,cnt);
return flag;
}
return Dfs(i+1,cnt);
}
void solve(){
for(int i=2;i<=n;i++){
cin>>a[i].a>>a[i].b;
}
for(int i=1;i<=m;i++){
cin>>e[i].u>>e[i].v;
}
ans=INF;
iota(fa,fa+1+n,0),fill(siz+1,siz+1+n,1);
Dfs(1);
cout<<ans<<endl;
}
}
int main(){
cin>>n>>m;
if(n<=26)Solve1::solve();
else Solve2::solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5448kb
input:
4 4 4 2 5 3 2 6 1 2 1 3 2 4 3 4
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 2ms
memory: 5704kb
input:
15 14 254040392438309 117083115436273 500005748229691 557255157630172 821034233718230 865199673774998 659892147898798 987564141425694 81172575487567 811635577877255 751768357864605 341103322647288 454926350150218 140191090713900 921608121471585 659295670987251 223751724062143 505619245326640 8907765...
output:
1665396301509143
result:
ok 1 number(s): "1665396301509143"
Test #3:
score: 0
Accepted
time: 12ms
memory: 11556kb
input:
18 17 636830992776530 847574431876821 330869946457865 78274534165482 450581372553540 11565219334965 8736347226844 17186323694285 870805093198860 559070167736042 674369178493171 930151818400874 641605209598997 222521062460239 450936030349531 469197172169023 831295459816974 626096008793091 53095460351...
output:
2375957544280218
result:
ok 1 number(s): "2375957544280218"
Test #4:
score: 0
Accepted
time: 40ms
memory: 23804kb
input:
20 19 539893468691183 767805205447882 240338186903141 960937349402327 942645580569365 896509929612645 542601575005817 191461109090531 540992546866047 765080044816119 904535155855114 858111921213175 452499200048240 115895143306864 983856946412026 838504718536099 586421298181479 265212699386882 677124...
output:
800919806038419
result:
ok 1 number(s): "800919806038419"
Test #5:
score: 0
Accepted
time: 660ms
memory: 268632kb
input:
24 23 114281007218527 308690671179962 145951034437731 718976086594208 709172151907814 926071954787084 224496444610281 498657753059525 874422017133378 857676356343078 532175866197017 818525693672607 303837639402605 374469705563954 512244364294540 952911486867703 748959419417502 249992707230361 512696...
output:
114281007218527
result:
ok 1 number(s): "114281007218527"
Test #6:
score: 0
Accepted
time: 1ms
memory: 3380kb
input:
36 35 389328367777319 678636570542258 32216944647452 612585362150577 891592845704885 596030605892036 688825276167602 461516360471825 916552899998310 106733202183953 400050408958777 670724326933521 995792861502757 894514508573875 14511185222713 612305257166443 175168368096281 508263855969282 85578802...
output:
171942144116875
result:
ok 1 number(s): "171942144116875"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3448kb
input:
36 35 759037289890767 849577210686635 16379509883489 441829377955433 589378488455351 990818352083122 871208015900506 727359003875494 207852561142533 28766987248469 81321183353129 892618157632070 198487099788393 519364502513651 83942803274015 988821788304459 868185445880277 269956013388079 3834515054...
output:
759037289890767
result:
ok 1 number(s): "759037289890767"
Test #8:
score: 0
Accepted
time: 1ms
memory: 3444kb
input:
36 35 100792831728257 823656493168793 866936535786311 187861146327778 132998929717538 605906559206892 3319598846477 393401056223733 964444786730964 932398059281618 925176496607384 148825907337833 985037559482190 646827297289525 469876125353024 641923164294854 453796287874442 291205025001534 72806942...
output:
1397699717661157
result:
ok 1 number(s): "1397699717661157"
Test #9:
score: -100
Wrong Answer
time: 1ms
memory: 3408kb
input:
36 36 245996406159980 462974248377488 839352152971124 40282565369163 572695144110271 507726167903341 671102350267895 18090181781241 643724978558334 551787913319524 936340565446887 517649577919257 158127116487034 175750969611510 396852573858996 670814068366285 534702788102341 124550558279140 69441153...
output:
245996406159980
result:
wrong answer 1st numbers differ - expected: '2508008255775889', found: '245996406159980'