#include <bits/stdc++.h>
#include "homecoming.h"
#define endl '\n'
using namespace std;
const int MAXN = (1 << 22);
template<class FlowT>
struct max_flow
{
const static FlowT finf = 1e18 + 42 + 17;
const static FlowT feps = 0;
struct edge
{
FlowT flow, cap;
int idx, rev, to;
edge() { flow = 0; cap = 0; rev = 0; idx = 0; to = 0; }
edge(int _to, int _rev, FlowT _flow, FlowT _cap, int _idx)
{
to = _to; rev = _rev;
flow = _flow; cap = _cap;
idx = _idx;
}
};
vector<edge> G[MAXN];
int n, dist[MAXN], po[MAXN];
bool bfs(int s, int t)
{
dist[s] = -1, po[s] = 0;
dist[t] = -1, po[t] = 0;
for(int v = 0; v <= n; v++)
dist[v] = -1, po[v] = 0;
queue<int> Q;
Q.push(s);
dist[s] = 0;
while(!Q.empty())
{
int u = Q.front();
Q.pop();
for(edge e: G[u])
if(dist[e.to] == -1 && e.flow < e.cap)
{
dist[e.to] = dist[u] + 1;
Q.push(e.to);
}
}
return dist[t] != -1;
}
FlowT dfs(int u, int t, FlowT fl = finf)
{
if(u == t)
return fl;
for(; po[u] < G[u].size(); po[u]++)
{
auto &e = G[u][po[u]];
if(dist[e.to] == dist[u] + 1 && e.flow < e.cap)
{
FlowT f = dfs(e.to, t, min(fl, e.cap - e.flow));
e.flow += f;
G[e.to][e.rev].flow -= f;
if(f > 0)
return f;
}
}
return 0;
}
void init(int _n) { n = _n; for(int i = 0; i <= n; i++) G[i].clear(); }
void add_edge(int u, int v, FlowT w, int idx = -1)
{
//cout<<u<<" "<<v<<" "<<w<<endl;
G[u].push_back(edge(v, G[v].size(), 0, w, idx));
G[v].push_back(edge(u, G[u].size() - 1, 0, 0, -1));
}
FlowT flow(int s, int t)
{
if(s == t) return finf;
FlowT ret = 0, to_add;
while(bfs(s, t))
while((to_add = dfs(s, t)))
ret += to_add;
return ret;
}
};
max_flow<long long> f;
long long int solve(int N, int K, int *A, int *B)
{
/*
f.init(2*N+5);
for(int i=1;i<=N;i++)
f.add_edge(0,i,A[i-1]);
for(int i=1;i<=N;i++)
f.add_edge(N+i,2*N+1,B[i-1]);
for(int i=0;i<N;i++)
for(int add=0;add<K;add++)
{
int j=(i+add)%N;
f.add_edge(i+1,N+j+1,1e18);
}
long long ret=0;
for(int i=0;i<N;i++)
ret=ret+A[i];
return ret-f.flow(0,2*N+1);
*/
long long ret=0;
for(int i=0;i<N;i++)
ret=ret+A[i];
for(int i=0;i<N;i++)
for(int add=0;add<K;add++)
{
int j=(i+add)%N;
long long rem=min(A[i],B[j]);
ret=ret-rem;
A[i]=A[i]-rem;
B[j]=B[j]-rem;
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
98808 KB |
Output is correct |
2 |
Correct |
95 ms |
98880 KB |
Output is correct |
3 |
Correct |
93 ms |
98808 KB |
Output is correct |
4 |
Correct |
94 ms |
98936 KB |
Output is correct |
5 |
Correct |
95 ms |
98900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
98808 KB |
Output is correct |
2 |
Correct |
95 ms |
98880 KB |
Output is correct |
3 |
Correct |
93 ms |
98808 KB |
Output is correct |
4 |
Correct |
94 ms |
98936 KB |
Output is correct |
5 |
Correct |
95 ms |
98900 KB |
Output is correct |
6 |
Correct |
213 ms |
99028 KB |
Output is correct |
7 |
Correct |
181 ms |
98936 KB |
Output is correct |
8 |
Correct |
109 ms |
98940 KB |
Output is correct |
9 |
Incorrect |
97 ms |
98908 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
147 ms |
112152 KB |
Output is correct |
2 |
Correct |
104 ms |
99412 KB |
Output is correct |
3 |
Correct |
253 ms |
153948 KB |
Output is correct |
4 |
Incorrect |
104 ms |
99320 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
115 ms |
98808 KB |
Output is correct |
2 |
Correct |
95 ms |
98880 KB |
Output is correct |
3 |
Correct |
93 ms |
98808 KB |
Output is correct |
4 |
Correct |
94 ms |
98936 KB |
Output is correct |
5 |
Correct |
95 ms |
98900 KB |
Output is correct |
6 |
Correct |
213 ms |
99028 KB |
Output is correct |
7 |
Correct |
181 ms |
98936 KB |
Output is correct |
8 |
Correct |
109 ms |
98940 KB |
Output is correct |
9 |
Incorrect |
97 ms |
98908 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |