# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
336423 | ncduy0303 | Lasers (NOI19_lasers) | C++17 | 149 ms | 10076 KiB |
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>
using namespace std;
#define ar array
#define ll long long
const int MAX_N = 1e5 + 1;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const ll LINF = 1e18;
void solve() {
int len, n; cin >> len >> n;
vector<ar<int,2>> block; // all ranges where the laser cannot pass through
for (int i = 0; i < n; i++) {
int m; cin >> m;
vector<int> ps(m + 1);
for (int i = 1; i <= m; i++) {
cin >> ps[i];
ps[i] += ps[i - 1];
}
for (int i = 1; i <= m; i++) {
int l = len - (ps[m] - ps[i - 1]) + 1;
int r = ps[i];
if (l <= r) block.push_back({l, r});
}
}
sort(block.begin(), block.end());
if (block.empty()) {
cout << 0 << "\n";
return;
}
int ans = 0;
auto rng = block[0];
for (int i = 1; i < block.size(); i++) {
auto new_rng = block[i];
if (rng[1] + 1 < new_rng[0]) {
ans += rng[1] - rng[0] + 1;
rng = new_rng;
}
else {
rng[1] = max(rng[1], new_rng[1]);
}
}
ans += rng[1] - rng[0] + 1;
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}
Compilation message (stderr)
# | 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... |