結果

問題 No.1687 What the Heck?
ユーザー 沙耶花沙耶花
提出日時 2021-09-24 21:26:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 4,052 ms
コンパイル使用メモリ 260,828 KB
実行使用メモリ 5,576 KB
最終ジャッジ日時 2023-09-18 20:38:44
合計ジャッジ時間 5,309 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 12 ms
4,380 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 11 ms
4,376 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 34 ms
5,400 KB
testcase_13 AC 35 ms
5,556 KB
testcase_14 AC 33 ms
5,428 KB
testcase_15 AC 34 ms
5,576 KB
testcase_16 AC 33 ms
5,400 KB
testcase_17 AC 4 ms
4,376 KB
testcase_18 AC 33 ms
5,440 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 10000000000000000



int main(){
	
	int n;
	cin>>n;
	
	vector<int> p(n);
	vector<long long> point(n);

	rep(i,n){
		scanf("%d",&p[i]);
		point[p[i]-1] = i+1;
	}
	
	vector<long long> dp(2,0);
	
	rep(i,n){
		vector<long long> ndp(2,-Inf);
		ndp[1] = max(dp[0] + point[i], dp[1] + point[i]);
		ndp[0] = max(dp[0], dp[1] - point[i]);
		swap(dp,ndp);
		
	}
	
	cout<<dp[0]<<endl;
	
	return 0;
}
0