| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1287357 | QuocSensei | Lasers (NOI19_lasers) | C++20 | 95 ms | 8856 KiB |
#include <bits/stdc++.h>
#define ll long long
#define el cout << '\n'
#define ii pair<int, int>
#define fi first
#define se second
using namespace std;
struct Line
{
int l, r;
Line(int l = 0, int r = 0) :
l(l), r(r) {};
Line operator & (Line other)
{
Line ans;
ans.l = max(l, other.l);
ans.r = min(r, other.r);
return ans;
}
};
const int maxn = 5e5;
int L, R, a[maxn + 10], ans = 0, cnt = 0;
vector<ii> points;
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen("LASER.INP", "r"))
{
freopen("LASER.INP", "r", stdin);
freopen("LASER.OUT", "w", stdout);
}
cin >> L >> R;
for (int i = 1; i <= R; i++)
{
int n, pre = 0, suf = 0;
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
suf += a[i];
}
for (int i = 1; i <= n; pre += a[i], i++)
{
suf -= a[i];
int l_1 = pre + 1;
int r_1 = l_1 + a[i] - 1;
int r_2 = L - suf;
int l_2 = r_2 - a[i] + 1;
Line intersect = Line(l_1, r_1) & Line(l_2, r_2);
if (intersect.l > intersect.r)
continue;
points.push_back(ii(intersect.l, 1));
points.push_back(ii(intersect.r + 1, -1));
}
}
sort(points.begin(), points.end());
// for (ii pr : points)
// cout << pr.fi << ' ' << pr.se, el;
for (int i = 0; i < points.size(); )
{
if (cnt)
ans += points[i].fi - points[i - 1].fi;
int j = i;
while (j < points.size() && points[i].fi == points[j].fi)
{
cnt += points[j].se;
j++;
}
// cout << i << ' ' << j << ' ' << delta, el;
i = j;
}
cout << ans;
}
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... | ||||
