ログインしてください。
提出 #48914466
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
long long solve(vector<long long> &a) {
int n = a.size();
stack<int> st;
vector<int> nse(n), pse(n);
for (int i = 0; i < n; i++) {
while (!st.empty() && a[st.top()] > a[i]) {
nse[st.top()] = i;
st.pop();
}
if (st.empty()) {
pse[i] = -1;
} else {
pse[i] = st.top();
}
st.push(i);
}
while (!st.empty()) {
nse[st.top()] = n;
st.pop();
}
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += a[i] * (i - pse[i]) * (nse[i] - i);
}
return ans;
}
int main() {
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
cout << solve(a) << endl;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | B - Minimum Sum |
| ユーザ | adaptatron |
| 言語 | C++ 20 (gcc 12.2) |
| 得点 | 400 |
| コード長 | 856 Byte |
| 結果 | AC |
| 実行時間 | 37 ms |
| メモリ | 7012 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 400 / 400 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example0, example1, example2 |
| All | corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2 |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| corner0 | AC | 35 ms | 7012 KiB |
| corner1 | AC | 34 ms | 6220 KiB |
| corner2 | AC | 1 ms | 3396 KiB |
| corner3 | AC | 35 ms | 6544 KiB |
| example0 | AC | 1 ms | 3460 KiB |
| example1 | AC | 1 ms | 3568 KiB |
| example2 | AC | 1 ms | 3432 KiB |
| maxrand0 | AC | 36 ms | 6440 KiB |
| maxrand1 | AC | 37 ms | 6220 KiB |
| maxrand2 | AC | 36 ms | 6308 KiB |
| rand0 | AC | 1 ms | 3416 KiB |
| rand1 | AC | 1 ms | 3424 KiB |
| rand2 | AC | 1 ms | 3464 KiB |