답안 #336318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
336318 2020-12-15T04:35:14 Z tengiz05 Bigger segments (IZhO19_segments) C++17
37 / 100
618 ms 133484 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FASTIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define pii pair<int, int>
#define ff first
#define ss second
#define PI acos(-1)
#define ld long double
const int mod = 1e9+7, N = 5005, inf = 1e18;
int msb(int val){return sizeof(int)*8-__builtin_clzll(val);}
int a[N], n, m, k;
vector<pii> dp[N];
int pr[N];
vector<int> pm[N];
void solve(int test_case){
	int i, j;
	cin >> n;
	for(i=1;i<=n;i++){
		cin >> a[i];
		pr[i]=a[i];pr[i]+=pr[i-1];
	}
	for(i=1;i<=n;i++){
		dp[i].pb({pr[i], 1});
		dp[i].pb({inf, -213234684});
		pm[i].pb(dp[i][0].ss);
		for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
	}
	for(i=2;i<=n;i++){
		for(j=1;j<i;j++){
			int s = pr[i]-pr[j];
			int pos = upper_bound(all(dp[j]), pii{s+1,-1})-dp[j].begin();pos--;
		/*	cout << "the sum is " << s << '\n';
			cout << dp[j][pos+1].ff << " <- was this\n"; 
			cout << pos << '\n';*/
			int mx=0;
			if(pos<0)continue;
		/*	bool f = false;
			//if(i == 5)cout << s << '\n';
			for(k=0;k<=pos;k++){
				if(dp[j][k].ff > s)continue;
				mx = max(mx, dp[j][k].ss);f=true;
				//if(i==5)cout << dp[j][k].ff << ' ' << dp[j][k].ss << '\n';
			}*/
			int mx2 = pm[j][pos];
		//	cout << mx << ' ' << mx2 << '\n';
			dp[i].pb({s, mx2+1});
		}sort(all(dp[i]));
		pm[i].clear();
		pm[i].pb(dp[i][0].ss);
		for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
	}
/*	for(i=1;i<=n;i++){
		cout << "doing " << i<< '\n';
		for(auto [x, y] : dp[i]){
			cout << x << ' ' << y << '\n';
		}
	}*/
	int ans = 1;
	for(auto [x, y] : dp[n]){
		ans = max(ans, y);
	} 
	cout << ans << '\n';
	return;
}

signed main(){
	FASTIO;
#define MULTITEST 0
#if MULTITEST
	int ___T;
	cin >> ___T;
	for(int T_CASE = 1; T_CASE <= ___T; T_CASE++)
		solve(T_CASE);
#else
	solve(1);
#endif
	return 0;
}




Compilation message

segments.cpp: In function 'void solve(long long int)':
segments.cpp:29:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |   for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
      |           ~^~~~~~~~~~~~~
segments.cpp:38:8: warning: unused variable 'mx' [-Wunused-variable]
   38 |    int mx=0;
      |        ^~
segments.cpp:53:12: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |   for(j=1;j<dp[i].size();j++)pm[i].pb(max(pm[i].back(), dp[i][j].ss));
      |           ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 10 ms 3948 KB Output is correct
