結果
問題 | No.1687 What the Heck? |
ユーザー |
|
提出日時 | 2021-09-24 22:05:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 679 bytes |
コンパイル時間 | 1,569 ms |
コンパイル使用メモリ | 167,952 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 10:38:08 |
合計ジャッジ時間 | 2,842 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 18 |
ソースコード
#include <bits/stdc++.h> #define rep(i, l, r) for (int i = (l); i < (r); i++) using namespace std; typedef long long ll; int main() { ll N; cin >> N; vector<int> P(N), Q(N); rep(i, 0, N) { cin >> P[i]; Q[P[i] - 1] = i + 1; } if (N == 1) { cout << 0 << endl; return 0; } if (N == 2) { if (P[0] == 1) cout << 0 << endl; else cout << 1 << endl; return 0; } ll t = N * (N + 1) / 2, ans = 0; //cout << ans << endl; rep(i, 0, N) { ans = max(ans, t - 2 * Q[N - 1 - i]); t -= Q[N - 1 - i]; //cout << i << " " << ans << endl; } cout << ans << endl; }