QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#487213 | #5340. It Can Be Arranged | PetroTarnavskyi# | RE | 0ms | 3572kb | C++20 | 3.0kb | 2024-07-22 18:20:42 | 2024-07-22 18:20:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
LL LINF = 1e18;
struct Graph
{
struct Edge
{
int from, to;
LL cap, flow;
};
int n;
vector<Edge> edges;
vector<VI> g;
VI d, p;
void init(int _n)
{
n = _n;
edges.clear();
g.clear();
g.resize(n);
d.resize(n);
p.resize(n);
}
void addEdge(int from, int to, LL cap)
{
assert(0 <= from && from < n);
assert(0 <= to && to < n);
assert(0 <= cap);
g[from].PB(SZ(edges));
edges.PB({from, to, cap, 0});
g[to].PB(SZ(edges));
edges.PB({to, from, 0, 0});
}
int bfs(int s, int t)
{
fill(ALL(d), -1);
d[s] = 0;
queue<int> q;
q.push(s);
while (!q.empty())
{
int v = q.front();
q.pop();
for (int e : g[v])
{
int to = edges[e].to;
if (edges[e].flow < edges[e].cap && d[to] == -1)
{
d[to] = d[v] + 1;
q.push(to);
}
}
}
return d[t];
}
LL dfs(int v, int t, LL flow)
{
if (v == t || flow == 0)
return flow;
for (; p[v] < SZ(g[v]); p[v]++)
{
int e = g[v][p[v]], to = edges[e].to;
LL c = edges[e].cap, f = edges[e].flow;
if (f < c && (to == t || d[to] == d[v] + 1))
{
LL push = dfs(to, t, min(flow, c - f));
if (push > 0)
{
edges[e].flow += push;
edges[e ^ 1].flow -= push;
return push;
}
}
}
return 0;
}
LL flow(int s, int t)
{
assert(0 <= s && s < n);
assert(0 <= t && t < n);
assert(s != t);
LL flow = 0;
while (bfs(s, t) != -1)
{
fill(ALL(p), 0);
while (true)
{
LL f = dfs(s, t, LINF);
if (f == 0)
break;
flow += f;
}
}
return flow;
}
};
const int N = 147;
const int INF = 1e9;
bool used[N];
int a[N], b[N], s[N];
int c[N][N];
VI g[N];
void dfs(int v)
{
used[v] = true;
for (auto to : g[v])
if (!used[to])
dfs(to);
}
void solve()
{
int n, m;
cin >> n >> m;
Graph G;
G.init(2 * n + 2);
int ans = 0;
FOR (i, 0, n)
{
cin >> a[i] >> b[i] >> s[i];
ans += (s[i] + m - 1) / m;
}
FOR (i, 0, n)
{
FOR (j, 0, n)
{
cin >> c[i][j];
if (b[i] + c[i][j] < a[j])
g[i].PB(j);
}
}
int S = 2 * n;
int T = S + 1;
FOR (i, 0, n)
{
int x = (s[i] + m - 1) / m;
G.addEdge(S, i, x);
G.addEdge(n + i, T, x);
for(int j : g[i])
G.addEdge(i, n + j, INF);
//fill(used, used + n, false);
//dfs(i);
//FOR (j, 0, n)
//{
// if (used[j] && i != j)
// G.addEdge(i, n + j, INF);
//}
}
cout << ans - G.flow(S, T) << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
FOR (tc, 0, t)
{
cout << "Case " << tc + 1 << ": ";
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
3 1 5 1 60 12 0 4 1 1 100 10 50 130 3 150 200 15 80 170 7 0 2 3 4 5 0 7 8 9 10 0 12 13 14 15 0 2 1 1 10 1 12 20 1 0 2 5 0
output:
Case 1: 3 Case 2: 22 Case 3: 2
result:
ok 3 lines
Test #2:
score: -100
Runtime Error
input:
93 73 2421 5 5997 5769 8953 13857 572 32065 39982 2558 29906 54006 3321 12912 18798 7139 28055 40575 8920 30260 41509 4672 18593 45948 8750 17795 40178 6221 16098 43279 5229 14957 39451 2945 32472 42065 6492 3588 14115 8299 12991 37234 3922 17784 41003 1252 21981 25241 4935 21382 44165 8795 16387 26...