QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#170883 | #5517. Adjacent Product Sum | ucup-team963# | WA | 21ms | 4712kb | C++14 | 1.6kb | 2023-09-09 16:09:37 | 2023-09-09 16:09:38 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
signed main() {
if(fopen("yl.in", "r")) {
freopen("yl.in", "r", stdin);
freopen("yl.out", "w", stdout);
}
ios::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
while(T --) {
int n;
cin >> n;
vector<int> vec(n);
rep(i,0,n - 1) cin >> vec[i];
sort(vec.begin(), vec.end());
deque<int> d1, d2;
int side = 1;
long long ans = 0;
for(auto it = vec.begin(); it != vec.end() && *it <= 0; ++ it) {
if(side) {
if(d1.size()) ans += 1ll * d1.front() * (*it);
d1.push_front(*it);
} else {
if(d1.size()) ans += 1ll * d1.back() * (*it);
d1.push_back(*it);
}
side ^= 1;
}
side = 1;
for(auto it = vec.rbegin(); it != vec.rend() && *it > 0; ++ it) {
if(side) {
if(d2.size()) ans += 1ll * d2.front() * (*it);
d2.push_front(*it);
} else {
if(d2.size()) ans += 1ll * d2.back() * (*it);
d2.push_back(*it);
}
side ^= 1;
}
if(d1.size() == 0) ans += d2.front() * d2.back();
else if(d2.size() == 0) ans += d1.front() * d1.back();
else {
ans += min(1ll * d1.front() * d2.front() + 1ll * d1.back() * d2.back(), 1ll * d1.back() * d2.front() + 1ll * d1.front() * d2.back());
}
cout << ans << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3624kb
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: 4712kb
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:
66608463123493909
result:
wrong answer 1st numbers differ - expected: '66608463123493911', found: '66608463123493909'