QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#377569 | #5500. Bars | 8BQube# | WA | 196ms | 3984kb | C++20 | 1.3kb | 2024-04-05 15:22:16 | 2024-04-05 15:22:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define SZ(a) ((int)a.size())
#define pb push_back
#define ALL(v) v.begin(), v.end()
const int N = 5e5 + 5;
ll a[N];
void solve() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
// for (int i = 1; i <= n; i++) {
// dp[i] = (i - 1) * a[i];
// for (int j = 1; j < i; j++)
// dp[i] = max(dp[i], dp[j] + (i - j) * (a[i] + a[j]));
// }
// ll ans = 0;
// for (int i = 1; i <= n; i++)
// ans = max(ans, dp[i] + (n - i) * a[i]);
// cout << ans << "\n";
vector<ll> L;
L.pb(1);
for (int i = 2; i <= n; i++)
if (a[i] > a[L.back()])
L.pb(i);
vector<ll> R;
R.pb(n);
for (int i = n - 1; i >= 1; i--)
if (a[i] > a[R.back()])
R.pb(i);
reverse(ALL(R));
for (int x : R)
if (x > L.back())
L.pb(x);
ll ans = 0;
for (int i = 0; i + 1 < SZ(L); i++) {
ans += (a[L[i]] + a[L[i + 1]]) * (L[i + 1] - L[i]);
}
ans += a[L[0]] * (L[0] - 1);
ans += a[L.back()] * (n - L.back());
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--)
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3632kb
input:
2 4 5 2 2 6 5 1 5 4 4 1
output:
33 29
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 196ms
memory: 3984kb
input:
10000 4 5 2 2 6 5 1 5 4 4 1 197 763787596 15221694 898228999 187472305 466351873 822742732 437754202 800092772 843092246 915675776 166265020 346340615 796714085 497548541 182089610 64356048 363276768 181268733 257949015 236568898 752096761 928725929 443146784 114577469 833053207 38120723 14891030 41...
output:
33 29 381268324603 658930892444 543073796232 458946673513 296420749955 872966641760 630432425409 583595848800 225238172692 715347519911 462034667948 273545943459 585094154153 200443831314 336548821022 483213442818 602558460217 586771956643 400264139273 826365121407 975377092201 920978353624 26408806...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '381268324603'