QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#283317 | #5517. Adjacent Product Sum | Misuki# | AC ✓ | 25ms | 6424kb | C++20 | 2.4kb | 2023-12-14 14:05:41 | 2023-12-14 14:05:42 |
Judging History
answer
#pragma GCC optimize("O2")
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>
#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)
namespace R = std::ranges;
namespace V = std::views;
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = tuple<int, int, int>;
using ldb = long double;
//#define double ldb
template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
for(const T &X : arr)
os << X << ' ';
return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
for(const T &X : vec)
os << X << ' ';
return os;
}
signed main() {
ios::sync_with_stdio(false), cin.tie(NULL);
int t; cin >> t;
while(t--) {
int n; cin >> n;
vector<int> a(n);
for(int &x : a)
cin >> x;
R::sort(a | V::reverse);
deque<int> dq;
for(int i = 0; i < n; i++) {
if (i & 1) dq.push_front(a[i]);
else dq.push_back(a[i]);
}
int ans = dq.front() * dq.back();
for(int i = 0; i + 1 < n; i++) {
int x = dq.front(); dq.pop_front();
ans += x * dq.front();
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3872kb
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: 0
Accepted
time: 22ms
memory: 6208kb
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:
66608463123493911
result:
ok 1 number(s): "66608463123493911"
Test #3:
score: 0
Accepted
time: 22ms
memory: 6308kb
input:
1 200000 7902 376928 977876 -664787 382287 -671247 263725 -875047 554163 59899 -976624 726497 617682 -387432 -960499 -703748 -644991 72374 -564962 -569121 -412123 907945 -379338 915496 665461 389485 -742294 942448 -862668 -677446 -72510 -382856 893536 128827 -596269 -572440 -532339 536145 -521524 -3...
output:
66581505433554478
result:
ok 1 number(s): "66581505433554478"
Test #4:
score: 0
Accepted
time: 25ms
memory: 6424kb
input:
1 200000 969944 -942957 346587 328855 61775 -596222 -622652 -504245 181233 -694452 -90194 -350098 1294 844554 -273993 205351 -674109 35911 887981 -929585 826563 179388 689051 -716467 450354 -746718 -220733 348937 529775 -331268 868892 -885852 -839030 834684 803928 225887 435807 575645 189798 -255705...
output:
66721135858270454
result:
ok 1 number(s): "66721135858270454"
Test #5:
score: 0
Accepted
time: 25ms
memory: 6228kb
input:
1 200000 -68015 -262842 778522 -607801 -287109 542027 -515508 -105072 871526 -483654 865940 -391840 419758 -929943 -650710 -885551 359996 -965702 340923 611878 -899901 387610 -214190 616720 235247 117080 300828 -342648 20292 -83165 747072 -521774 561331 505688 -830728 -877713 438804 -419707 -35659 7...
output:
66646767806203928
result:
ok 1 number(s): "66646767806203928"
Test #6:
score: 0
Accepted
time: 25ms
memory: 6200kb
input:
1 200000 894027 417274 -887618 -579309 -635992 645424 598116 363804 -536255 -203152 787222 531567 866594 -732810 35796 -941601 -703973 -65388 759014 -811810 -724439 595832 -180652 -78465 -945009 113803 -212463 994139 377883 -800211 -311527 -59622 828766 -788457 -493755 885764 372098 -380207 675663 8...
output:
66669581129323609
result:
ok 1 number(s): "66669581129323609"
Test #7:
score: 0
Accepted
time: 24ms
memory: 5136kb
input:
2 100000 169603 145427 -202283 -480350 -856872 -65853 -442884 -773569 -275747 -953075 873381 -155156 -519569 -351127 558958 -345448 461553 927180 -310163 -46521 -857521 -906097 -91734 875600 836439 39554 488295 162237 -570813 -456645 -876308 254421 93745 689934 -712525 31372 536079 487786 191237 747...
output:
33392172147649469 33329865049707147
result:
ok 2 number(s): "33392172147649469 33329865049707147"
Test #8:
score: 0
Accepted
time: 25ms
memory: 5224kb
input:
2 100000 166496 -139607 131578 -451857 794246 -927605 601038 660456 316473 -672574 -170486 -196898 -101105 909229 -754537 535280 -602416 -74433 -857221 -435356 381164 365348 -58196 208786 621332 -998574 -990145 -431275 -213222 -110468 65094 716574 430883 -604211 -375551 829699 -495776 -535937 -13229...
output:
33445326050536015 33363059196148572
result:
ok 2 number(s): "33445326050536015 33363059196148572"
Test #9:
score: 0
Accepted
time: 24ms
memory: 5352kb
input:
2 100000 -871463 568880 -401636 611487 445363 -852579 777884 -870669 -56457 -461776 -249205 824583 -717493 71511 868747 -555622 -603163 825881 595722 -893894 -380151 573570 -24659 548454 377854 -134776 496566 -157711 242444 -827514 -56727 -919349 698318 -933207 954943 -343604 472370 -496437 579028 -...
output:
33375458994693108 33453260311973619
result:
ok 2 number(s): "33375458994693108 33453260311973619"
Test #10:
score: 0
Accepted
time: 24ms
memory: 5132kb
input:
2 100000 90579 -751006 -67776 -423243 124850 -749182 856656 -471496 -429386 783875 637226 782840 666120 -668134 -444748 353477 430943 -175732 -986188 745643 -204689 781792 -927900 -118360 162747 -236127 -981874 213927 669738 -579410 884675 577656 604 737799 355139 -510426 -587857 -456937 325201 -996...
output:
33287772768665659 33313392958107202
result:
ok 2 number(s): "33287772768665659 33313392958107202"
Test #11:
score: 0
Accepted
time: 24ms
memory: 5480kb
input:
2 100000 -947380 -70891 -670693 -394750 -224033 389067 -1349 -2620 -773945 -935625 656582 -293754 -915416 494148 -821465 -737425 -633027 -212195 466755 287104 68848 53235 -894362 249678 982492 -309107 -460313 557194 -972672 -331307 860928 -23415 -668739 408803 692113 316272 380289 -417437 -963479 -9...
output:
33288924160392129 33379620728513712
result:
ok 2 number(s): "33288924160392129 33379620728513712"
Test #12:
score: 0
Accepted
time: 22ms
memory: 3964kb
input:
10 20000 841746 527518 595261 331297 -946901 129987 670374 -140388 -684770 309555 -302589 415564 -387435 613331 -624940 -95922 945847 -199224 24636 -565799 -72069 -395358 -523453 -511446 854898 -846967 -749453 -341866 173256 -508156 574073 878761 984359 798117 -622388 434663 264157 607113 -38776 139...
output:
6622802477773024 6640013265208007 6592100254591181 6640170208895030 6688143425864831 6705222845668074 6676830146528095 6618221005278570 6714940493280121 6724345935461679
result:
ok 10 numbers
Test #13:
score: 0
Accepted
time: 16ms
memory: 3620kb
input:
100 2000 -607224 -718287 -433045 -816611 -935719 -559217 508630 -485197 134273 -520442 886499 318527 104344 -376092 -146638 -921227 98459 -324526 -396653 39142 -536124 114612 -22769 215450 -806035 217692 -758435 -360933 -470886 -271877 -839014 683804 138195 405799 -385833 481109 198084 -145350 -4353...
output:
664320265599433 656060796084111 670847172001984 693285015575982 641806321082038 686775083044219 660836368097072 665848189708176 656774554796514 640515026177509 637922445211883 651793096312130 668305333192730 680836044550146 642790615977139 659533778528338 689986245290621 679990801733695 664398460938...
result:
ok 100 numbers
Test #14:
score: 0
Accepted
time: 17ms
memory: 3600kb
input:
1000 200 324840 875913 -750586 872247 891834 -802538 -394930 -39271 -402853 -935536 -148671 -311516 -470147 168411 428251 -412526 736882 93448 384219 -987587 -924419 974032 864821 448111 409149 -889736 17366 -198877 -314710 -952652 406856 124043 183144 -182906 -79075 308212 785198 -276953 260766 178...
output:
65021379321819 61482831940623 64907628507685 65762816459484 64637099110104 70521910685375 71017401353273 63188959323659 64923749759877 78536500128365 72214363259863 72551077515316 64319147242944 70483971638209 60920280492111 74602439250852 66241024614625 66265066071760 69062565668032 71163034443457 ...
result:
ok 1000 numbers
Test #15:
score: 0
Accepted
time: 17ms
memory: 3592kb
input:
10000 20 15812 -152393 101507 981503 -762519 70570 197040 710069 767152 -683226 691070 -756515 -396347 -388139 -327351 -323136 -451642 -327842 989160 548358 20 -344746 439864 -408284 787179 -526193 -898718 -1701 -843020 956421 697486 -822953 243028 -209174 82020 -997778 242139 -932413 -673559 176880...
output:
5836057833484 7900249490263 6741513108893 7695904868186 5905346687260 6210447934702 6528577603481 6366200793553 7285941052913 6695898759021 5336229787408 6603459571509 5516442382707 6068193077387 6836405277420 5809766642183 7914983783571 7722262525971 6863867878728 5452027662683 6336759366520 571716...
result:
ok 10000 numbers
Test #16:
score: 0
Accepted
time: 17ms
memory: 3720kb
input:
42 4761 -884836 423256 -16540 5180 626061 574189 64375 565165 891155 631808 84833 -143882 -909496 758173 204660 -700050 163672 -867390 920820 848717 -347766 -768001 437344 -21942 403333 -220324 388822 84096 -938705 527686 841315 876833 131270 836458 700753 -740379 253394 -432058 494815 -255931 -8361...
output:
1568197940334474 1627465779774764 1613876915865833 1579828038154862 1563836977436851 1608582638636216 1589836095120383 1577031292775532 1608544317984962 1617042083628598 1589929522676958 1588048186120208 1562897607148914 1551101839004540 1582371865754027 1590036248776725 1606863383861959 16117573084...
result:
ok 42 numbers
Test #17:
score: 0
Accepted
time: 20ms
memory: 3920kb
input:
69 2898 -826877 -729045 -951445 -391404 197462 798213 -288928 -157886 631013 -85218 377079 -128051 -661781 -189943 -900471 43621 -847997 400563 -695730 -932224 -245215 -395642 -559167 -118464 920363 252772 -623730 -286403 -674675 -560306 -448483 924941 210935 -834513 608008 -136257 -953207 665428 29...
output:
942714868546250 946859857816400 969037992012804 977484785384248 919489346073972 969868311124320 933818196842132 977503973543166 967593973040804 982214889485424 963286569050653 970847618560724 957508838495683 945357209274080 933598867828567 978233850926901 975379109413588 1000443792815115 98105291396...
result:
ok 69 numbers