답안 #1007935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007935 2024-06-26T00:40:36 Z kebine Lasers (NOI19_lasers) C++17
100 / 100
98 ms 49600 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 700069
#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 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});
            }
        }
    }
    if(vec.size())
    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;
    }
    ans=min(ans,n);
    cout<<ans<<endl;
}
int main(){
    cha
    ll tc=1;
//    cin>>tc;
    while(tc--){
        solve();
    }
}

Compilation message

lasers.cpp: In function 'void solve()':
lasers.cpp:69: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]
   69 |     while(i<vec.size()){
      |           ~^~~~~~~~~~~
lasers.cpp:73: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]
   73 |         while(idx<vec.size()){
      |               ~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 3 ms 20828 KB Output is correct
3 Correct 3 ms 20828 KB Output is correct
4 Correct 3 ms 20928 KB Output is correct
5 Correct 3 ms 20828 KB Output is correct
6 Correct 3 ms 20824 KB Output is correct
7 Correct 4 ms 20924 KB Output is correct
8 Correct 3 ms 20828 KB Output is correct
9 Correct 3 ms 20824 KB Output is correct
10 Correct 3 ms 20824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 3 ms 20828 KB Output is correct
3 Correct 3 ms 20828 KB Output is correct
4 Correct 3 ms 20928 KB Output is correct
5 Correct 3 ms 20828 KB Output is correct
6 Correct 3 ms 20824 KB Output is correct
7 Correct 4 ms 20924 KB Output is correct
8 Correct 3 ms 20828 KB Output is correct
9 Correct 3 ms 20824 KB Output is correct
10 Correct 3 ms 20824 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 90 ms 47440 KB Output is correct
13 Correct 3 ms 20824 KB Output is correct
14 Correct 3 ms 20824 KB Output is correct
15 Correct 3 ms 20828 KB Output is correct
16 Correct 3 ms 20828 KB Output is correct
17 Correct 94 ms 44488 KB Output is correct
18 Correct 4 ms 20828 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Correct 3 ms 20828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 31960 KB Output is correct
2 Correct 9 ms 24536 KB Output is correct
3 Correct 9 ms 24512 KB Output is correct
4 Correct 34 ms 33228 KB Output is correct
5 Correct 16 ms 29600 KB Output is correct
6 Correct 25 ms 34256 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 34 ms 32208 KB Output is correct
9 Correct 18 ms 30164 KB Output is correct
10 Correct 34 ms 34612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 3 ms 20828 KB Output is correct
3 Correct 3 ms 20828 KB Output is correct
4 Correct 3 ms 20824 KB Output is correct
5 Correct 3 ms 20828 KB Output is correct
6 Correct 3 ms 20828 KB Output is correct
7 Correct 3 ms 20936 KB Output is correct
8 Correct 3 ms 20824 KB Output is correct
9 Correct 3 ms 20828 KB Output is correct
10 Correct 3 ms 20828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 31960 KB Output is correct
2 Correct 9 ms 24536 KB Output is correct
3 Correct 9 ms 24512 KB Output is correct
4 Correct 34 ms 33228 KB Output is correct
5 Correct 16 ms 29600 KB Output is correct
6 Correct 25 ms 34256 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 34 ms 32208 KB Output is correct
9 Correct 18 ms 30164 KB Output is correct
10 Correct 34 ms 34612 KB Output is correct
11 Correct 3 ms 20828 KB Output is correct
12 Correct 3 ms 20828 KB Output is correct
13 Correct 3 ms 20828 KB Output is correct
14 Correct 3 ms 20824 KB Output is correct
15 Correct 3 ms 20828 KB Output is correct
16 Correct 3 ms 20828 KB Output is correct
17 Correct 3 ms 20936 KB Output is correct
18 Correct 3 ms 20824 KB Output is correct
19 Correct 3 ms 20828 KB Output is correct
20 Correct 3 ms 20828 KB Output is correct
21 Correct 87 ms 47812 KB Output is correct
22 Correct 15 ms 24028 KB Output is correct
23 Correct 11 ms 25604 KB Output is correct
24 Correct 35 ms 33616 KB Output is correct
25 Correct 90 ms 48320 KB Output is correct
26 Correct 32 ms 30928 KB Output is correct
27 Correct 18 ms 23768 KB Output is correct
28 Correct 90 ms 48840 KB Output is correct
29 Correct 88 ms 47864 KB Output is correct
30 Correct 27 ms 30032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 20828 KB Output is correct
2 Correct 3 ms 20828 KB Output is correct
3 Correct 3 ms 20828 KB Output is correct
4 Correct 3 ms 20928 KB Output is correct
5 Correct 3 ms 20828 KB Output is correct
6 Correct 3 ms 20824 KB Output is correct
7 Correct 4 ms 20924 KB Output is correct
8 Correct 3 ms 20828 KB Output is correct
9 Correct 3 ms 20824 KB Output is correct
10 Correct 3 ms 20824 KB Output is correct
11 Correct 4 ms 20828 KB Output is correct
12 Correct 90 ms 47440 KB Output is correct
13 Correct 3 ms 20824 KB Output is correct
14 Correct 3 ms 20824 KB Output is correct
15 Correct 3 ms 20828 KB Output is correct
16 Correct 3 ms 20828 KB Output is correct
17 Correct 94 ms 44488 KB Output is correct
18 Correct 4 ms 20828 KB Output is correct
19 Correct 4 ms 20828 KB Output is correct
20 Correct 3 ms 20828 KB Output is correct
21 Correct 31 ms 31960 KB Output is correct
22 Correct 9 ms 24536 KB Output is correct
23 Correct 9 ms 24512 KB Output is correct
24 Correct 34 ms 33228 KB Output is correct
25 Correct 16 ms 29600 KB Output is correct
26 Correct 25 ms 34256 KB Output is correct
27 Correct 4 ms 21084 KB Output is correct
28 Correct 34 ms 32208 KB Output is correct
29 Correct 18 ms 30164 KB Output is correct
30 Correct 34 ms 34612 KB Output is correct
31 Correct 3 ms 20828 KB Output is correct
32 Correct 3 ms 20828 KB Output is correct
33 Correct 3 ms 20828 KB Output is correct
34 Correct 3 ms 20824 KB Output is correct
35 Correct 3 ms 20828 KB Output is correct
36 Correct 3 ms 20828 KB Output is correct
37 Correct 3 ms 20936 KB Output is correct
38 Correct 3 ms 20824 KB Output is correct
39 Correct 3 ms 20828 KB Output is correct
40 Correct 3 ms 20828 KB Output is correct
41 Correct 87 ms 47812 KB Output is correct
42 Correct 15 ms 24028 KB Output is correct
43 Correct 11 ms 25604 KB Output is correct
44 Correct 35 ms 33616 KB Output is correct
45 Correct 90 ms 48320 KB Output is correct
46 Correct 32 ms 30928 KB Output is correct
47 Correct 18 ms 23768 KB Output is correct
48 Correct 90 ms 48840 KB Output is correct
49 Correct 88 ms 47864 KB Output is correct
50 Correct 27 ms 30032 KB Output is correct
51 Correct 16 ms 26128 KB Output is correct
52 Correct 98 ms 49600 KB Output is correct
53 Correct 93 ms 48580 KB Output is correct
54 Correct 23 ms 26580 KB Output is correct
55 Correct 46 ms 33468 KB Output is correct
56 Correct 31 ms 34248 KB Output is correct
57 Correct 35 ms 31704 KB Output is correct
58 Correct 95 ms 49344 KB Output is correct
59 Correct 29 ms 26824 KB Output is correct
60 Correct 32 ms 28616 KB Output is correct