# Source
https://arxiv.org/pdf/2303.04147.pdf

# Gen Testcase
## Small test
## Large test
m = [10, 50, 100, 500, 1000]
k = [10, 50, 100, 500, 1000]
n = [10, 50, 100, 500, 1000]
# Checker
```cpp=
#include <bits/stdc++.h>
using namespace std;
// using ld = double;
void format_err(string msg) {
cout << "0 " << "Wrong format:: " << msg;
exit(0);
}
void invalid(string msg) {
cout << "0 " << "Invalid:: " << msg;
exit(0);
}
bool check_date_format(string s) {
for (auto &c : s) {
if (c >= '0' && c <= '9') c = '*';
}
return s != "**:**:**";
}
string to_str(int x, int n_dg = 0) {
string s;
while (x) s += x % 10 ^ '0', x /= 10;
while (s.size() < n_dg) s += '0';
reverse(begin(s), end(s));
return s;
}
int time_to_sec(string s) {
if (check_date_format(s)) format_err("Wrong time format (" + s + ")!");
s += ':';
int x = 0;
vector<int> cc;
for (auto c : s) {
if (c >= '0' && c <= '9') (x *= 10) += c ^ '0';
else cc.push_back(x), x = 0;
}
return cc[0] * 60 * 60 + cc[1] * 60 + cc[2];
}
string sec_to_time(int x) {
vector<string> v;
for (int c = 0; c < 3; c++) {
v.push_back(to_str(x % 60, 2));
x /= 60;
}
return v[2] + ":" + v[1] + ":" + v[0];
}
struct ttruck {
int p; // id start/end
string k; // start time
string t; // end time
double c; // capacity
double vol; // volume
double vel; // average speed
int K, T;
void ref() {
vel /= 3.6;
K = time_to_sec(k);
T = time_to_sec(t);
}
friend ostream& operator << (ostream &ss, ttruck b) {
ss << "(" << b.p << " " << b.k << " " << b.t << " " << b.c << " " << b.vol << " " << b.vel << ")";
return ss;
}
};
struct trequest {
int s; // id source
int e; // id dest.
double d; // weight
double v; // volume
int sp; // load time
int sd; // unload time
string ep; // source - earliest time
string lp; // source - latest time
string ed; // dest. - earliest time
string ld; // dest. - latest time
int eps, lps, eds, lds;
void ref() {
eps = time_to_sec(ep);
lps = time_to_sec(lp);
eds = time_to_sec(ed);
lds = time_to_sec(ld);
}
friend ostream& operator << (ostream &ss, trequest b) {
ss << "(" << b.s << " " << b.e << " " << b.d << " " << b.v << " " << b.sp << " " << b.sd << " " << b.ep << " " << b.lp << " " << b.ed << " " << b.ld << ")";
return ss;
}
};
struct tprod {
int id;
int pd;
};
struct troute {
int h;
int ar;
int de;
vector<tprod> xs;
bool operator < (troute b) {
return make_pair(ar, -de) < make_pair(b.ar, -b.de);
}
};
int main(int argc, char* argv[]) {
// registerTestlibCmd(argc, argv);
int m;// = inf.readInt();
if (!(cin >> m)) {
format_err("Failed to read m from input data!");
}
vector<vector<double>> dst(m + 1, vector<double>(m + 1)); // distance between each pair of hub
for (int i = 1; i <= m; i++) {
for (int j = 1; j <= m; j++) //dst[i][j] = inf.readInt() * 1000;
if (!(cin >> dst[i][j])) {
format_err("Failed to read distance matrix from input data!");
}
}
int k;// = inf.readInt();
if (!(cin >> k)) {
format_err("Failed to read k from input data!");
}
vector<ttruck> ts(k);
for (auto &t : ts) {
if (!(cin >> t.p >> t.k >> t.t >> t.c >> t.vol >> t.vel)) {
format_err("Failed to read truck information from input data!");
}
// t.p = inf.readInt();
// t.k = inf.readToken();
// t.t = inf.readToken();
// t.c = inf.readDouble();
// t.vol = inf.readDouble();
// t.vel = inf.readDouble();
t.ref();
}
int n;// = inf.readInt();
if (!(cin >> n)) {
format_err("Failed to read n from input data!");
}
vector<trequest> rqs(n);
for (auto &rq : rqs) {
if (!(cin >> rq.s >> rq.e >> rq.d >> rq.v >> rq.sp >> rq.sd >> rq.ep >> rq.lp >> rq.ed >> rq.ld)) {
format_err("Failed to read order information from input data!");
}
// rq.s = inf.readInt();
// rq.e = inf.readInt();
// rq.d = inf.readDouble();
// rq.v = inf.readDouble();
// rq.sp = inf.readInt();
// rq.sd = inf.readInt();
// rq.ep = inf.readToken();
// rq.lp = inf.readToken();
// rq.ed = inf.readToken();
// rq.ld = inf.readToken();
rq.ref();
}
// exit(0);
int n_ = 0, uk = 0, tt = 0;
vector<int> load(n, -1), unload(n, -1);
for (int _ = 0; _ < k; _++) {
auto &t = ts[_];
int u; // = ouf.readInt();
if (!(cin >> u)) {
format_err("Failed to read u(" + to_str(_ + 1) + ") from your output!");
}
vector<troute> v(u);
int j = 0;
for (auto &r : v) {
j++;
// r.h = ouf.readInt(1, m);
if (!(cin >> r.h)) {
format_err("Failed to read h(" + to_str(_ + 1) + ", " + to_str(j) + ") from your output!");
}
if (r.h < 1 || r.h > m) {
format_err("h(" + to_str(_ + 1) + ", " + to_str(j) + " out of range [1, m]!");
}
int x;// = ouf.readInt();
if (!(cin >> x)) {
format_err("Failed to read x(" + to_str(_ + 1) + ", " + to_str(j) + ") from your output!");
}
n_ += x;
r.xs.resize(x);
string a, b;
if (!(cin >> a)) {
format_err("Failed to read ar(" + to_str(_ + 1) + ", " + to_str(j) + ") from your output!");
}
if (!(cin >> b)) {
format_err("Failed to read de(" + to_str(_ + 1) + ", " + to_str(j) + ") from your output!");
}
// a = ouf.readToken(); b = ouf.readToken();
r.ar = time_to_sec(a);
r.de = time_to_sec(b);
int z = 0;
for (auto &x : r.xs) {
z++;
if (!(cin >> x.id)) {
format_err("Failed to read id(" + to_str(_ + 1) + ", " + to_str(j) + ", " + to_str(z) + ") from your output!");
}
// x.id = ouf.readInt(1, n);
if (!(cin >> a)) {
format_err("Failed to read pd(" + to_str(_ + 1) + ", " + to_str(j) + ", " + to_str(z) + ") from your output!");
}
// a = ouf.readToken();
x.pd = time_to_sec(a);
}
}
if (v.back().h ^ t.p) invalid("The last hub on the route of truck " + to_str(_ + 1) + " is violated!");
if (v[0].h ^ t.p) invalid("The first hub on the route of truck " + to_str(_ + 1) + " is violated!");
if (v[0].ar < t.K) invalid("ar(" + to_str(_ + 1) + ", 1) is less than f(" + to_str(_ + 1) + ")!");
if (v.back().de > t.T) invalid("de(" + to_str(_ + 1) + ", u( + " + to_str(_ + 1) + ")) is greater than t(" + to_str(_ + 1) + ")!");
double cr = t.K;
int cru = t.p;
for (int i = 0; i < v.size(); i++) {
auto r = v[i];
if (r.ar > r.de) invalid("ar(" + to_str(_ + 1) + ", " + to_str(i + 1) + ") is greater than de(" + to_str(_ + 1) + ", " + to_str(i + 1) + ")!");
if (i >= 0) {
cr = ceil(cr + dst[cru][r.h] / t.vel);
if (cr > r.ar) invalid("ear(" + to_str(_ + 1) + ", " + to_str(i + 1) + ") is greater than ar(" + to_str(_ + 1) + ", " + to_str(i + 1) + ")!");
cr = r.ar;
int z = 0;
for (auto x : r.xs) {
x.id--;
z++;
auto &rq = rqs[x.id];
if (rq.s == r.h) {
if (~load[x.id] && load[x.id] ^ _) invalid("Truck " + to_str(_ + 1) + " takes order " + to_str(x.id + 1) + " that is taken by truck " + to_str(load[x.id] + 1) + "!");
load[x.id] = _;
if ((t.c -= rq.d) < -1e-6 || (t.vol -= rq.v) < -1e-6) {
invalid("Truck " + to_str(_ + 1) + " is overloaded at hub " + to_str(r.h + 1) + " when picking up order " + to_str(x.id + 1) + "!");
}
if (x.pd < rq.eps || x.pd > rq.lps) invalid("The picking time of order " + to_str(x.id + 1) + " is out of range [ep, lp]!");
if (cr > x.pd) invalid("epd(" + to_str(_ + 1) + ", " + to_str(i + 1) + ", " + to_str(z) + ") is greater than pd(" + to_str(_ + 1) + ", " + to_str(i) + ", " + to_str(z) + ")!");
cr = x.pd + rq.sp;
}
else if (rq.e == r.h) {
if (~unload[x.id] && unload[x.id] ^ _ || load[x.id] ^ _) {
// cerr << "truck " << (_ + 1) << " order " << (x.id + 1) << " load " << (load[x.id]) << " unload " << unload[x.id] << endl;
invalid("Truck "+ to_str(_ + 1) + " arrives at the delivery hub of order " + to_str(x.id + 1) + " before arriving the pickup hub!" );
}
unload[x.id] = _;
t.c += rq.d; t.vol += rq.v;
if (x.pd < rq.eds || x.pd > rq.lds) invalid("The delivery time of order " + to_str(x.id + 1) + " is out of range [ed, ld]!");
if (cr > x.pd) invalid("epd(" + to_str(_ + 1) + ", " + to_str(i + 1) + ", " + to_str(z) + ") is greater than pd(" + to_str(_ + 1) + ", " + to_str(i) + ", " + to_str(z) + ")!");
cr = x.pd + rq.sd;
}
else {
// cout << _ << " " << i << " " << rq.s << " " << rq.e << "\n";
invalid("Order " + to_str(x.id + 1) + " is neither delivered nor picked up at hub " + to_str(r.h + 1) + "!");
}
}
if (cr > r.de) invalid("The time of completion of loading and unloading at hub " + to_str(r.h + 1) + " of truck " + to_str(_ + 1) + " exceeds the departure time!");
cr = r.de;
cru = r.h;
}
}
tt += v.back().de - v[0].ar;
uk += u > 1;
}
if (n_ & 1 || n_ > n * 2) {
invalid("At least one request is taken twice!");
// cout << "0 " << "At least one request is taken twice!";
}
for (int i = 0; i < n; i++) {
if (load[i] ^ unload[i]) invalid("Order " + to_str(i + 1) + " is picked up but not delivered!");
}
int o = n_ >> 1;
int score = 1e9 * o / n - 1e6 * uk / k - 1. / 1e3 * tt;
score = max(0, score);
cout << score << " Accepted";
// quitp(1e6 * o / n + 1e3 * (k - uk) / k - 1. / 1e3 * tt, "Correct!");
return 0;
}
```