結果
問題 |
No.1687 What the Heck?
|
ユーザー |
|
提出日時 | 2021-09-24 22:12:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 212 ms / 2,000 ms |
コード長 | 638 bytes |
コンパイル時間 | 1,145 ms |
コンパイル使用メモリ | 103,572 KB |
最終ジャッジ日時 | 2025-01-24 17:21:57 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <iostream> #include <string> #include <vector> #include <algorithm> #include <utility> #include <set> #include <map> #include <queue> #include <cmath> using namespace std; typedef long long ll; #define rep(i, n) for (int i=0;i < (int)(n);i++) int main(){ ll n; cin >> n; ll ans = 0; if (n == 1){ cout << 0 << endl; return 0; } map<int,int> mp; rep(i,n){ ll x; cin >> x; mp[int(x)] = i+1; } ll sum = n*(n+1)/2; for (int i = n;i >= 1;i--){ ans = max(sum - 2*mp[i],ans); sum -= mp[i]; } cout << ans << endl; return 0; }