Submission #643011

#TimeUsernameProblemLanguageResultExecution timeMemory
643011devariaotaLasers (NOI19_lasers)C++17
24 / 100
270 ms13284 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); const ll MOD=1e9+7; using namespace std; ll N,M,s[500005]; vector <pair<ll,ll> > vec; int main(){ cin>>N>>M; for(int i=1;i<=M;i++){ cin>>s[i]; ll a[s[i]+1]; ll pref[s[i]+1]; ll suff[s[i]+1]; for(int j=1;j<=s[i];j++){ ll y; cin>>y; a[j]=y; } pref[0]=0; suff[s[i]+1]=0; for(int j=1;j<=s[i];j++){ pref[j]=pref[j-1]+a[j]; } for(int j=s[i];j>=1;j--){ suff[j]=suff[j+1]+a[j]; } for(int j=1;j<=s[i];j++){ ll l=N-suff[j]+1; ll r=pref[j]; if(l<=r){ vec.push_back({l,r}); } } } sort(vec.begin(),vec.end()); if(vec.empty()){ cout<<0<<endl; return 0; } ll l=vec[0].fi; ll r=vec[0].se; ll ans=r-l+1; for(int i=1;i<vec.size();i++){ if(vec[i].fi>r){ l=vec[i].fi; r=vec[i].se; ans+=vec[i].se-vec[i].fi+1; } else if(vec[i].se>r){ l=vec[i].fi; r=vec[i].se; ans+=vec[i].se-r; } } cout<<ans<<endl; } /* 20 6 1 8 2 2 8 3 2 2 8 4 2 2 2 8 5 2 2 2 2 8 6 2 2 2 2 2 8 */

Compilation message (stderr)

lasers.cpp: In function 'int main()':
lasers.cpp:46:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |   for(int i=1;i<vec.size();i++){
      |               ~^~~~~~~~~~~
#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...