# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
525285 | sicho_mohit | Lasers (NOI19_lasers) | C++14 | 331 ms | 41284 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 ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std ;
const int N=1e5+5;
int main ()
{
ll n , k ;
cin >> n >> k ;
vector<vector<ll>>prefix(k+1);
for (int i=0;i<k;i++)
{
int t ;
cin >> t ;
ll sum=0;
prefix[i].pb(0);
for (int j=0;j<t;j++)
{
ll a;
cin >> a ;
sum+=a;
prefix[i].pb(sum);
}
}
vector<pair<ll,ll>>ans;
// start from each row
for (int i=0;i<k;i++)
{
// work on this row
for (int j=1;j<prefix[i].size();j++)
{
ll l=prefix[i][j-1]+1;
ll r=(n-(prefix[i][prefix[i].size()-1]-prefix[i][j]));
ll s=r-l+1;
ll w=prefix[i][j]-prefix[i][j-1];
if(2*w-s>0)
{
ans.pb({r-w+1,l+w-1});
}
}
}
sort(ans.begin(),ans.end());
if(ans.size()==0)
cout<<"0"<<"\n";
else
{
ll emax=ans[0].ss;
ll finalans=ans[0].ss-ans[0].ff+1;
for (int i=1;i<ans.size();)
{
while(ans[i].ss<=emax&&i<ans.size())
{
i++;
}
if(i<ans.size())
{
if(ans[i].ff>emax)
{
finalans+=ans[i].ss-ans[i].ff+1;
}
else if(ans[i].ff==emax)
{
finalans+=ans[i].ss-ans[i].ff;
}
else
{
finalans+=ans[i].ss-emax;
}
emax=max(emax,ans[i].ss);
i++;
}
}
cout<<finalans<<"\n";
}
}
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... |