답안 #1007865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1007865 2024-06-25T15:41:31 Z christinelynn Lasers (NOI19_lasers) C++17
100 / 100
205 ms 44100 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define pii pair<ll,ll>
#define fi first
#define sec second
#define endl '\n'
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset tree<ll, null_type,  less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> 

const ll MOD = 998244353;
const ll N = 5e5 + 5;
const ll INF = 1e18;

vector<ll>vec[N];

int32_t main(){
  cin.tie(0)->sync_with_stdio(0);
  int tc = 1;
  // cin >> tc;
  while(tc--){
    ll n,q; cin >> n >> q;
    for(int i=1;i<=q;i++){
      ll a; cin >> a;
      for(int j=1;j<=a;j++){
        ll x; cin >> x;
        vec[i].pb(x);
      }
    }
    set<pii>interval;
    for(int i=1;i<=q;i++){
      ll l = 1;
      vector<ll>suff(vec[i].size() + 5);
      for(int j=vec[i].size();j>=0;j--){
        if(j == vec[i].size()-1) suff[j] = vec[i][j];
        else suff[j] = suff[j+1] + vec[i][j];
      }
      for(int j=0;j<vec[i].size();j++){
        ll val = max(0LL, 2*vec[i][j] - (n-(j == vec[i].size()-1 ? 0 : suff[j+1])-l+1));
        if(val > 0) interval.insert({l-val+vec[i][j], l+vec[i][j]-1});
        l += vec[i][j];
      }
    }
    if(interval.size() == 0){
      cout << 0 << endl;
      continue;
    }
    ll last = -1, prev = -1, mx = 0, ans = 0;
    for(auto i : interval){
      if(prev == -1) prev = i.fi;
      if(i.fi != prev){
        ans += max(0LL, last - max(prev - 1,mx));
        mx = max(mx, last);
        prev = i.fi;
        last = 0;
      }
      last = i.sec;
    }
    ans += max(0LL, last - max(prev - 1,mx));
    cout << ans << endl;
  }
}
/*
1 2 3 4 5 6 7 8 9 10 11
*/

Compilation message

lasers.cpp: In function 'int32_t main()':
lasers.cpp:39:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |         if(j == vec[i].size()-1) suff[j] = vec[i][j];
      |            ~~^~~~~~~~~~~~~~~~~~
lasers.cpp:42:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |       for(int j=0;j<vec[i].size();j++){
      |                   ~^~~~~~~~~~~~~~
lasers.cpp:43:47: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |         ll val = max(0LL, 2*vec[i][j] - (n-(j == vec[i].size()-1 ? 0 : suff[j+1])-l+1));
      |                                             ~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 2 ms 12124 KB Output is correct
3 Correct 3 ms 12168 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12120 KB Output is correct
9 Correct 2 ms 12124 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 2 ms 12124 KB Output is correct
3 Correct 3 ms 12168 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12120 KB Output is correct
9 Correct 2 ms 12124 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
11 Correct 3 ms 12252 KB Output is correct
12 Correct 75 ms 27292 KB Output is correct
13 Correct 3 ms 12120 KB Output is correct
14 Correct 2 ms 12124 KB Output is correct
15 Correct 3 ms 12124 KB Output is correct
16 Correct 3 ms 12124 KB Output is correct
17 Correct 186 ms 40684 KB Output is correct
18 Correct 2 ms 12124 KB Output is correct
19 Correct 2 ms 12124 KB Output is correct
20 Correct 2 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 26408 KB Output is correct
2 Correct 11 ms 14640 KB Output is correct
3 Correct 10 ms 14024 KB Output is correct
4 Correct 44 ms 28016 KB Output is correct
5 Correct 21 ms 18380 KB Output is correct
6 Correct 25 ms 19844 KB Output is correct
7 Correct 4 ms 12380 KB Output is correct
8 Correct 32 ms 24836 KB Output is correct
9 Correct 30 ms 22740 KB Output is correct
10 Correct 49 ms 30196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12124 KB Output is correct
2 Correct 2 ms 12124 KB Output is correct
3 Correct 3 ms 12124 KB Output is correct
4 Correct 3 ms 12124 KB Output is correct
5 Correct 2 ms 12164 KB Output is correct
6 Correct 3 ms 12124 KB Output is correct
7 Correct 2 ms 12260 KB Output is correct
8 Correct 3 ms 12124 KB Output is correct
9 Correct 2 ms 12124 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 26408 KB Output is correct
2 Correct 11 ms 14640 KB Output is correct
3 Correct 10 ms 14024 KB Output is correct
4 Correct 44 ms 28016 KB Output is correct
5 Correct 21 ms 18380 KB Output is correct
6 Correct 25 ms 19844 KB Output is correct
7 Correct 4 ms 12380 KB Output is correct
8 Correct 32 ms 24836 KB Output is correct
9 Correct 30 ms 22740 KB Output is correct
10 Correct 49 ms 30196 KB Output is correct
11 Correct 3 ms 12124 KB Output is correct
12 Correct 2 ms 12124 KB Output is correct
13 Correct 3 ms 12124 KB Output is correct
14 Correct 3 ms 12124 KB Output is correct
15 Correct 2 ms 12164 KB Output is correct
16 Correct 3 ms 12124 KB Output is correct
17 Correct 2 ms 12260 KB Output is correct
18 Correct 3 ms 12124 KB Output is correct
19 Correct 2 ms 12124 KB Output is correct
20 Correct 2 ms 12124 KB Output is correct
21 Correct 155 ms 40776 KB Output is correct
22 Correct 26 ms 17712 KB Output is correct
23 Correct 14 ms 16000 KB Output is correct
24 Correct 52 ms 27688 KB Output is correct
25 Correct 172 ms 40532 KB Output is correct
26 Correct 61 ms 23756 KB Output is correct
27 Correct 24 ms 16724 KB Output is correct
28 Correct 163 ms 40772 KB Output is correct
29 Correct 205 ms 40596 KB Output is correct
30 Correct 33 ms 23020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 12120 KB Output is correct
2 Correct 2 ms 12124 KB Output is correct
3 Correct 3 ms 12168 KB Output is correct
4 Correct 2 ms 12124 KB Output is correct
5 Correct 2 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 3 ms 12124 KB Output is correct
8 Correct 3 ms 12120 KB Output is correct
9 Correct 2 ms 12124 KB Output is correct
10 Correct 2 ms 12124 KB Output is correct
11 Correct 3 ms 12252 KB Output is correct
12 Correct 75 ms 27292 KB Output is correct
13 Correct 3 ms 12120 KB Output is correct
14 Correct 2 ms 12124 KB Output is correct
15 Correct 3 ms 12124 KB Output is correct
16 Correct 3 ms 12124 KB Output is correct
17 Correct 186 ms 40684 KB Output is correct
18 Correct 2 ms 12124 KB Output is correct
19 Correct 2 ms 12124 KB Output is correct
20 Correct 2 ms 12124 KB Output is correct
21 Correct 40 ms 26408 KB Output is correct
22 Correct 11 ms 14640 KB Output is correct
23 Correct 10 ms 14024 KB Output is correct
24 Correct 44 ms 28016 KB Output is correct
25 Correct 21 ms 18380 KB Output is correct
26 Correct 25 ms 19844 KB Output is correct
27 Correct 4 ms 12380 KB Output is correct
28 Correct 32 ms 24836 KB Output is correct
29 Correct 30 ms 22740 KB Output is correct
30 Correct 49 ms 30196 KB Output is correct
31 Correct 3 ms 12124 KB Output is correct
32 Correct 2 ms 12124 KB Output is correct
33 Correct 3 ms 12124 KB Output is correct
34 Correct 3 ms 12124 KB Output is correct
35 Correct 2 ms 12164 KB Output is correct
36 Correct 3 ms 12124 KB Output is correct
37 Correct 2 ms 12260 KB Output is correct
38 Correct 3 ms 12124 KB Output is correct
39 Correct 2 ms 12124 KB Output is correct
40 Correct 2 ms 12124 KB Output is correct
41 Correct 155 ms 40776 KB Output is correct
42 Correct 26 ms 17712 KB Output is correct
43 Correct 14 ms 16000 KB Output is correct
44 Correct 52 ms 27688 KB Output is correct
45 Correct 172 ms 40532 KB Output is correct
46 Correct 61 ms 23756 KB Output is correct
47 Correct 24 ms 16724 KB Output is correct
48 Correct 163 ms 40772 KB Output is correct
49 Correct 205 ms 40596 KB Output is correct
50 Correct 33 ms 23020 KB Output is correct
51 Correct 20 ms 17384 KB Output is correct
52 Correct 178 ms 43192 KB Output is correct
53 Correct 184 ms 44100 KB Output is correct
54 Correct 39 ms 19608 KB Output is correct
55 Correct 94 ms 30384 KB Output is correct
56 Correct 72 ms 25392 KB Output is correct
57 Correct 64 ms 25168 KB Output is correct
58 Correct 180 ms 43172 KB Output is correct
59 Correct 48 ms 21848 KB Output is correct
60 Correct 60 ms 24096 KB Output is correct