QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370943 | #6406. Stage Clear | Harry27182 | WA | 3036ms | 134572kb | C++14 | 1.9kb | 2024-03-29 19:58:20 | 2024-03-29 19:58:21 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int a[105],b[105],n,m;
void cmin(int &x,int y){x=(x<y?x:y);}
const int inf=0x3f3f3f3f3f3f3f3f;
namespace Sub1
{
int dp[1<<26],e[20],u,v;
void main()
{
for(int i=1;i<=m;i++)
{
cin>>u>>v;u--;v--;
e[u]|=(1<<v);e[v]|=(1<<u);
}
for(int s=0;s<(1<<n);s++)dp[s]=inf;
dp[1]=a[1];
for(int s=1;s<(1<<n);s++)
{
int t=0;
for(int i=0;i<n;i++)if(s&(1<<i))t|=e[i];
int now=dp[s];
for(int i=0;i<n;i++)if(s&(1<<i))now-=a[i+1],now+=b[i+1];
for(int i=0;i<n;i++)
{
if(s&(1<<i))continue;
if(!(t&(1<<i)))continue;
cmin(dp[s|(1<<i)],dp[s]+max(0ll,a[i+1]-now));
}
}
cout<<dp[(1<<n)-1];
}
}
namespace Sub2
{
struct node{int u,c,w;}val[105];
int ans=inf,vis[105],fa[105],u,v;vector<int>g[105];
bool operator <(node x,node y)
{
if(max(x.c,y.c-x.w)!=max(y.c,x.c-y.w))return max(x.c,y.c-x.w)<max(y.c,x.c-y.w);
return x.u<y.u;
}
node operator +(node x,node y)
{
return node{x.u,max(x.c,y.c-x.w),x.w+y.w};
}
void solve()
{
for(int i=1;i<=n;i++)vis[i]=0;
set<node>s;vis[0]=1;
//max(c[u],c[v]-w[u])<max(c[v],c[u]-w[v])
for(int i=1;i<=n;i++)s.insert(val[i]=node{i,a[i],b[i]-a[i]});
node res={0,0,0};
while(s.size())
{
node now=*s.begin();s.erase(s.find(now));
if(vis[fa[now.u]])res=res+now;
else
{
s.erase(s.find(val[fa[now.u]]));
val[fa[now.u]]=val[fa[now.u]]+now;
s.insert(val[fa[now.u]]);
}
vis[now.u]=1;
}
ans=min(ans,res.c);
}
void search(int x)
{
if(x==n+1){solve();return;}
for(int i=0;i<g[x].size();i++)
{
fa[x]=g[x][i];
search(x+1);
}
}
void main()
{
for(int i=1;i<=m;i++)
{
cin>>u>>v;
g[v].emplace_back(u);
}
search(2);
cout<<ans;
}
}
signed main()
{
cin.tie(0)->sync_with_stdio(0);
cin>>n>>m;
for(int i=2;i<=n;i++)cin>>a[i]>>b[i];
if(n<=25)Sub1::main();
else Sub2::main();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3796kb
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: 5ms
memory: 4024kb
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: 46ms
memory: 5708kb
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: 184ms
memory: 11764kb
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: 3036ms
memory: 134572kb
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: -100
Wrong Answer
time: 0ms
memory: 3852kb
input:
36 35 389328367777319 678636570542258 32216944647452 612585362150577 891592845704885 596030605892036 688825276167602 461516360471825 916552899998310 106733202183953 400050408958777 670724326933521 995792861502757 894514508573875 14511185222713 612305257166443 175168368096281 508263855969282 85578802...
output:
162564391924159
result:
wrong answer 1st numbers differ - expected: '171942144116875', found: '162564391924159'