QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#879674 | #9692. Currency | nullptr_qwq | WA | 0ms | 22216kb | C++17 | 2.2kb | 2025-02-02 10:28:09 | 2025-02-02 10:28:10 |
Judging History
answer
// 私は猫です
#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define inf 1000000000
#define infll 1000000000000000000ll
#define pii pair<int,int>
#define rep(i,a,b,c) for(int i=(a);i<=(b);i+=(c))
#define per(i,a,b,c) for(int i=(a);i>=(b);i-=(c))
#define F(i,a,b) for(int i=a,i##end=b;i<=i##end;i++)
#define dF(i,a,b) for(int i=a,i##end=b;i>=i##end;i--)
#define cmh(sjy) while(sjy--)
#define lowbit(x) ((x)&(-(x)))
#define HH printf("\n")
#define eb emplace_back
#define poly vector<int>
#define SZ(x) ((int)x.size())
using namespace std;
template<typename T>inline void chkmax(T &x,const T &y){ x=std::max(x,y); }
template<typename T>inline void chkmin(T &x,const T &y){ x=std::min(x,y); }
const int mod=998244353,maxn=500005;
vector<array<ll,3>>g[maxn];
int dis[maxn],cur[maxn],q[maxn],N,S,T,id[maxn],n,zsy;
ll co[maxn][2];
void add(int u,int v,ll w){ g[u].push_back({v,w,SZ(g[v])}),g[v].push_back({u,0,SZ(g[u])-1}); }
bool bfs(){
F(i,0,N)cur[i]=dis[i]=0;
int qL=1,qR=0; dis[q[++qR]=S]=1;
while(qL<=qR){
const int u=q[qL++];
for(auto [v,w,e]:g[u])if(w&&!dis[v]){
dis[v]=dis[u]+1,q[++qR]=v;
if(v==T)return 1;
}
} return 0;
}
ll dfs(int u,ll f){
if(u==T)return f;
ll res=0;
for(int &i=cur[u];i<SZ(g[u]);++i){
const int v=g[u][i][0]; ll &w=g[u][i][1];
if(w&&dis[v]==dis[u]+1){
ll val=dfs(v,min(f,w));
w-=val,g[v][g[u][i][2]][1]+=val;
f-=val,res+=val;
if(!f)return res;
}
}
return res;
}
void solve(){
cin>>n>>zsy,S=++N,T=++N;
if(n==1){
int x; cin>>x;
cout<<x<<'\n';
return;
}
F(i,1,n-1)id[i]=++N;
F(i,1,n-1){ int x; cin>>x,co[i][0]+=x; }
F(i,1,n){
int x; cin>>x;
if(i==1)co[1][1]+=x;
else if(i==n)co[n-1][0]+=x;
else add(id[i],id[i-1],x),add(id[i-1],id[i],x);
}
F(i,1,n-1){ int x; cin>>x,co[i][1]+=x; }
F(i,1,n-1)add(S,id[i],co[i][0]);
F(i,1,n-1)add(id[i],T,co[i][1]);
F(_,1,zsy){ int x,y,c; cin>>x>>y>>c,add(id[x],id[y],c); }
ll ans=0;
while(bfs())ans+=dfs(S,infll);
cout<<ans;
}
signed main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int zsy=1;
F(____,1,zsy)solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 22216kb
input:
5 2 2 3 5 2 6 1 2 1 1 1 2 4 2 1 4 4 2 3 1
output:
11
result:
wrong answer 1st numbers differ - expected: '13', found: '11'