Submission #736193

# Submission time Handle Problem Language Result Execution time Memory
736193 2023-05-05T09:56:53 Z onebit1024 Lasers (NOI19_lasers) C++17
100 / 100
173 ms 16500 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back
#define all(c) c.begin(), c.end()
#define endl "\n"

const double PI=3.141592653589;


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define dbg(x...) cerr << "LINE(" << __LINE__ << ") -> " <<"[" << #x << "] = ["; _print(x)
#else
#define dbg(x...)
#endif



void solve()
{
    int L,n;
    cin >> L >> n;
    vector<pair<int,int>>tot;
    for(int i = 1;i<=n;++i){
        int x;
        cin >> x;
        vector<int>a(x+1);
        int sum = 0;
        for(int j= 1;j<=x;++j)cin >> a[j],sum+=a[j];
        int space = L-sum;
        sum = 0;
        int curr = 1;
        vector<pair<int,int>>range;
        for(int j = 1;j<=x;++j){
            if(space)range.pb({curr,curr+space-1});
            sum+=a[j];
            curr = sum+1;
        }
        if(space)range.pb({curr,L});
        vector<pair<int,int>>not_safe;
        for(int j = 1;j<(int)(range.size());++j){
            if(range[j].first > range[j-1].second+1)not_safe.pb({range[j-1].second+1,range[j].first-1});
        }
        if(!space)not_safe.pb({1,L});
        for(auto x : not_safe)tot.pb(x);
    }
    sort(all(tot));
    int res = 0;
    int r = 1;
    if(!tot.empty())r = tot[0].second, res+= (tot[0].second-tot[0].first+1);
    for(int j = 1;j<(int)(tot.size());++j){
        if(tot[j].second > r){
            res+=tot[j].second-max(r+1,tot[j].first)+1;
        }
        r = max(r, tot[j].second);
    }
    cout << res << endl;
}   

int32_t main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    

    int T=1;
    for(int i = 1;i<=T;++i)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 129 ms 14020 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 156 ms 9408 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 12936 KB Output is correct
2 Correct 10 ms 3152 KB Output is correct
3 Correct 9 ms 2440 KB Output is correct
4 Correct 45 ms 14396 KB Output is correct
5 Correct 19 ms 7680 KB Output is correct
6 Correct 40 ms 12048 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 41 ms 16500 KB Output is correct
9 Correct 25 ms 8136 KB Output is correct
10 Correct 43 ms 15260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 324 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 12936 KB Output is correct
2 Correct 10 ms 3152 KB Output is correct
3 Correct 9 ms 2440 KB Output is correct
4 Correct 45 ms 14396 KB Output is correct
5 Correct 19 ms 7680 KB Output is correct
6 Correct 40 ms 12048 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 41 ms 16500 KB Output is correct
9 Correct 25 ms 8136 KB Output is correct
10 Correct 43 ms 15260 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 324 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 148 ms 8544 KB Output is correct
22 Correct 21 ms 2000 KB Output is correct
23 Correct 12 ms 3056 KB Output is correct
24 Correct 46 ms 11020 KB Output is correct
25 Correct 138 ms 8520 KB Output is correct
26 Correct 36 ms 5764 KB Output is correct
27 Correct 14 ms 1916 KB Output is correct
28 Correct 139 ms 8592 KB Output is correct
29 Correct 135 ms 8596 KB Output is correct
30 Correct 36 ms 6084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 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 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 129 ms 14020 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 156 ms 9408 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 38 ms 12936 KB Output is correct
22 Correct 10 ms 3152 KB Output is correct
23 Correct 9 ms 2440 KB Output is correct
24 Correct 45 ms 14396 KB Output is correct
25 Correct 19 ms 7680 KB Output is correct
26 Correct 40 ms 12048 KB Output is correct
27 Correct 1 ms 596 KB Output is correct
28 Correct 41 ms 16500 KB Output is correct
29 Correct 25 ms 8136 KB Output is correct
30 Correct 43 ms 15260 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 212 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 212 KB Output is correct
35 Correct 0 ms 324 KB Output is correct
36 Correct 0 ms 320 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 340 KB Output is correct
41 Correct 148 ms 8544 KB Output is correct
42 Correct 21 ms 2000 KB Output is correct
43 Correct 12 ms 3056 KB Output is correct
44 Correct 46 ms 11020 KB Output is correct
45 Correct 138 ms 8520 KB Output is correct
46 Correct 36 ms 5764 KB Output is correct
47 Correct 14 ms 1916 KB Output is correct
48 Correct 139 ms 8592 KB Output is correct
49 Correct 135 ms 8596 KB Output is correct
50 Correct 36 ms 6084 KB Output is correct
51 Correct 16 ms 3180 KB Output is correct
52 Correct 143 ms 9784 KB Output is correct
53 Correct 166 ms 9636 KB Output is correct
54 Correct 28 ms 3804 KB Output is correct
55 Correct 64 ms 7016 KB Output is correct
56 Correct 43 ms 8864 KB Output is correct
57 Correct 47 ms 6500 KB Output is correct
58 Correct 173 ms 9872 KB Output is correct
59 Correct 34 ms 3520 KB Output is correct
60 Correct 41 ms 4648 KB Output is correct