結果

問題 No.1687 What the Heck?
ユーザー 沙耶花
提出日時 2021-09-24 21:26:54
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 590 bytes
コンパイル時間 4,468 ms
コンパイル使用メモリ 250,036 KB
最終ジャッジ日時 2025-01-24 16:47:25
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 18
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:21:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   21 |                 scanf("%d",&p[i]);
      |                 ~~~~~^~~~~~~~~~~~

ソースコード

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