QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#741663#5035. foo~wdnmdwrnmmp0 14ms5160kbC++141.3kb2024-11-13 14:56:572024-11-13 14:57:03

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 14:57:03]
  • 评测
  • 测评结果:0
  • 用时:14ms
  • 内存:5160kb
  • [2024-11-13 14:56:57]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
// #define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
typedef vector<int> vi;
typedef pair<int,int> pi;

void chmax(int &x,int y){
	if(y>x) x=y;
}

signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	
	int n,k; cin>>n>>k;
	vi p(n);
	rep(i,0,n-1){
		cin>>p[i];
		p[i]--;
	}
	int idx=max_element(p.begin(), p.end())-p.begin();
	p.insert(p.end(), p.begin(), p.begin()+idx);
	p.erase(p.begin(), p.begin()+idx);
	
	// for(int x:p){
		// cout<< x <<' ';
	// }
	// cout<<'\n';
	
	int ans=0;
	
	auto solve=[&](){
		vector<vi> f(k+1, vi(n+1));
		vi s0, s1;
		rep(i,0,n-1){
			while(!s0.empty() && p[s0.back()]<p[i]){
				s0.pop_back();
			}
			while(!s1.empty() && p[s1.back()]>p[i]){
				s1.pop_back();
			}
			s0.pb(i);
			s1.pb(i);
			rep(c,0,k-1){
				per(x,(int)s0.size()-1,0){
					chmax(f[c+1][i+1], f[c][s0[x]]+(s0.size()-x));
				}
				per(x,(int)s1.size()-1,0){
					chmax(f[c+1][i+1], f[c][s1[x]]+(s1.size()-x));
				}
				chmax(f[c+1][i+1], f[c+1][i]);
			}
		}
		chmax(ans, f[k][n]);
	};
	solve();
	
	reverse(p.begin(), p.end());
	
	solve();
	cout<< ans <<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 10
Accepted
time: 1ms
memory: 3480kb

input:

23 6
16 20 22 4 21 10 3 7 5 8 15 12 9 1 6 17 23 13 11 19 18 14 2

output:

20

result:

ok "20"

Test #2:

score: 10
Accepted
time: 0ms
memory: 3540kb

input:

13 6
13 9 3 4 12 6 5 1 8 10 11 7 2

output:

13

result:

ok "13"

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 3744kb

input:

25 3
25 2 3 19 5 6 7 11 8 10 9 20 4 14 21 1 17 12 13 18 15 22 23 16 24

output:

17

result:

wrong answer 1st words differ - expected: '16', found: '17'

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 14ms
memory: 5160kb

input:

93943 1
87243 48984 50611 19218 77699 25025 85769 28141 13380 34875 42459 66419 53472 4367 48292 16894 92171 87263 42527 67085 30687 29235 27515 81053 31421 34864 83591 70491 75344 7026 50250 63402 26773 5330 36308 76399 80032 15501 16205 71750 73964 67876 68901 70548 2043 79979 89479 19784 38838 44...

output:

28

result:

wrong answer 1st words differ - expected: '25', found: '28'

Subtask #3:

score: 0
Wrong Answer

Test #36:

score: 0
Wrong Answer
time: 3ms
memory: 3676kb

input:

1992 25
144 612 1315 1966 1779 1773 1529 625 36 1849 1783 1441 1388 1558 1258 724 137 397 542 353 1162 1213 406 792 1317 882 994 298 1864 1969 103 449 508 1501 89 1721 195 778 657 222 1152 1780 613 743 1206 694 829 142 69 1973 1465 1343 655 1540 155 146 350 491 759 1695 1082 1357 1329 1745 232 1850 ...

output:

250

result:

wrong answer 1st words differ - expected: '237', found: '250'

Subtask #4:

score: 0
Skipped

Dependency #1:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%