Submission #224521

# Submission time Handle Problem Language Result Execution time Memory
224521 2020-04-18T09:51:56 Z kshitij_sodani Lasers (NOI19_lasers) C++17
100 / 100
189 ms 35308 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define a first
#define b second
#define pb push_back
typedef long long int llo;
llo mod=1000000007;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int l,r;
	cin>>l>>r;
	int x;
	vector<int> aa[r];
	int y;
	for(int i=0;i<r;i++){
		cin>>x;
		for(int j=0;j<x;j++){
			cin>>y;
			aa[i].pb(y);
		}
	}
	vector<pair<int,int>> ran;
	for(int i=0;i<r;i++){
		if(aa[i].size()==0){
			continue;
		}
		int pre[aa[i].size()];
		int ss[aa[i].size()];
		pre[0]=aa[i][0];
		for(int j=1;j<aa[i].size();j++){
			pre[j]=pre[j-1]+aa[i][j];
		}
		ss[aa[i].size()-1]=aa[i][aa[i].size()-1];
		for(int j=aa[i].size()-2;j>=0;j--){
			ss[j]=ss[j+1]+aa[i][j];
		}
		for(int j=0;j<aa[i].size();j++){
			int st=0;
			int e=aa[i][0]-1;
			if(j>0){
				st=pre[j-1];
				e=st+aa[i][j]-1;
			}
			int st2=l-ss[j];
			int e2=st2+aa[i][j]-1;
			if(e>=st2){
				ran.pb({st2,e});

			}
		}
	}
	sort(ran.begin(),ran.end());
	int ans=0;
	int mi=-1;
	int ma=-1;
	for(auto nn:ran){
	//	cout<<nn.a<<" "<<nn.b<<endl;
		if(nn.a>ma){
			if(ma!=-1){
				ans+=ma-mi+1;
			}
			mi=nn.a;
			ma=nn.b;
			
		}
		else{
			ma=max(ma,nn.b);
		}
	}
	if(ma!=-1){
		ans+=ma-mi+1;
	}	
	cout<<ans<<endl;
	return 0;
}

Compilation message

lasers.cpp: In function 'int main()':
lasers.cpp:32:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=1;j<aa[i].size();j++){
               ~^~~~~~~~~~~~~
lasers.cpp:39:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j=0;j<aa[i].size();j++){
               ~^~~~~~~~~~~~~
lasers.cpp:47:8: warning: unused variable 'e2' [-Wunused-variable]
    int e2=st2+aa[i][j]-1;
        ^~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 177 ms 35308 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 189 ms 33532 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5624 KB Output is correct
2 Correct 12 ms 1696 KB Output is correct
3 Correct 13 ms 1532 KB Output is correct
4 Correct 49 ms 5744 KB Output is correct
5 Correct 24 ms 3828 KB Output is correct
6 Correct 36 ms 6260 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 42 ms 6132 KB Output is correct
9 Correct 26 ms 4728 KB Output is correct
10 Correct 49 ms 6128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 5624 KB Output is correct
2 Correct 12 ms 1696 KB Output is correct
3 Correct 13 ms 1532 KB Output is correct
4 Correct 49 ms 5744 KB Output is correct
5 Correct 24 ms 3828 KB Output is correct
6 Correct 36 ms 6260 KB Output is correct
7 Correct 5 ms 512 KB Output is correct
8 Correct 42 ms 6132 KB Output is correct
9 Correct 26 ms 4728 KB Output is correct
10 Correct 49 ms 6128 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 176 ms 33388 KB Output is correct
22 Correct 23 ms 2300 KB Output is correct
23 Correct 15 ms 1916 KB Output is correct
24 Correct 55 ms 6892 KB Output is correct
25 Correct 170 ms 33388 KB Output is correct
26 Correct 45 ms 5364 KB Output is correct
27 Correct 20 ms 2172 KB Output is correct
28 Correct 175 ms 33440 KB Output is correct
29 Correct 176 ms 33516 KB Output is correct
30 Correct 37 ms 4716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 177 ms 35308 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 189 ms 33532 KB Output is correct
18 Correct 5 ms 512 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 44 ms 5624 KB Output is correct
22 Correct 12 ms 1696 KB Output is correct
23 Correct 13 ms 1532 KB Output is correct
24 Correct 49 ms 5744 KB Output is correct
25 Correct 24 ms 3828 KB Output is correct
26 Correct 36 ms 6260 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 42 ms 6132 KB Output is correct
29 Correct 26 ms 4728 KB Output is correct
30 Correct 49 ms 6128 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 4 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 5 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 5 ms 384 KB Output is correct
39 Correct 5 ms 384 KB Output is correct
40 Correct 5 ms 384 KB Output is correct
41 Correct 176 ms 33388 KB Output is correct
42 Correct 23 ms 2300 KB Output is correct
43 Correct 15 ms 1916 KB Output is correct
44 Correct 55 ms 6892 KB Output is correct
45 Correct 170 ms 33388 KB Output is correct
46 Correct 45 ms 5364 KB Output is correct
47 Correct 20 ms 2172 KB Output is correct
48 Correct 175 ms 33440 KB Output is correct
49 Correct 176 ms 33516 KB Output is correct
50 Correct 37 ms 4716 KB Output is correct
51 Correct 21 ms 2424 KB Output is correct
52 Correct 180 ms 33204 KB Output is correct
53 Correct 181 ms 33264 KB Output is correct
54 Correct 36 ms 3956 KB Output is correct
55 Correct 83 ms 8428 KB Output is correct
56 Correct 47 ms 6512 KB Output is correct
57 Correct 57 ms 6252 KB Output is correct
58 Correct 178 ms 33516 KB Output is correct
59 Correct 41 ms 4216 KB Output is correct
60 Correct 55 ms 5616 KB Output is correct