Submission #521615

# Submission time Handle Problem Language Result Execution time Memory
521615 2022-02-02T14:44:00 Z dsyz Lasers (NOI19_lasers) C++17
100 / 100
373 ms 68916 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define MAXN (1000005)
bool cmp(pair<ll,pair<ll,ll> > a,pair<ll,pair<ll,ll> > b){
	if(a.second.first == b.second.first){ //same row
		return a.second.second < b.second.second;
	}else{
		return a.first < b.first;
	}
}
int main() {
	ios_base::sync_with_stdio(false);cin.tie(0);
	ll L,R;
	cin>>L>>R;
	vector<ll> rows[R];
	ll maxlevel = 0;
	ll maximum = 0;
	ll prefix[R];
	ll suffix[R];
	memset(prefix,0,sizeof(prefix));
	memset(suffix,0,sizeof(suffix));
	for(ll i = 0;i < R;i++){
		ll X;
		cin>>X;
		maxlevel = max(maxlevel,X);
		ll cur = 0;
		for(ll j = 0;j < X;j++){
			ll a;
			cin>>a;
			cur += a;
			rows[i].push_back(a);
		}
		suffix[i] = L - cur;
		maximum = max(maximum,cur);
	}
	vector<pair<ll,pair<ll,ll> > > level; //level is the vertical thing, row is index
	for(ll i = 0;i < R;i++){
		ll total = 0;
		for(ll j = 0;j < rows[i].size();j++){
			total += rows[i][j];
			level.push_back(make_pair(total,make_pair(i,j)));
		}
	}
	sort(level.begin(),level.end(),cmp);
	priority_queue<pair<ll,ll>,vector<pair<ll,ll> >,greater<pair<ll,ll> > > pq;
	for(ll i = 0;i < R;i++){
		pq.push(make_pair(suffix[i],i));
	}
	ll sum = L;
	ll l = 0;
	ll r = L - maximum;
	ll prevr = 0;
	sum -= r - prevr;
	prevr = L - maximum;	
	for(ll i = 0;i < level.size();i++){
		prefix[level[i].second.first] += rows[level[i].second.first][level[i].second.second];
		l = max(l,prefix[level[i].second.first]);
		prevr = max(prevr,l);
		suffix[level[i].second.first] += rows[level[i].second.first][level[i].second.second];
		while(pq.size() != 0 && pq.top().first != suffix[pq.top().second]){
			ll a = suffix[pq.top().second];
			ll b = pq.top().second;
			pq.pop();
			pq.push(make_pair(a,b));
		}
		r = pq.top().first;
		sum -= max(0ll,r - prevr);
		prevr = max(prevr,r);
	}
	cout<<sum<<'\n';
}

Compilation message

lasers.cpp: In function 'int main()':
lasers.cpp:40:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |   for(ll j = 0;j < rows[i].size();j++){
      |                ~~^~~~~~~~~~~~~~~~
lasers.cpp:56:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |  for(ll i = 0;i < level.size();i++){
      |               ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 248 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 248 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 224 ms 67980 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 369 ms 68916 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 17196 KB Output is correct
2 Correct 17 ms 4420 KB Output is correct
3 Correct 23 ms 4708 KB Output is correct
4 Correct 89 ms 17184 KB Output is correct
5 Correct 48 ms 9488 KB Output is correct
6 Correct 98 ms 19712 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 144 ms 20248 KB Output is correct
9 Correct 39 ms 8964 KB Output is correct
10 Correct 99 ms 17464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 308 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 312 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 448 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 448 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 17196 KB Output is correct
2 Correct 17 ms 4420 KB Output is correct
3 Correct 23 ms 4708 KB Output is correct
4 Correct 89 ms 17184 KB Output is correct
5 Correct 48 ms 9488 KB Output is correct
6 Correct 98 ms 19712 KB Output is correct
7 Correct 1 ms 588 KB Output is correct
8 Correct 144 ms 20248 KB Output is correct
9 Correct 39 ms 8964 KB Output is correct
10 Correct 99 ms 17464 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 308 KB Output is correct
14 Correct 0 ms 332 KB Output is correct
15 Correct 0 ms 312 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 448 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 448 KB Output is correct
20 Correct 1 ms 316 KB Output is correct
21 Correct 369 ms 67124 KB Output is correct
22 Correct 32 ms 5568 KB Output is correct
23 Correct 22 ms 4668 KB Output is correct
24 Correct 113 ms 18640 KB Output is correct
25 Correct 355 ms 67128 KB Output is correct
26 Correct 71 ms 16972 KB Output is correct
27 Correct 27 ms 5268 KB Output is correct
28 Correct 367 ms 67076 KB Output is correct
29 Correct 354 ms 67160 KB Output is correct
30 Correct 84 ms 17276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 248 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 296 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 224 ms 67980 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 369 ms 68916 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 84 ms 17196 KB Output is correct
22 Correct 17 ms 4420 KB Output is correct
23 Correct 23 ms 4708 KB Output is correct
24 Correct 89 ms 17184 KB Output is correct
25 Correct 48 ms 9488 KB Output is correct
26 Correct 98 ms 19712 KB Output is correct
27 Correct 1 ms 588 KB Output is correct
28 Correct 144 ms 20248 KB Output is correct
29 Correct 39 ms 8964 KB Output is correct
30 Correct 99 ms 17464 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 204 KB Output is correct
33 Correct 0 ms 308 KB Output is correct
34 Correct 0 ms 332 KB Output is correct
35 Correct 0 ms 312 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 448 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 448 KB Output is correct
40 Correct 1 ms 316 KB Output is correct
41 Correct 369 ms 67124 KB Output is correct
42 Correct 32 ms 5568 KB Output is correct
43 Correct 22 ms 4668 KB Output is correct
44 Correct 113 ms 18640 KB Output is correct
45 Correct 355 ms 67128 KB Output is correct
46 Correct 71 ms 16972 KB Output is correct
47 Correct 27 ms 5268 KB Output is correct
48 Correct 367 ms 67076 KB Output is correct
49 Correct 354 ms 67160 KB Output is correct
50 Correct 84 ms 17276 KB Output is correct
51 Correct 31 ms 5268 KB Output is correct
52 Correct 359 ms 68044 KB Output is correct
53 Correct 368 ms 68108 KB Output is correct
54 Correct 55 ms 10076 KB Output is correct
55 Correct 121 ms 21044 KB Output is correct
56 Correct 89 ms 17724 KB Output is correct
57 Correct 81 ms 18128 KB Output is correct
58 Correct 373 ms 68528 KB Output is correct
59 Correct 62 ms 10424 KB Output is correct
60 Correct 86 ms 18372 KB Output is correct