Submission #645468

# Submission time Handle Problem Language Result Execution time Memory
645468 2022-09-27T08:06:42 Z kith14 Lasers (NOI19_lasers) C++14
100 / 100
395 ms 31624 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define x first
#define y second
#define mp make_pair
#define pb push_back

const ll N = 5e5+5, MOD = 1e9+7;
ll tc = 1, n, m, ar[N], br[N];
ll k, len;
string s, s1, s2, ye = "YA", no = "TIDAK";
map<ll,ll> mapz;
vector<ll> v;
vector<pairll> cmp;

void input(){
  cin >> len >> n;
  repp(j,1,n){
    //cout << "i = " << j << endl;
    cin >> k;
    v.clear();
    cmp.clear();
    ll rig = 0, lef = 0;
    while(k--){
      cin >> m;
      v.pb(m);
      rig += m;
    }
    for (auto i : v){
      cmp.pb(mp(lef+1,len-rig));
      rig -= i;
      lef += i;
    }
    cmp.pb(mp(lef+1,len));
    ll l = cmp[0].fr, r = cmp[0].sc;   
    for (auto i : cmp){
      //cout << i.fr << " " << i.sc << endl;
      if (i.fr > r){
        mapz[l]++;
        mapz[r+1]--;
        //cout << l << " " << r << endl;
        l = i.fr;
        r = i.sc;
      }
      else r = max(r,i.sc);
    }
    mapz[l]++;
    mapz[r+1]--;
    //cout << l << " " << r << endl;
  }
}

void solve(){
  ll ans = 0, cur = 0, pre = -1;
  for (auto it = mapz.begin(); it != mapz.end(); ++it){
    ll key = it -> first, val = it->second;
    cur += val;
    //cout << "mapz = " << key << " " << cur << endl;
    if (cur < n && pre != -1){
      ans += key-pre;
      //cout << key << " " << pre << endl;
      pre = -1;
    }
    else if (pre == -1 && cur == n) pre = key;
  }
  cout << len-ans << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 76 ms 304 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 323 ms 26360 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 25252 KB Output is correct
2 Correct 16 ms 5028 KB Output is correct
3 Correct 11 ms 3412 KB Output is correct
4 Correct 102 ms 28212 KB Output is correct
5 Correct 38 ms 11936 KB Output is correct
6 Correct 65 ms 14692 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 65 ms 17604 KB Output is correct
9 Correct 71 ms 19400 KB Output is correct
10 Correct 126 ms 31624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 107 ms 25252 KB Output is correct
2 Correct 16 ms 5028 KB Output is correct
3 Correct 11 ms 3412 KB Output is correct
4 Correct 102 ms 28212 KB Output is correct
5 Correct 38 ms 11936 KB Output is correct
6 Correct 65 ms 14692 KB Output is correct
7 Correct 2 ms 724 KB Output is correct
8 Correct 65 ms 17604 KB Output is correct
9 Correct 71 ms 19400 KB Output is correct
10 Correct 126 ms 31624 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 354 ms 23904 KB Output is correct
22 Correct 51 ms 7680 KB Output is correct
23 Correct 23 ms 6856 KB Output is correct
24 Correct 100 ms 22064 KB Output is correct
25 Correct 329 ms 23812 KB Output is correct
26 Correct 118 ms 14796 KB Output is correct
27 Correct 37 ms 6480 KB Output is correct
28 Correct 328 ms 23816 KB Output is correct
29 Correct 357 ms 24036 KB Output is correct
30 Correct 73 ms 15760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 76 ms 304 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 323 ms 26360 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 107 ms 25252 KB Output is correct
22 Correct 16 ms 5028 KB Output is correct
23 Correct 11 ms 3412 KB Output is correct
24 Correct 102 ms 28212 KB Output is correct
25 Correct 38 ms 11936 KB Output is correct
26 Correct 65 ms 14692 KB Output is correct
27 Correct 2 ms 724 KB Output is correct
28 Correct 65 ms 17604 KB Output is correct
29 Correct 71 ms 19400 KB Output is correct
30 Correct 126 ms 31624 KB Output is correct
31 Correct 0 ms 340 KB Output is correct
32 Correct 0 ms 212 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 0 ms 340 KB Output is correct
35 Correct 0 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 0 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 354 ms 23904 KB Output is correct
42 Correct 51 ms 7680 KB Output is correct
43 Correct 23 ms 6856 KB Output is correct
44 Correct 100 ms 22064 KB Output is correct
45 Correct 329 ms 23812 KB Output is correct
46 Correct 118 ms 14796 KB Output is correct
47 Correct 37 ms 6480 KB Output is correct
48 Correct 328 ms 23816 KB Output is correct
49 Correct 357 ms 24036 KB Output is correct
50 Correct 73 ms 15760 KB Output is correct
51 Correct 35 ms 9032 KB Output is correct
52 Correct 379 ms 30004 KB Output is correct
53 Correct 365 ms 29840 KB Output is correct
54 Correct 71 ms 10248 KB Output is correct
55 Correct 218 ms 24680 KB Output is correct
56 Correct 102 ms 22064 KB Output is correct
57 Correct 142 ms 18276 KB Output is correct
58 Correct 395 ms 31208 KB Output is correct
59 Correct 119 ms 13952 KB Output is correct
60 Correct 136 ms 16372 KB Output is correct