답안 #942880

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
942880 2024-03-11T06:18:21 Z Lilypad Lasers (NOI19_lasers) C++14
100 / 100
163 ms 76216 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll,ll>
#define pb push_back
#define fi first
#define se second

const ll N = 5e5+5;

ll l,r,xx,c,ans;
ll tot[N];
vector<ll> a[N];
vector<pii> seg[N],seg1;
stack<pii> st,st1;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> l >> r;
	for(int i=1; i<=r; i++) {
		cin >> xx;
		for(int j=1; j<=xx; j++) {
			cin >> c;
			a[i].pb(c);
			tot[i] += c;
		}
	}
	for(int i=1; i<=r; i++) {
		if(tot[i] == l) {
			cout << l << endl;
			return 0;
		}
	}
	for(int i=1; i<=r; i++) {
		ll tmp = 0;
		for(auto j : a[i]) {	
			if(tmp+1 <= l-tot[i]) seg[i].pb({tmp+1,l-tot[i]});
			tot[i] -= j;
			tmp += j;
		}
		if(tmp+1 <= l) seg[i].pb({tmp+1,l});
		sort(seg[i].begin(),seg[i].end());
		for(int j=0; j<seg[i].size(); j++) {
			pii y = seg[i][j];
			while(!st.empty()) {
				pii x = st.top();
				if(x.se < y.fi) break;
				y.fi = min(y.fi,x.fi);
				y.se = max(y.se,x.se);
				st.pop(); 
			}
			st.push(y);
		}
		ll pre = l;
		while(!st.empty()) {
			pii x = st.top();
			st.pop();
			if(x.se+1 <= pre) seg1.pb({x.se+1,pre});
			pre = x.fi-1;
		}
		if(1 <= pre) seg1.pb({1,pre}); 
	}
	sort(seg1.begin(),seg1.end());
	for(auto j : seg1) {
		pii y = j;
		while(!st1.empty()) {
			pii x = st1.top();
			if(y.se < x.fi || y.fi > x.se) break;
			y.fi = min(y.fi,x.fi);
			y.se = max(y.se,x.se);
			st1.pop(); 
		}
		st1.push(y);
	}
	while(!st1.empty()) {
		pii x = st1.top();
		st1.pop();
		ans += x.se - x.fi + 1;
	}
	cout << ans << endl;
}

Compilation message

