This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
typedef long long ll;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n, m;
std::cin >> n >> m;
std::vector<ll> t(m), a(m);
for (auto &i : t) {
std::cin >> i;
}
for (auto &i : a) {
std::cin >> i;
}
std::vector<std::vector<ll>> adj(m);
std::vector<ll> indeg(m), outdeg(m);
for (ll i = 0; i < m; ++i) {
for (ll j = 0; j < m; ++j) {
if (i == j) {
continue;
}
if (std::abs(a[i] - a[j]) <= t[j] - t[i]) {
adj[i].push_back(j);
// std::cout << i << ", " << j << '\n';
outdeg[i]++, indeg[j]++;
}
}
}
std::function<ll(ll)> dfs;
std::vector<bool> vis(n);
bool bad = false;
dfs = [&](ll node) {
if (vis[node]) {
bad = true;
return ll(-1e15);
}
vis[node] = true;
ll ans = 0;
for (auto &i : adj[node]) {
ans += dfs(i);
}
return std::max(ans, 1LL);
};
ll ans = 0;
for (ll i = 0; i < m; ++i) {
if (indeg[i] == 0) {
ll cur = dfs(i);
if (!bad) {
ans += cur;
} else {
bad = false;
}
}
}
std::cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |