Submission #1007943

# Submission time Handle Problem Language Result Execution time Memory
1007943 2024-06-26T01:35:11 Z andecaandeci Lasers (NOI19_lasers) C++17
100 / 100
133 ms 20308 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pp pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pll pair<ll,ll> 
#define pii pair<int,int> 
#define vl vector<ll> 
#define nikah ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const ll maxn = 5e5+7, modn1 = 1e9+7, modn2 = 998244353;
using namespace std;

// kalo kamu ngga emas nanti nadya merasa bersalah, ayo san demi nadya!!!
// Kalo emang soalnya susah, pindah soal dulu 
// Jangan sampe diem, pikirin sesuatu, pasti bisa!!!
// Cobain semua approach, jangan ngestuck di satu pemikiran
// Jangan overthinking, jangan panik, tenangin pikiranmu


ll t,n,q;
ll a[maxn], pref[maxn];
set<pll>s;

void solve () {
  cin>>n>>q;
  while (q--) {
    ll k; cin>>k;
    for (ll i=1; i<=k; i++) {
      cin>>a[i];
      pref[i] = a[i] + pref[i-1];
    }
    ll cnt = 0;
    for (ll i=k; i>=1; i--) {
      ll x = min(pref[i], n);
      ll y = max(n - cnt - a[i] + 1, (ll)1);
      if (x >= y) {
        s.insert({y,x});
      }
      cnt += a[i];
    }
  }
  ll ans = 0, x = 0, y = 0, prey = 0;
  for (auto p : s) {
    x = p.fi; y = p.se;
    if (y <= prey) continue;
    if (prey == 0) {
      ans += (y-x+1);
    } else{
      ans += (y - max(prey+1, x) + 1);
    }
    prey = y;
  }
  cout<<ans<<endl;
}           


int main () {
  nikah
  t = 1;
//  cin>>t;
  while (t--) {
    solve();
  //  cout<<endl;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2508 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2508 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 42 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 125 ms 15384 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 17376 KB Output is correct
2 Correct 8 ms 8584 KB Output is correct
3 Correct 6 ms 7516 KB Output is correct
4 Correct 39 ms 18448 KB Output is correct
5 Correct 14 ms 10840 KB Output is correct
6 Correct 19 ms 10076 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 23 ms 10376 KB Output is correct
9 Correct 29 ms 15256 KB Output is correct
10 Correct 53 ms 20308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2392 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 17376 KB Output is correct
2 Correct 8 ms 8584 KB Output is correct
3 Correct 6 ms 7516 KB Output is correct
4 Correct 39 ms 18448 KB Output is correct
5 Correct 14 ms 10840 KB Output is correct
6 Correct 19 ms 10076 KB Output is correct
7 Correct 1 ms 2652 KB Output is correct
8 Correct 23 ms 10376 KB Output is correct
9 Correct 29 ms 15256 KB Output is correct
10 Correct 53 ms 20308 KB Output is correct
11 Correct 1 ms 2392 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 1 ms 2392 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 132 ms 14276 KB Output is correct
22 Correct 22 ms 6492 KB Output is correct
23 Correct 11 ms 7772 KB Output is correct
24 Correct 47 ms 17716 KB Output is correct
25 Correct 125 ms 14076 KB Output is correct
26 Correct 54 ms 10648 KB Output is correct
27 Correct 19 ms 5724 KB Output is correct
28 Correct 117 ms 14160 KB Output is correct
29 Correct 116 ms 14164 KB Output is correct
30 Correct 26 ms 14160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2392 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2508 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2392 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 42 ms 2396 KB Output is correct
13 Correct 1 ms 2392 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 125 ms 15384 KB Output is correct
18 Correct 0 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 36 ms 17376 KB Output is correct
22 Correct 8 ms 8584 KB Output is correct
23 Correct 6 ms 7516 KB Output is correct
24 Correct 39 ms 18448 KB Output is correct
25 Correct 14 ms 10840 KB Output is correct
26 Correct 19 ms 10076 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 23 ms 10376 KB Output is correct
29 Correct 29 ms 15256 KB Output is correct
30 Correct 53 ms 20308 KB Output is correct
31 Correct 1 ms 2392 KB Output is correct
32 Correct 1 ms 2396 KB Output is correct
33 Correct 1 ms 2396 KB Output is correct
34 Correct 0 ms 2396 KB Output is correct
35 Correct 0 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2392 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 1 ms 2392 KB Output is correct
40 Correct 1 ms 2396 KB Output is correct
41 Correct 132 ms 14276 KB Output is correct
42 Correct 22 ms 6492 KB Output is correct
43 Correct 11 ms 7772 KB Output is correct
44 Correct 47 ms 17716 KB Output is correct
45 Correct 125 ms 14076 KB Output is correct
46 Correct 54 ms 10648 KB Output is correct
47 Correct 19 ms 5724 KB Output is correct
48 Correct 117 ms 14160 KB Output is correct
49 Correct 116 ms 14164 KB Output is correct
50 Correct 26 ms 14160 KB Output is correct
51 Correct 15 ms 8796 KB Output is correct
52 Correct 129 ms 17216 KB Output is correct
53 Correct 129 ms 17232 KB Output is correct
54 Correct 31 ms 7404 KB Output is correct
55 Correct 75 ms 14676 KB Output is correct
56 Correct 38 ms 16724 KB Output is correct
57 Correct 55 ms 11348 KB Output is correct
58 Correct 133 ms 18004 KB Output is correct
59 Correct 42 ms 9228 KB Output is correct
60 Correct 50 ms 10324 KB Output is correct