QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#457331#5517. Adjacent Product SumWTR2007WA 21ms8824kbC++201.3kb2024-06-29 10:38:332024-06-29 10:38:33

Judging History

你现在查看的是最新测评结果

  • [2024-06-29 10:38:33]
  • 评测
  • 测评结果:WA
  • 用时:21ms
  • 内存:8824kb
  • [2024-06-29 10:38:33]
  • 提交

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: 0ms
memory: 4048kb

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: 21ms
memory: 8824kb

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'