Submission #821323

#TimeUsernameProblemLanguageResultExecution timeMemory
821323makanhuliaLasers (NOI19_lasers)C++17
100 / 100
282 ms45004 KiB
#include <bits/stdc++.h> #define ll long long #define longlonginf LONG_LONG_MAX using namespace std; ll n,m,x; ll l,r; void solve(){ cin>>n; cin>>m; vector<vector<ll>> v(m+5); ll rem[m+5]; memset(rem,0,sizeof(rem)); for(int i = 0 ; i < m ; i++){ cin>>x; while(x--){ ll k; cin>>k; v[i].push_back(k); rem[i] += k; } rem[i] = n-rem[i]; } vector<pair<ll,ll>> p; for(int i = 0 ; i < m ; i++){ ll k = 0; for(auto x : v[i]){ r = k+x; l = k+1; if( l+rem[i]-1 < r ){ p.push_back({l+rem[i],r}); //cout<<"{"<<l+rem[i]<<","<<r<<"} "; } k += x; } //cout<<"\n"; } if( p.empty() ){ cout<<0<<"\n"; return; } sort(p.begin(),p.end()); p.push_back({longlonginf,longlonginf}); ll cur = p[0].first; ll mx = p[0].second; ll ans = 0; for(auto x : p){ if( x.first <= mx ){ mx = max(mx,x.second); } else{ //cout<<"! "<<cur<<" "<<mx<<"\n"; ans += mx-cur+1; cur = x.first; mx = max(mx,x.second); } } cout<<ans<<"\n"; } int main(){ int T = 1; //cin>>T; for(int i = 1 ; i <= T ; i++){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...