QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#225599 | #5500. Bars | Kac5002 | WA | 201ms | 3732kb | C++14 | 1.3kb | 2023-10-24 20:32:42 | 2023-10-24 20:32:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int ilwekt(pair<int, int> X, pair<int, int> Y, pair<int, int> Z){
int x1 = Z.first - X.first, y1 = Z.second - X.second;
int x2 = Y.first - X.first, y2 = Y.second - X.second;
return x1*y2 - x2*y1;
}
stack<int> otoczka(vector<int> &B){
stack<int> S;
S.push(0);
int x = 0, y = 1;
for(int i = 2; i<B.size(); i++){
while(ilwekt({x, B[x]}, {y, B[y]}, {i, B[i]})<0){
y = x;
S.pop();
if(S.empty()) break;
x = S.top();
}
S.push(y);
x = y;
y = i;
}
S.push(B.size()-1);
return S;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int z;
cin >> z;
while(z--){
int n;
cin >> n;
vector<int> B(n);
for(auto &b : B) cin >> b;
auto S = otoczka(B);
int ans = 0;
int lp = 0, lr = 0;
for(int i = n-1; i>=0; i--){
if(i==S.top()){
ans+=lr*B[i];
S.pop();
if(S.empty()) break;
lp = i-S.top();
ans+=lp*B[i];
lr = i-S.top();
}
}
cout << ans << "\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3612kb
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: 201ms
memory: 3732kb
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 324658624 793445285 135701300 -614827159 68006531 1041472957 -2079769354 1622454214 1899874298 577398246 1052188061 286602769 978601897 52009853 1541383052 -1036447661 1284911644 1810264968 103497341 -1288589731 -1016875005 842520498 2095057071 2067565728 -1218375174 1025155419 -1009738986 -29...
result:
wrong answer 3rd lines differ - expected: '382465638565', found: '324658624'