Submission #1007901

# Submission time Handle Problem Language Result Execution time Memory
1007901 2024-06-25T17:34:34 Z makanhulia Lasers (NOI19_lasers) C++17
45 / 100
87 ms 43124 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<ll,ll>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define freeopen freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define mod 998244353
#define pb push_back
#define mk make_pair
#define ll long long
#define foor(x,vec) for(auto x:vec ){cout<<x<<" ";}
#define fi first
#define se second
#define MAXN 500069
#define lld long double
#define cha ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ffl fflush(stdout)
#define sst string
#define pii pair<ll,ll>
ll mvx[]={0,0,-1,1};
ll mvy[]={1,-1,0,0};
ll n,q;

ll k[MAXN];
vector<ll> b[MAXN];
ll vis[MAXN];
ll ps[MAXN],sf[MAXN];
void solve(){
    cin>>n>>q;
    REP(i,0,q-1){
        cin>>k[i];
        REP(j,0,k[i]-1){
            ll x;
            cin>>x;
            b[i].pb(x);
        }
    }
    ll ans=0;
    vector <pair<ll,ll>> vec;
    REP(i,0,q-1){
        REP(j,0,k[i]){
            ps[j]=0;
            sf[j]=0;
        }
        for(ll j=0;j<k[i];j++){
            ps[j]=ps[j-1]+b[i][j];
        }
        for(ll j=k[i]-1;j>=0;j--){
            sf[j]=sf[j+1]+b[i][j];
        }
       
        REP(j,0,k[i]-1){
            ll r=n-sf[j+1];
            ll l=ps[j-1];
            l=max(l,(ll)0);
            r=min(r,(n));
            if(j-1<0)l=0;
            ll len=r-l+1;
            if(len-2*(len-b[i][j])>0){
                ll nl=r-b[i][j]+1;
                ll nr=l+b[i][j];
                nl=max(nl,(ll)1);
                nr=min(nr,(n));
                if(nl<=nr)
                vec.pb({nl,nr});
            }
        }
    }
    sort(vec.begin(),vec.end());
    ll i=0;
    while(i<vec.size()){
        ll ln=vec[i].fi;
        ll rn=vec[i].se;
        ll idx=i+1;
        while(idx<vec.size()){
            if(vec[idx].fi<=rn){
                rn=max(rn,vec[idx].se);
                idx++;
            }
            else{
                break;
            }
        }
        ans+=max((rn-ln+1),(ll)0);
        i=idx;
    }
    cout<<ans<<endl;
}
int main(){
    cha
    ll tc=1;
//    cin>>tc;
    while(tc--){
        solve();
    }
}

Compilation message

lasers.cpp: In function 'void solve()':
lasers.cpp:70:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     while(i<vec.size()){
      |           ~^~~~~~~~~~~
lasers.cpp:74:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |         while(idx<vec.size()){
      |               ~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16728 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16984 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 2 ms 16728 KB Output is correct
9 Correct 2 ms 16732 KB Output is correct
10 Correct 2 ms 16728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16728 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16984 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 2 ms 16728 KB Output is correct
9 Correct 2 ms 16732 KB Output is correct
10 Correct 2 ms 16728 KB Output is correct
11 Correct 2 ms 16728 KB Output is correct
12 Correct 82 ms 43124 KB Output is correct
13 Correct 2 ms 16732 KB Output is correct
14 Correct 2 ms 16732 KB Output is correct
15 Correct 2 ms 16732 KB Output is correct
16 Correct 2 ms 16732 KB Output is correct
17 Correct 87 ms 39880 KB Output is correct
18 Correct 2 ms 16732 KB Output is correct
19 Correct 2 ms 16732 KB Output is correct
20 Correct 2 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 29144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 3 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16732 KB Output is correct
7 Correct 2 ms 16728 KB Output is correct
8 Correct 2 ms 16732 KB Output is correct
9 Correct 2 ms 16732 KB Output is correct
10 Correct 2 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 29144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 16728 KB Output is correct
2 Correct 2 ms 16732 KB Output is correct
3 Correct 2 ms 16732 KB Output is correct
4 Correct 2 ms 16732 KB Output is correct
5 Correct 2 ms 16732 KB Output is correct
6 Correct 2 ms 16984 KB Output is correct
7 Correct 2 ms 16732 KB Output is correct
8 Correct 2 ms 16728 KB Output is correct
9 Correct 2 ms 16732 KB Output is correct
10 Correct 2 ms 16728 KB Output is correct
11 Correct 2 ms 16728 KB Output is correct
12 Correct 82 ms 43124 KB Output is correct
13 Correct 2 ms 16732 KB Output is correct
14 Correct 2 ms 16732 KB Output is correct
15 Correct 2 ms 16732 KB Output is correct
16 Correct 2 ms 16732 KB Output is correct
17 Correct 87 ms 39880 KB Output is correct
18 Correct 2 ms 16732 KB Output is correct
19 Correct 2 ms 16732 KB Output is correct
20 Correct 2 ms 16732 KB Output is correct
21 Incorrect 30 ms 29144 KB Output isn't correct
22 Halted 0 ms 0 KB -