# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
519429 | Jomnoi | Lasers (NOI19_lasers) | C++17 | 220 ms | 68500 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>
#define DEBUG 0
using namespace std;
using pii = pair <int, int>;
const int N = 5e5+10;
vector <int> laser[N];
vector <int> qs[N];
int ct[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int l, r;
cin >> l >> r;
for(int i = 1; i <= r; i++) {
int x, y;
cin >> x;
while(x--) {
cin >> y;
laser[i].push_back(y);
}
qs[i].push_back(0);
for(int j = 0; j < laser[i].size(); j++) {
qs[i].push_back(qs[i].back()+laser[i][j]);
}
if(DEBUG) {
cout << "\nDebug : ";
for(auto v : qs[i]) {
cout << v << " ";
}
cout << endl << endl;
}
}
if(DEBUG) {
cout << endl;
}
vector <pii> vec;
for(int i = 1; i <= r; i++) {
for(int j = 0; j < laser[i].size(); j++) {
int left = qs[i][j];
int right = l-qs[i].back()+qs[i][j+1];
int range = right-left;
if(DEBUG) {
cout << "Debug : ";
cout << left << " " << right << " " << 2*laser[i][j]-range << " " << range-laser[i][j] << endl;
}
if(2*laser[i][j]-range > 0) {
vec.emplace_back(left+range-laser[i][j]+1, 1);
vec.emplace_back(right-range+laser[i][j]+1, -1);
}
}
if(DEBUG) {
cout << endl;
}
}
sort(vec.begin(), vec.end());
int ans = 0, sum = 0, left = -1;
for(auto v : vec) {
sum += v.second;
if(left == -1) {
left = v.first;
}
if(!sum) {
ans += v.first-left;
left = -1;
}
}
cout << ans;
return 0;
}
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... |