結果
問題 |
No.1687 What the Heck?
|
ユーザー |
|
提出日時 | 2021-09-24 21:55:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 707 bytes |
コンパイル時間 | 1,714 ms |
コンパイル使用メモリ | 167,992 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-05 10:31:09 |
合計ジャッジ時間 | 2,774 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 7 WA * 11 |
ソースコード
#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() { int 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 - 2 * Q[N - 1], ans = t; //cout << ans << endl; rep(i, 0, N) { t += Q[N - 1 - i]; t -= 2 * Q[N - 2 - i]; ans = max(ans, t); //cout << i << " " << ans << endl; } cout << ans << endl; }