QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#154155 | #6406. Stage Clear | 275307894a | WA | 1ms | 3888kb | C++14 | 2.1kb | 2023-08-31 14:13:55 | 2023-08-31 14:13:57 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=36+5,M=N*40+5,K=(1<<25)+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,m;ll A[N],B[N];
namespace Solve1{
ll dp[K],S[K];int k,x,y,E[K],P[N];
void Solve(){
int i,j;k=(1<<n-1);
while(m--) scanf("%d%d",&x,&y),P[x-1]|=1<<y-1;
E[0]=P[0];for(i=0;i<n-1;i++) E[1<<i]=P[i+1];
for(i=1;i<k;i++) E[i]=E[i^(i&-i)]|E[i&-i];
for(i=0;i<n-1;i++) S[1<<i]=B[i+1]-A[i+1];
for(i=1;i<k;i++) S[i]=S[i^(i&-i)]+S[i&-i];
Me(dp,0x3f);dp[0]=0;for(i=0;i<k;i++){
for(j=1;j<n;j++) if(!(i>>(j-1)&1)&&E[i]>>j&1) dp[i|(1<<j-1)]=min(dp[i|(1<<j-1)],dp[i]+max(0ll,A[j]-(dp[i]+S[i])));
}
printf("%lld\n",dp[k-1]);exit(0);
}
}
vector<int> S[N];int To[N];ll ans=INF;
struct Node{
ll x,y;
Node operator +(const Node &B)const{return (Node){x+max(B.x-(x+y),0ll),y+B.y};}
bool operator <(const Node &B)const{
if((y>0)^(B.y>0)) return (y>0)>(B.y>0);
if(y>0) return x<B.x;
return x+y>B.x+B.y;
}
}w[N];
int fa[N];
int GF(int x){return fa[x]^x?fa[x]=GF(fa[x]):x;}
void calc(){
int i,j;
for(i=1;i<=n;i++) w[i]=(Node){A[i],B[i]-A[i]};
iota(fa+1,fa+n+1,1);
for(i=2;i<=n;i++){
int p=0;
for(j=2;j<=n;j++) if(fa[j]==j&&(!p||w[j]<w[p])) p=j;
w[GF(To[p])]=w[GF(To[p])]+w[p];fa[p]=GF(To[p]);
}
ans=min(ans,w[1].x);
}
void dfs(int x){
if(x==n+1) return calc();
for(int i:S[x]) To[x]=i,dfs(x+1);
}
void Solve(){
int i,j;scanf("%d%d",&n,&m);
for(i=1;i<n;i++) scanf("%lld%lld",&A[i],&B[i]);
// if(n<=26) Solve1::Solve();
while(m--){int x,y;scanf("%d%d",&x,&y);S[y].emplace_back(x);}
dfs(2);printf("%lld\n",ans);
}
int main(){
int t;
// scanf("%d",&t);
t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3888kb
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: 1ms
memory: 3772kb
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: 1ms
memory: 3736kb
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: 1ms
memory: 3732kb
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: 1ms
memory: 3828kb
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: 1ms
memory: 3736kb
input:
36 35 389328367777319 678636570542258 32216944647452 612585362150577 891592845704885 596030605892036 688825276167602 461516360471825 916552899998310 106733202183953 400050408958777 670724326933521 995792861502757 894514508573875 14511185222713 612305257166443 175168368096281 508263855969282 85578802...
output:
389328367777319
result:
wrong answer 1st numbers differ - expected: '171942144116875', found: '389328367777319'