QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#102416#5517. Adjacent Product SumYldar#WA 36ms4600kbC++17929b2023-05-03 12:56:152023-05-03 12:56:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-03 12:56:17]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:4600kb
  • [2023-05-03 12:56:15]
  • 提交

answer

//
//  a.cpp
//  2023-04-29 02:23
//
//  Created by liznb
//

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int z; cin >> z;
  while (z--) {
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a.begin(), a.end());
    int ans = 0;
    for (int i = 0; i < n - 1; i++) {
      ans += a[i] * a[i + 1];
    }
    ans += a[n - 1] * a[0];
    int res = 0;
    for (int i = 1; i < n - 1; i++) {
      int backup = ans;
      ans -= a[(i - 1 + n) % n] * a[i];
      ans -= a[(i + 1) % n] * a[i];
      ans -= a[0] * a[n - 1];
      ans += a[(i - 1 + n) % n] * a[(i + 1) % n];
      ans += a[0] * a[i];
      ans += a[n - 1] * a[i];
      res = max(ans, res);
      ans = backup;
    }
    cout << res << endl;
  }

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3404kb

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: 36ms
memory: 4600kb

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:

66607463195438342

result:

wrong answer 1st numbers differ - expected: '66608463123493911', found: '66607463195438342'