18 Correct 10 ms 4460 KB Output is correct
19 Correct 9 ms 4588 KB Output is correct
20 Correct 10 ms 4588 KB Output is correct
21 Correct 10 ms 4460 KB Output is correct
22 Correct 7 ms 3180 KB Output is correct
23 Correct 4 ms 1900 KB Output is correct
24 Correct 10 ms 4460 KB Output is correct
25 Correct 10 ms 4460 KB Output is correct
26 Correct 10 ms 4608 KB Output is correct
27 Correct 7 ms 3308 KB Output is correct
28 Correct 10 ms 4460 KB Output is correct
29 Correct 10 ms 4588 KB Output is correct
30 Correct 10 ms 4588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 10 ms 3948 KB Output is correct
18 Correct 10 ms 4460 KB Output is correct
19 Correct 9 ms 4588 KB Output is correct
20 Correct 10 ms 4588 KB Output is correct
21 Correct 10 ms 4460 KB Output is correct
22 Correct 7 ms 3180 KB Output is correct
23 Correct 4 ms 1900 KB Output is correct
24 Correct 10 ms 4460 KB Output is correct
25 Correct 10 ms 4460 KB Output is correct
26 Correct 10 ms 4608 KB Output is correct
27 Correct 7 ms 3308 KB Output is correct
28 Correct 10 ms 4460 KB Output is correct
29 Correct 10 ms 4588 KB Output is correct
30 Correct 10 ms 4588 KB Output is correct
31 Correct 18 ms 896 KB Output is correct
32 Correct 401 ms 103916 KB Output is correct
33 Correct 529 ms 131236 KB Output is correct
34 Correct 454 ms 103552 KB Output is correct
35 Correct 524 ms 133356 KB Output is correct
36 Correct 546 ms 130284 KB Output is correct
37 Correct 345 ms 91116 KB Output is correct
38 Correct 232 ms 57708 KB Output is correct
39 Correct 550 ms 130540 KB Output is correct
40 Correct 618 ms 130540 KB Output is correct
41 Correct 545 ms 133484 KB Output is correct
42 Correct 481 ms 112236 KB Output is correct
43 Correct 481 ms 108140 KB Output is correct
44 Correct 536 ms 133484 KB Output is correct
45 Correct 533 ms 133100 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 10 ms 3948 KB Output is correct
18 Correct 10 ms 4460 KB Output is correct
19 Correct 9 ms 4588 KB Output is correct
20 Correct 10 ms 4588 KB Output is correct
21 Correct 10 ms 4460 KB Output is correct
22 Correct 7 ms 3180 KB Output is correct
23 Correct 4 ms 1900 KB Output is correct
24 Correct 10 ms 4460 KB Output is correct
25 Correct 10 ms 4460 KB Output is correct
26 Correct 10 ms 4608 KB Output is correct
27 Correct 7 ms 3308 KB Output is correct
28 Correct 10 ms 4460 KB Output is correct
29 Correct 10 ms 4588 KB Output is correct
30 Correct 10 ms 4588 KB Output is correct
31 Correct 18 ms 896 KB Output is correct
32 Correct 401 ms 103916 KB Output is correct
33 Correct 529 ms 131236 KB Output is correct
34 Correct 454 ms 103552 KB Output is correct
35 Correct 524 ms 133356 KB Output is correct
36 Correct 546 ms 130284 KB Output is correct
37 Correct 345 ms 91116 KB Output is correct
38 Correct 232 ms 57708 KB Output is correct
39 Correct 550 ms 130540 KB Output is correct
40 Correct 618 ms 130540 KB Output is correct
41 Correct 545 ms 133484 KB Output is correct
42 Correct 481 ms 112236 KB Output is correct
43 Correct 481 ms 108140 KB Output is correct
44 Correct 536 ms 133484 KB Output is correct
45 Correct 533 ms 133100 KB Output is correct
46 Runtime error 2 ms 1260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 620 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 620 KB Output is correct
10 Correct 1 ms 640 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 620 KB Output is correct
13 Correct 1 ms 620 KB Output is correct
14 Correct 1 ms 620 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 620 KB Output is correct
17 Correct 10 ms 3948 KB Output is correct
18 Correct 10 ms 4460 KB Output is correct
19 Correct 9 ms 4588 KB Output is correct
20 Correct 10 ms 4588 KB Output is correct
21 Correct 10 ms 4460 KB Output is correct
22 Correct 7 ms 3180 KB Output is correct
23 Correct 4 ms 1900 KB Output is correct
24 Correct 10 ms 4460 KB Output is correct
25 Correct 10 ms 4460 KB Output is correct
26 Correct 10 ms 4608 KB Output is correct
27 Correct 7 ms 3308 KB Output is correct
28 Correct 10 ms 4460 KB Output is correct
29 Correct 10 ms 4588 KB Output is correct
30 Correct 10 ms 4588 KB Output is correct
31 Correct 18 ms 896 KB Output is correct
32 Correct 401 ms 103916 KB Output is correct
33 Correct 529 ms 131236 KB Output is correct
34 Correct 454 ms 103552 KB Output is correct
35 Correct 524 ms 133356 KB Output is correct
36 Correct 546 ms 130284 KB Output is correct
37 Correct 345 ms 91116 KB Output is correct
38 Correct 232 ms 57708 KB Output is correct
39 Correct 550 ms 130540 KB Output is correct
40 Correct 618 ms 130540 KB Output is correct
41 Correct 545 ms 133484 KB Output is correct
42 Correct 481 ms 112236 KB Output is correct
43 Correct 481 ms 108140 KB Output is correct
44 Correct 536 ms 133484 KB Output is correct
45 Correct 533 ms 133100 KB Output is correct
46 Runtime error 2 ms 1260 KB Execution killed with signal 11 (could be triggered by violating memory limits)
47 Halted 0 ms 0 KB -