lasers.cpp: In function 'int main()':
lasers.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(int j=0; j<seg[i].size(); j++) {
      |                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 6 ms 25256 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25260 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 8 ms 25468 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 7 ms 25180 KB Output is correct
9 Correct 6 ms 25264 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 6 ms 25256 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25260 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 8 ms 25468 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 7 ms 25180 KB Output is correct
9 Correct 6 ms 25264 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 6 ms 25176 KB Output is correct
12 Correct 88 ms 48696 KB Output is correct
13 Correct 6 ms 25176 KB Output is correct
14 Correct 6 ms 25180 KB Output is correct
15 Correct 7 ms 25588 KB Output is correct
16 Correct 6 ms 25260 KB Output is correct
17 Correct 162 ms 75600 KB Output is correct
18 Correct 6 ms 25176 KB Output is correct
19 Correct 6 ms 25180 KB Output is correct
20 Correct 6 ms 25180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 43524 KB Output is correct
2 Correct 9 ms 26080 KB Output is correct
3 Correct 16 ms 28480 KB Output is correct
4 Correct 45 ms 42448 KB Output is correct
5 Correct 25 ms 35016 KB Output is correct
6 Correct 44 ms 42192 KB Output is correct
7 Correct 6 ms 25436 KB Output is correct
8 Correct 55 ms 48476 KB Output is correct
9 Correct 31 ms 36428 KB Output is correct
10 Correct 60 ms 44492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 25180 KB Output is correct
2 Correct 6 ms 25180 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25264 KB Output is correct
5 Correct 5 ms 25176 KB Output is correct
6 Correct 6 ms 25180 KB Output is correct
7 Correct 7 ms 25180 KB Output is correct
8 Correct 6 ms 25180 KB Output is correct
9 Correct 6 ms 25180 KB Output is correct
10 Correct 7 ms 25180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 43524 KB Output is correct
2 Correct 9 ms 26080 KB Output is correct
3 Correct 16 ms 28480 KB Output is correct
4 Correct 45 ms 42448 KB Output is correct
5 Correct 25 ms 35016 KB Output is correct
6 Correct 44 ms 42192 KB Output is correct
7 Correct 6 ms 25436 KB Output is correct
8 Correct 55 ms 48476 KB Output is correct
9 Correct 31 ms 36428 KB Output is correct
10 Correct 60 ms 44492 KB Output is correct
11 Correct 6 ms 25180 KB Output is correct
12 Correct 6 ms 25180 KB Output is correct
13 Correct 6 ms 25180 KB Output is correct
14 Correct 6 ms 25264 KB Output is correct
15 Correct 5 ms 25176 KB Output is correct
16 Correct 6 ms 25180 KB Output is correct
17 Correct 7 ms 25180 KB Output is correct
18 Correct 6 ms 25180 KB Output is correct
19 Correct 6 ms 25180 KB Output is correct
20 Correct 7 ms 25180 KB Output is correct
21 Correct 162 ms 74688 KB Output is correct
22 Correct 15 ms 27184 KB Output is correct
23 Correct 18 ms 29068 KB Output is correct
24 Correct 56 ms 42596 KB Output is correct
25 Correct 150 ms 74696 KB Output is correct
26 Correct 46 ms 40516 KB Output is correct
27 Correct 21 ms 30160 KB Output is correct
28 Correct 149 ms 74572 KB Output is correct
29 Correct 147 ms 74936 KB Output is correct
30 Correct 53 ms 37768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 25176 KB Output is correct
2 Correct 6 ms 25256 KB Output is correct
3 Correct 6 ms 25180 KB Output is correct
4 Correct 6 ms 25260 KB Output is correct
5 Correct 6 ms 25180 KB Output is correct
6 Correct 8 ms 25468 KB Output is correct
7 Correct 5 ms 25180 KB Output is correct
8 Correct 7 ms 25180 KB Output is correct
9 Correct 6 ms 25264 KB Output is correct
10 Correct 6 ms 25180 KB Output is correct
11 Correct 6 ms 25176 KB Output is correct
12 Correct 88 ms 48696 KB Output is correct
13 Correct 6 ms 25176 KB Output is correct
14 Correct 6 ms 25180 KB Output is correct
15 Correct 7 ms 25588 KB Output is correct
16 Correct 6 ms 25260 KB Output is correct
17 Correct 162 ms 75600 KB Output is correct
18 Correct 6 ms 25176 KB Output is correct
19 Correct 6 ms 25180 KB Output is correct
20 Correct 6 ms 25180 KB Output is correct
21 Correct 51 ms 43524 KB Output is correct
22 Correct 9 ms 26080 KB Output is correct
23 Correct 16 ms 28480 KB Output is correct
24 Correct 45 ms 42448 KB Output is correct
25 Correct 25 ms 35016 KB Output is correct
26 Correct 44 ms 42192 KB Output is correct
27 Correct 6 ms 25436 KB Output is correct
28 Correct 55 ms 48476 KB Output is correct
29 Correct 31 ms 36428 KB Output is correct
30 Correct 60 ms 44492 KB Output is correct
31 Correct 6 ms 25180 KB Output is correct
32 Correct 6 ms 25180 KB Output is correct
33 Correct 6 ms 25180 KB Output is correct
34 Correct 6 ms 25264 KB Output is correct
35 Correct 5 ms 25176 KB Output is correct
36 Correct 6 ms 25180 KB Output is correct
37 Correct 7 ms 25180 KB Output is correct
38 Correct 6 ms 25180 KB Output is correct
39 Correct 6 ms 25180 KB Output is correct
40 Correct 7 ms 25180 KB Output is correct
41 Correct 162 ms 74688 KB Output is correct
42 Correct 15 ms 27184 KB Output is correct
43 Correct 18 ms 29068 KB Output is correct
44 Correct 56 ms 42596 KB Output is correct
45 Correct 150 ms 74696 KB Output is correct
46 Correct 46 ms 40516 KB Output is correct
47 Correct 21 ms 30160 KB Output is correct
48 Correct 149 ms 74572 KB Output is correct
49 Correct 147 ms 74936 KB Output is correct
50 Correct 53 ms 37768 KB Output is correct
51 Correct 25 ms 30696 KB Output is correct
52 Correct 81 ms 48612 KB Output is correct
53 Correct 156 ms 75452 KB Output is correct
54 Correct 34 ms 34256 KB Output is correct
55 Correct 75 ms 45756 KB Output is correct
56 Correct 51 ms 39876 KB Output is correct
57 Correct 53 ms 42020 KB Output is correct
58 Correct 163 ms 76216 KB Output is correct
59 Correct 41 ms 35528 KB Output is correct
60 Correct 52 ms 39364 KB Output is correct