답안 #1007898

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007898 2024-06-25T17:27:25 Z makanhulia Lasers (NOI19_lasers) C++17
0 / 100
24 ms 28636 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];
            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]-1;
                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;
            }
        }
        i=idx;
        ans+=max((rn-ln+1),(ll)0);
    }
    cout<<ans<<endl;
}
int main(){
    cha
    ll tc=1;
//    cin>>tc;
    while(tc--){
        solve();
    }
}

Compilation message

lasers.cpp: In function 'void solve()':
lasers.cpp:67: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]
   67 |     while(i<vec.size()){
      |           ~^~~~~~~~~~~
lasers.cpp:71: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]
   71 |         while(idx<vec.size()){
      |               ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Incorrect 2 ms 16732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Incorrect 2 ms 16732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 28636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 16732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 24 ms 28636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 16732 KB Output is correct
2 Incorrect 2 ms 16732 KB Output isn't correct
3 Halted 0 ms 0 KB -