結果
| 問題 |
No.1525 Meximum Sum
|
| ユーザー |
|
| 提出日時 | 2023-02-08 19:11:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 2,000 ms |
| コード長 | 1,572 bytes |
| コンパイル時間 | 3,956 ms |
| コンパイル使用メモリ | 230,312 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-06 05:31:13 |
| 合計ジャッジ時間 | 6,353 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
#include "atcoder/all"
#define debug cout << "OK" << endl;
template<typename T>
inline bool chmax(T& a, const T b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
inline bool chmin(T& a, const T b) { if (a > b) { a = b; return true; } return false; }
inline int Code(char c) {
if ('A' <= c and c <= 'Z')return (int)(c - 'A');
if ('a' <= c and c <= 'z')return (int)(c - 'a');
if ('0' <= c and c <= '9')return (int)(c - '0');
assert(false);
}
using namespace std;
using namespace atcoder;
#define int long long
constexpr int MOD = 998244353;
constexpr int INF = (1LL << 62);
using minit = modint998244353;
template<typename T>
ostream& operator << (ostream& st, const vector<T> &v) {
for (const T value : v) {
st << value << " ";
}
return st;
}
template<typename T>
istream& operator >> (istream& st, vector<T>& v) {
for (T &value : v) {
st >> value;
}
return st;
}
//
//
void solve() {
int N;
cin >> N;
vector<int> A(N);
cin >> A;
vector<int> place(N);
for (int i = 0; i < N; i++)place[A[i]] = i;
int ans = 0;
int l = place[0], r = place[0];
for (int i = 1; i < N; i++) {
int p = place[i];
if (l < p and p < r)continue;
else if (p < l) {
ans += (l - p) * (N - r) * i;
l = p;
}
else if (r < p) {
ans += (p - r) * (l + 1) * i;
r = p;
}
else assert(false);
}
ans += N;
cout << ans << endl;
}
signed main() {
int T = 1;
// cin >> T;
for (int i = 0; i < T; i++)
solve();
return 0;
}
/*
* わらびのコードこーどすぺーす
(σ・∀・)σゲッツ!!
*/