QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#457328 | #5517. Adjacent Product Sum | WTR2007 | WA | 24ms | 8872kb | C++20 | 1.3kb | 2024-06-29 10:36:09 | 2024-06-29 10:36:10 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define MULT_TEST 1
using namespace std;
typedef long double ldb;
typedef unsigned long long ull;
const int INF = 0x3f3f3f3f;
const int MOD = 998244353;
inline int read() {
int w = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
w = (w << 1) + (w << 3) + ch - 48;
ch = getchar();
}
return w * f;
}
inline void Solve() {
int n, tot = 0, res = 0;
n = read();
vector<int> a(n + 1), ans(n + 1);
for (int i = 1; i <= n; i++) a[i] = read();
sort(a.begin() + 1, a.end());
vector<int> A, B;
A.push_back(a[1]), B.push_back(a[2]);
for (int i = 3; i <= n; i++) {
if (A.back() * a[i] > B.back() * a[i]) B.push_back(a[i]);
else A.push_back(a[i]);
}
reverse(A.begin(), A.end());
for (auto t : A) ans[++tot] = t;
for (auto t : B) ans[++tot] = t;
// if ((ans[n - 1] - ans[n]) * (ans[n - 2] - ans[1]) < 0)
// swap(ans[n - 1], ans[n]);
for (int i = 1; i <= n; i++) res += ans[i] * ans[i % n + 1];
printf("%lld\n", res);
}
signed main() {
int _ = 1;
#if MULT_TEST
_ = read();
#endif
while (_--) Solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
input:
4 3 1 2 3 6 1 1 1 1 0 0 5 100000 100000 100000 100000 -100000 5 1 2 3 4 5
output:
11 3 10000000000 48
result:
ok 4 number(s): "11 3 10000000000 48"
Test #2:
score: -100
Wrong Answer
time: 24ms
memory: 8872kb
input:
1 200000 11009 633591 -419208 -664908 731171 -774644 -878270 656078 -38057 -220602 -897906 670165 -765931 -612936 -583782 -549624 -644245 137209 -983054 -110583 349193 699723 -412876 -417691 810865 -474314 -200632 570810 -283481 39600 20940 218215 -408751 -507326 -961614 600863 499517 -538207 767155...
output:
66607963141474005
result:
wrong answer 1st numbers differ - expected: '66608463123493911', found: '66607963141474005'