QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#79748 | #5517. Adjacent Product Sum | yuto1115 | AC ✓ | 35ms | 4968kb | C++17 | 7.8kb | 2023-02-20 20:33:53 | 2023-02-20 20:33:56 |
Judging History
answer
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(i, n) for (ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for (ll i = ll(s); i < ll(n); ++i)
#define rep3(i, s, n, d) for(ll i = ll(s); i < ll(n); i+=d)
#define rep(...) overload4(__VA_ARGS__,rep3,rep2,rep1)(__VA_ARGS__)
#define rrep1(i, n) for (ll i = ll(n)-1; i >= 0; i--)
#define rrep2(i, n, t) for (ll i = ll(n)-1; i >= (ll)t; i--)
#define rrep3(i, n, t, d) for (ll i = ll(n)-1; i >= (ll)t; i-=d)
#define rrep(...) overload4(__VA_ARGS__,rrep3,rrep2,rrep1)(__VA_ARGS__)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define SUM(a) accumulate(all(a),0LL)
#define MIN(a) *min_element(all(a))
#define MAX(a) *max_element(all(a))
#define SORT(a) sort(all(a));
#define REV(a) reverse(all(a));
#define SZ(a) int(a.size())
#define popcount(x) __builtin_popcountll(x)
#define pf push_front
#define pb push_back
#define ef emplace_front
#define eb emplace_back
#define ppf pop_front
#define ppb pop_back
#ifdef __LOCAL
#define debug(...) { cout << #__VA_ARGS__; cout << ": "; print(__VA_ARGS__); cout << flush; }
#else
#define debug(...) void(0);
#endif
#define INT(...) int __VA_ARGS__;scan(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;scan(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;scan(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;scan(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;scan(__VA_ARGS__)
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vvvl = vector<vvl>;
using vd = vector<double>;
using vvd = vector<vd>;
using vs = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vp = vector<P>;
using vvp = vector<vp>;
using vlp = vector<LP>;
using vvlp = vector<vlp>;
template<class T>
using PQ = priority_queue<T>;
template<class T>
using PQrev = priority_queue<T, vector<T>, greater<T>>;
template<class S, class T>
istream &operator>>(istream &is, pair<S, T> &p) { return is >> p.first >> p.second; }
template<class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &p) { return os << '{' << p.first << ", " << p.second << '}'; }
template<class S, class T, class U>
istream &operator>>(istream &is, tuple<S, T, U> &t) { return is >> get<0>(t) >> get<1>(t) >> get<2>(t); }
template<class S, class T, class U>
ostream &operator<<(ostream &os, const tuple<S, T, U> &t) {
return os << '{' << get<0>(t) << ", " << get<1>(t) << ", " << get<2>(t) << '}';
}
template<class T>
istream &operator>>(istream &is, vector<T> &v) {
for (T &t: v) { is >> t; }
return is;
}
template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << '[';
rep(i, v.size()) os << v[i] << (i == int(v.size() - 1) ? "" : ", ");
return os << ']';
}
template<class T>
ostream &operator<<(ostream &os, const deque<T> &v) {
os << '[';
rep(i, v.size()) os << v[i] << (i == int(v.size() - 1) ? "" : ", ");
return os << ']';
}
template<class T>
ostream &operator<<(ostream &os, const set<T> &st) {
os << '{';
auto it = st.begin();
while (it != st.end()) {
os << (it == st.begin() ? "" : ", ") << *it;
it++;
}
return os << '}';
}
template<class T>
ostream &operator<<(ostream &os, const multiset<T> &st) {
os << '{';
auto it = st.begin();
while (it != st.end()) {
os << (it == st.begin() ? "" : ", ") << *it;
it++;
}
return os << '}';
}
template<class T, class U>
ostream &operator<<(ostream &os, const map<T, U> &mp) {
os << '{';
auto it = mp.begin();
while (it != mp.end()) {
os << (it == mp.begin() ? "" : ", ") << *it;
it++;
}
return os << '}';
}
template<class T>
void vecout(const vector<T> &v, char div = '\n') {
rep(i, v.size()) cout << v[i] << (i == int(v.size() - 1) ? '\n' : div);
}
template<class T>
bool constexpr chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool constexpr chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
void scan() {}
template<class Head, class... Tail>
void scan(Head &head, Tail &... tail) {
cin >> head;
scan(tail...);
}
template<class T>
void print(const T &t) { cout << t << '\n'; }
template<class Head, class... Tail>
void print(const Head &head, const Tail &... tail) {
cout << head << ' ';
print(tail...);
}
template<class T>
vector<T> &operator+=(vector<T> &v, T x) {
for (T &t: v) t += x;
return v;
}
template<class T>
vector<T> &operator-=(vector<T> &v, T x) {
for (T &t: v) t -= x;
return v;
}
template<class T>
vector<T> &operator*=(vector<T> &v, T x) {
for (T &t: v) t *= x;
return v;
}
template<class T>
vector<T> &operator/=(vector<T> &v, T x) {
for (T &t: v) t /= x;
return v;
}
struct Init_io {
Init_io() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout << boolalpha << fixed << setprecision(15);
cerr << boolalpha << fixed << setprecision(15);
}
} init_io;
const string yes[] = {"no", "yes"};
const string Yes[] = {"No", "Yes"};
const string YES[] = {"NO", "YES"};
const int inf = 1001001001;
const ll linf = 1001001001001001001;
void rearrange(const vi &) {}
template<class T, class... Tail>
void rearrange(const vi &ord, vector<T> &head, Tail &...tail) {
assert(ord.size() == head.size());
vector<T> ori = head;
rep(i, ord.size()) head[i] = ori[ord[i]];
rearrange(ord, tail...);
}
template<class T, class... Tail>
void sort_by(vector<T> &head, Tail &... tail) {
vi ord(head.size());
iota(all(ord), 0);
sort(all(ord), [&](int i, int j) { return head[i] < head[j]; });
rearrange(ord, head, tail...);
}
bool in_rect(int i, int j, int h, int w) {
return 0 <= i and i < h and 0 <= j and j < w;
}
template<class T>
constexpr vector<T> pow_table(int n, T base) {
vector<T> res(n, 1);
rep(i, n - 1) res[i + 1] = res[i] * base;
return res;
}
template<class T, class S>
vector<T> cumsum(const vector<S> &v, bool shift_one = true) {
int n = v.size();
vector<T> res;
if (shift_one) {
res.resize(n + 1);
rep(i, n) res[i + 1] = res[i] + v[i];
} else {
res.resize(n);
if (n) {
res[0] = v[0];
rep(i, 1, n) res[i] = res[i - 1] + v[i];
}
}
return res;
}
vvi graph(int n, int m, bool directed = false, int origin = 1) {
vvi G(n);
rep(_, m) {
INT(u, v);
u -= origin, v -= origin;
G[u].pb(v);
if (!directed) G[v].pb(u);
}
return G;
}
template<class T>
vector<vector<pair<int, T>>> weighted_graph(int n, int m, bool directed = false, int origin = 1) {
vector<vector<pair<int, T>>> G(n);
rep(_, m) {
int u, v;
T w;
scan(u, v, w);
u -= origin, v -= origin;
G[u].eb(v, w);
if (!directed) G[v].eb(u, w);
}
return G;
}
void solve() {
INT(n);
vi a(n);
scan(a);
sort(all(a));
vi b;
rep(i, 0, n, 2) b.pb(a[i]);
rrep(i, n - (n & 1), 0, 2) b.pb(a[i]);
ll ans = 0;
rep(i, n) ans += (ll) b[i] * b[(i + 1) % n];
print(ans);
}
int main() {
int t;
cin >> t;
rep(i, t) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3508kb
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: 33ms
memory: 4884kb
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: 30ms
memory: 4888kb
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: 30ms
memory: 4948kb
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: 30ms
memory: 4968kb
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: 35ms
memory: 4892kb
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: 25ms
memory: 4332kb
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: 35ms
memory: 4488kb
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: 34ms
memory: 4488kb
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: 30ms
memory: 4348kb
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: 35ms
memory: 4456kb
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: 21ms
memory: 3696kb
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: 25ms
memory: 3384kb
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: 28ms
memory: 3512kb
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: 23ms
memory: 3388kb
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: 30ms
memory: 3452kb
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: 19ms
memory: 3556kb
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