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>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
const ll mod = 1e9 + 7;
const int mxn = 1e6 + 69, mxq = 1e5 + 5, sq = 500, mxv = 2e7 + 5;
//const int base = (1 <<18);
const int inf = 1e9 + 5, neg = -69420;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//const int x[9] = {0, 1, 1, -1, -1, 2, -2, 2, -2};
//const inty[9] = {0, 2, -2, 2, -2, 1, 1, -1, -1};
int n, l;
map<int, int>p;
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen("COMCAT.INP", "r", stdin);
//freopen("COMCAT.OUT", "w", stdout);
cin >> l >> n;
for(int i = 1; i <= n; i++){
int x; cin >> x;
vt<int>v(x);
ll tot = 0;
for(int j = 0; j < x; j++){
cin >> v[j]; tot += v[j];
}
if(tot == l)continue;
ll pref = 0;
vt<pll>seg;
for(int j = 0; j <= x; j++){
ll lpos = pref + 1, rpos = l - (tot - pref);
while(sz(seg) && lpos <= seg.back().se){
lpos = seg.back().fi; seg.pop_back();
}
seg.pb(mpp(lpos, rpos));
if(j < x)pref += v[j];
}
for(auto [lp, rp]: seg){
p[lp]++; p[rp + 1]--;
}
}
ll pref = 0, ans = 0, last = 0;
for(auto i: p){
//cout << i.fi << " " << i.se << "\n";
if(pref == n){
ans += i.fi - last;
}
last = i.fi; pref += i.se;
}
cout << l - ans;
return(0);
}
Compilation message (stderr)
lasers.cpp: In function 'int main()':
lasers.cpp:56:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
56 | for(auto [lp, rp]: seg){
| ^
# | 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... |