Submission #18769236
Source Code Expand
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <atcoder/mincostflow>
#include <algorithm>
#include <cassert>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;
using namespace atcoder;
using uint = unsigned int;
using ll = long long;
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int n;
cin >> n;
struct Stone {
ll size, num;
int cost;
};
vector<int> offset(n + 1);
vector<vector<Stone>> stones(n);
for (int i = 0; i < n; i++) {
int k;
cin >> k;
offset[i + 1] = offset[i] + k;
stones[i] = vector<Stone>(k);
for (int j = 0; j < k; j++) {
cin >> stones[i][j].size >> stones[i][j].cost >> stones[i][j].num;
}
sort(stones[i].begin(), stones[i].end(),
[&](const Stone& l, const Stone& r) { return l.size < r.size; });
}
int sv = offset[n], tv = sv + 1;
struct E {
int to, rev, cap;
ll dist;
};
mcf_graph<int, ll> g(tv + 1);
const int INF_CAP = int(1e9);
for (int i = 0; i < n; i++) {
int k = int(stones[i].size());
int bk = sv;
for (int j = 0; j < k; j++) {
// x_ij >= x_i{j-1}
int nw = offset[i] + j;
g.add_edge(nw, bk, INF_CAP, 0);
g.add_edge(bk, nw, INF_CAP, stones[i][j].num);
g.add_edge(bk, nw, stones[i][j].cost, 0);
bk = nw;
}
g.add_edge(bk, tv, INF_CAP, 0);
g.add_edge(tv, bk, INF_CAP, 0);
}
int m;
cin >> m;
for (int ph = 0; ph < m; ph++) {
int u, v;
ll w;
cin >> u >> v >> w;
u--;
v--;
int ku = int(stones[u].size());
int kv = int(stones[v].size());
for (int i = 0; i < ku; i++) {
for (int j = 0; j < kv; j++) {
if (stones[u][i].size + w < stones[v][j].size) {
// x_ui <= x_v(j-1)
int vjn1 = (j == 0 ? sv : offset[v] + j - 1);
g.add_edge(vjn1, offset[u] + i, INF_CAP, 0);
break;
}
}
}
}
auto slope = g.slope(sv, tv, 30000);
using Line = tuple<ll, int, ll>;
vector<Line> lines;
for (int i = 0; i < int(slope.size()) - 1; i++) {
auto a = slope[i], b = slope[i + 1];
lines.push_back(Line{(b.second - a.second) / (b.first - a.first), a.first, a.second});
}
int q;
cin >> q;
for (int ph = 0; ph < q; ph++) {
ll a;
cin >> a;
auto it = lower_bound(lines.begin(), lines.end(), Line{a, -1, -1});
if (it == lines.end()) {
cout << -1 << "\n";
continue;
}
int cap_flow;
ll flow;
tie(ignore, cap_flow, flow) = *it;
ll sum = cap_flow * a - flow;
cout << sum << "\n";
}
return 0;
}
Submission Info
Submission Time |
|
Task |
F - Jewelry Box |
User |
yosupo |
Language |
C++ (GCC 9.2.1) |
Score |
2100 |
Code Size |
2991 Byte |
Status |
AC |
Exec Time |
99 ms |
Memory |
4084 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
2100 / 2100 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00-sample-01.txt, 00-sample-02.txt |
All |
00-sample-01.txt, 00-sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt |
Case Name |
Status |
Exec Time |
Memory |
00-sample-01.txt |
AC |
9 ms |
3552 KB |
00-sample-02.txt |
AC |
2 ms |
3508 KB |
01-01.txt |
AC |
36 ms |
3964 KB |
01-02.txt |
AC |
36 ms |
3972 KB |
01-03.txt |
AC |
38 ms |
3904 KB |
01-04.txt |
AC |
34 ms |
3980 KB |
01-05.txt |
AC |
35 ms |
3896 KB |
01-06.txt |
AC |
36 ms |
3984 KB |
01-07.txt |
AC |
27 ms |
3976 KB |
01-08.txt |
AC |
37 ms |
3932 KB |
01-09.txt |
AC |
33 ms |
4044 KB |
01-10.txt |
AC |
29 ms |
3988 KB |
01-11.txt |
AC |
23 ms |
3876 KB |
01-12.txt |
AC |
20 ms |
3868 KB |
01-13.txt |
AC |
12 ms |
4008 KB |
01-14.txt |
AC |
10 ms |
3868 KB |
01-15.txt |
AC |
6 ms |
3852 KB |
01-16.txt |
AC |
8 ms |
3992 KB |
01-17.txt |
AC |
81 ms |
3936 KB |
01-18.txt |
AC |
57 ms |
4008 KB |
01-19.txt |
AC |
73 ms |
4004 KB |
01-20.txt |
AC |
74 ms |
4008 KB |
01-21.txt |
AC |
42 ms |
4084 KB |
01-22.txt |
AC |
38 ms |
4060 KB |
01-23.txt |
AC |
14 ms |
3932 KB |
01-24.txt |
AC |
44 ms |
3968 KB |
01-25.txt |
AC |
44 ms |
3924 KB |
01-26.txt |
AC |
47 ms |
3984 KB |
01-27.txt |
AC |
11 ms |
4000 KB |
01-28.txt |
AC |
33 ms |
4052 KB |
01-29.txt |
AC |
42 ms |
3952 KB |
01-30.txt |
AC |
61 ms |
4008 KB |
01-31.txt |
AC |
44 ms |
3828 KB |
01-32.txt |
AC |
58 ms |
4008 KB |
01-33.txt |
AC |
60 ms |
3892 KB |
01-34.txt |
AC |
55 ms |
3992 KB |
01-35.txt |
AC |
55 ms |
3864 KB |
01-36.txt |
AC |
49 ms |
3888 KB |
01-37.txt |
AC |
45 ms |
3820 KB |
01-38.txt |
AC |
36 ms |
3956 KB |
01-39.txt |
AC |
37 ms |
3900 KB |
01-40.txt |
AC |
99 ms |
3980 KB |
01-41.txt |
AC |
84 ms |
4032 KB |
01-42.txt |
AC |
88 ms |
3948 KB |
01-43.txt |
AC |
39 ms |
3928 KB |
01-44.txt |
AC |
65 ms |
3968 KB |
01-45.txt |
AC |
68 ms |
3960 KB |
01-46.txt |
AC |
9 ms |
3640 KB |