Submission #1040962

# Submission time Handle Problem Language Result Execution time Memory
1040962 2024-08-01T12:51:22 Z 7again Lasers (NOI19_lasers) C++17
100 / 100
178 ms 13772 KB
#include <bits/stdc++.h>
#define int long long
#define double long double
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define FAST ios::sync_with_stdio(0);cout.tie(0);cin.tie(0)
//#define endl "\n"
#define f first
#define s second
#define pb push_back
#define in insert

//#define ind(v,t) distance(v.begin(),t)
using namespace std ;

int MOD = 1e18 ;
const int N = 500005 ;

//int fib(int n){double phi=(1+sqrt(5))/2;return round((pow(phi,n)-pow(1-phi,n))/sqrt(5));}
//void setIO(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
int fstpow(int a, int b){if(b==0)return 1;int ans=fstpow(a,b/2)%MOD;ans=ans%MOD*ans%MOD;if(b&1)return a*ans%MOD;return ans%MOD;}
int inv(int x){return fstpow(x,MOD-2);}
int DMOD(int x,int y){x%=MOD;y%=MOD;return fstpow(x,inv(y));}
int MMOD(int x,int y){x%=MOD;y%=MOD;return (x*y)%MOD;}
//int AMOD(int x,int y){x%=MOD;y%=MOD;return (x+y)%MOD;}
int SMOD(int x,int y){x%=MOD;y%=MOD;return (x-y+MOD)%MOD;}
//int Factorial[N];void FAC(){Factorial[0]=1;for(int i=1;i<=2e6;i++)Factorial[i]=(Factorial[i-1]%MOD*i%MOD)%MOD;}
//int PREFIX[3e6];void PFX(){PREFIX[0]=0;for(int i=1;i<=2e6;i++)PREFIX[i]=PREFIX[i]+PREFIX[i-1]+i;}
//fill_n(&a[0][0],(n+1)*(m+1),valu);
//int C(int x,int y){int A=1,B=1;for(int i=y+1;i<=x;i++)A*=i;for(int i=2;i<=x-y;i++)B*=i;return A/B;}

pair <int , int> pfx[N] ;
void slv()
{
    int n , m ;
    cin >> n >> m ;

    int p = 0 ;
    for(int t = 0 ; t < m ; t++)
    {
        int s ;
        cin >> s ;

        vector <int> v(s) ;
        double sum = 0 , sum2 = 0 ;
        for(int i = 0 ; i < s ; i++)
        {
            cin >> v[i] ;
            sum += v[i] ;
        }

        for(int i = 0 ; i < s ; i++)
        {
            int l = n - (sum - sum2) + 1 , r = sum2 + v[i] + 1 ;
            if(r > l)
                pfx[++p] = {l , r - 1} ;
            sum2 += v[i] ;
        }
    }

    sort(pfx + 1 , pfx + p + 1) ;
    int ans = 0;
    int l = 0 , r = -1 ;
    for(int i = 1 ; i <= p ; i++)
    {
        if(pfx[i].f > r)
        {
            ans += r - l + 1 ;
            l = pfx[i].f ;
            r = pfx[i].s ;
        }

        else
        {
            r = max(r , pfx[i].s) ;
        }
    }
    ans += r - l + 1 ;
    cout << ans ;
}
main()
{

    //FAST ;

    int t = 1 ;
    //cin >> t ;

    while(t--)
        slv() ;
}

//TLE Problem ?
/*
    -> const MOD
    -> const int
    -> FAST
    -> "/n" | endl
    -> array size
*/

//MLE Problem ?
/*
    -> array size()
    -> N ?
    -> long long
    -> define
    -> long long dp[1000][100000] ? ;
*/

//RTE problem ?
/*
    -> array size ?
    -> x / 0 ?
*/

Compilation message

lasers.cpp:81:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   81 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 145 ms 13772 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 160 ms 10308 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 5744 KB Output is correct
2 Correct 8 ms 3164 KB Output is correct
3 Correct 9 ms 2756 KB Output is correct
4 Correct 35 ms 5988 KB Output is correct
5 Correct 16 ms 3672 KB Output is correct
6 Correct 41 ms 3080 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 38 ms 4544 KB Output is correct
9 Correct 18 ms 3416 KB Output is correct
10 Correct 38 ms 6104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 360 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 5744 KB Output is correct
2 Correct 8 ms 3164 KB Output is correct
3 Correct 9 ms 2756 KB Output is correct
4 Correct 35 ms 5988 KB Output is correct
5 Correct 16 ms 3672 KB Output is correct
6 Correct 41 ms 3080 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 38 ms 4544 KB Output is correct
9 Correct 18 ms 3416 KB Output is correct
10 Correct 38 ms 6104 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 360 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 135 ms 4692 KB Output is correct
22 Correct 20 ms 2652 KB Output is correct
23 Correct 13 ms 2908 KB Output is correct
24 Correct 46 ms 5212 KB Output is correct
25 Correct 130 ms 4696 KB Output is correct
26 Correct 39 ms 2652 KB Output is correct
27 Correct 16 ms 2652 KB Output is correct
28 Correct 141 ms 4448 KB Output is correct
29 Correct 132 ms 4688 KB Output is correct
30 Correct 45 ms 3468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 145 ms 13772 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 160 ms 10308 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 35 ms 5744 KB Output is correct
22 Correct 8 ms 3164 KB Output is correct
23 Correct 9 ms 2756 KB Output is correct
24 Correct 35 ms 5988 KB Output is correct
25 Correct 16 ms 3672 KB Output is correct
26 Correct 41 ms 3080 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 38 ms 4544 KB Output is correct
29 Correct 18 ms 3416 KB Output is correct
30 Correct 38 ms 6104 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 360 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 1 ms 600 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 135 ms 4692 KB Output is correct
42 Correct 20 ms 2652 KB Output is correct
43 Correct 13 ms 2908 KB Output is correct
44 Correct 46 ms 5212 KB Output is correct
45 Correct 130 ms 4696 KB Output is correct
46 Correct 39 ms 2652 KB Output is correct
47 Correct 16 ms 2652 KB Output is correct
48 Correct 141 ms 4448 KB Output is correct
49 Correct 132 ms 4688 KB Output is correct
50 Correct 45 ms 3468 KB Output is correct
51 Correct 19 ms 3492 KB Output is correct
52 Correct 153 ms 10328 KB Output is correct
53 Correct 178 ms 10064 KB Output is correct
54 Correct 42 ms 3924 KB Output is correct
55 Correct 83 ms 7800 KB Output is correct
56 Correct 45 ms 6584 KB Output is correct
57 Correct 54 ms 6740 KB Output is correct
58 Correct 155 ms 10312 KB Output is correct
59 Correct 37 ms 3928 KB Output is correct
60 Correct 57 ms 4692 KB Output is correct