QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#143103 | #6406. Stage Clear | Schi2oid | Compile Error | / | / | C++20 | 2.6kb | 2023-08-20 16:38:22 | 2023-08-20 16:38:38 |
Judging History
This is the latest submission verdict.
- [2024-08-15 21:05:17]
- hack成功,自动添加数据
- (/hack/778)
- [2023-08-20 16:38:38]
- Judged
- Verdict: Compile Error
- Time: 0ms
- Memory: 0kb
- [2023-08-20 16:38:22]
- Submitted
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int INF=1e18;
int n,m;
vector<int>edge[7000005];
vector<int>fedge[7000005];
int x[105],y[105];
int bx[105],by[105];
int cnt[105];
int dp[70000005];
int ret=INF;
int solve1(){
dp[1]=0;
for(int i=2;i<(1ll<<n);i++) dp[i]=INF;
int sum=0;
for(int i=1;i<(1ll<<n);i++){
for(int j=0;j<n;j++){
if(((i>>j)&1)&&(!(((i-1)>>j)&1))){
sum+=y[j+1]-x[j+1];
for(int k=0;k<edge[j+1].size();k++) cnt[edge[j+1][k]]++;
}
else if((((i-1)>>j)&1)&&(!((i>>j)&1))){
sum-=y[j+1]-x[j+1];
for(int k=0;k<edge[j+1].size();k++) cnt[edge[j+1][k]]--;
}
else break;
}
for(int j=1;j<=n;j++) if(cnt[j]&&(!((i>>(j-1))&1))) dp[i^(1<<(j-1))]=min(dp[i^(1<<(j-1))],dp[i]+max(0ll,x[j]-dp[i]-sum));
}
return dp[(1ll<<n)-1];
}
struct node{
int x,y,id;
bool operator < (const node& ano) const {
if(y>=0&&ano.y<0) return 1;
else if(y<0&&ano.y>=0) return 0;
else if(y>=0){
if(x!=ano.x) return x<ano.x;
else return id<ano.id;
}
else{
if(x+y!=ano.x+ano.y) return x+y>ano.x+ano.y;
else if(x!=ano.x) return x<ano.x;
else if(y!=ano.y) return y<ano.y;
else return id<ano.id;
}
}
};
int fa[105],f[105],nxt[105],ed[105];
int find(int x){
if(fa[x]==x) return x;
fa[x]=find(fa[x]);
return fa[x];
}
void merge(int a,int b){
x[a]=max(x[a],x[b]-y[a]);
y[a]+=y[b];
}
bool vis[200005];
int calc(){
memcpy(x,bx,sizeof x);
memcpy(y,by,sizeof y);
set<node>s;
for(int i=2;i<=n;i++) s.insert((node){x[i],y[i],i});
for(int i=1;i<=n;i++) fa[i]=i,ed[i]=i,nxt[i]=-1;]
while(s.size()){
int u=(*s.begin()).id;
s.erase(*s.begin());
int ffu=find(f[u]);
nxt[ed[ffu]]=u;
ed[ffu]=ed[u];
fa[u]=ffu;
if(ffu!=1){
s.erase((node){x[ffu],y[ffu],ffu});
merge(ffu,u);
s.insert((node){x[ffu],y[ffu],ffu});
}
}
int now=1,ans=0,cost=0;
for(int i=2;i<=n;i++) vis[i]=0;
for(int i=1;i<n;i++){
now=nxt[now];
vis[now]=1;
cost+=max(x[now]-ans,0ll);
ans+=max(x[now]-ans,0ll)+y[now];
}
return cost;
}
void dfs(int x){
if(x==n+1){
ret=min(ret,calc());
return;
}
for(int i=0;i<fedge[x].size();i++){
f[x]=fedge[x][i];
dfs(x+1);
}
}
int solve2(){
memcpy(bx,x,sizeof bx);
memcpy(by,y,sizeof by);
for(int i=1;i<=n;i++) y[i]-=x[i],x[i]=max(x[i],y[i]);
dfs(2);
return ret;
}
signed main(){
int u,v;
cin>>n>>m;
for(int i=2;i<=n;i++) scanf("%lld%lld",&x[i],&y[i]);
for(int i=1;i<=m;i++){
scanf("%lld%lld",&u,&v);
edge[u].push_back(v);
fedge[v].push_back(u);
}
if(n<=26) cout<<solve1()<<endl;
else cout<<solve2()<<endl;
return 0;
}
詳細信息
answer.code: In function ‘long long int calc()’: answer.code:66:57: error: expected primary-expression before ‘]’ token 66 | for(int i=1;i<=n;i++) fa[i]=i,ed[i]=i,nxt[i]=-1;] | ^ answer.code: In function ‘int main()’: answer.code:110:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 110 | for(int i=2;i<=n;i++) scanf("%lld%lld",&x[i],&y[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~ answer.code:112:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 112 | scanf("%lld%lld",&u,&v); | ~~~~~^~~~~~~~~~~~~~~~~~