QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#586645#9142. Uniting AmoebasYukii_P#WA 27ms3836kbC++142.0kb2024-09-24 14:50:562024-09-24 14:50:57

Judging History

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

  • [2024-09-24 14:50:57]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:3836kb
  • [2024-09-24 14:50:56]
  • 提交

answer

/*

This code template was updated by Yukii_P on 2024/9/20.

*/
#include <bits/stdc++.h>
#define FIO cin.tie(0); ios::sync_with_stdio(false)
#define fi first
#define se second
#define inf 0x3f3f3f3f

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x << "=" << x << '\n'
#else
#define debug(x) 
#endif

using namespace std;
using i64 = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using pii = pair<int, int>;

inline char nc() {
    static char buf[1 << 20], *p1, *p2;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<20, stdin), p1 == p2) ? EOF : *p1++;
}
#ifndef ONLINE_JUDGE
#define nc getchar
#endif
void read() {}
template<typename T, typename... T2> 
inline void read(T &x, T2 &... oth) {
    x = 0; char c = nc(), up = c;
    while(!isdigit(c)) up = c, c = nc();
    while(isdigit(c)) x = x * 10 + c - '0', c = nc();
    up == '-' ? x = -x : 0;
    read(oth...);
}

constexpr int N = 2e5 + 10;
constexpr int MOD = 998244353;

i64 a[N];

void solve() {
    int n;
    cin >> n;
    priority_queue<i64, vector<i64>, greater<i64>> q;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        q.emplace(a[i]);
    }
    i64 sum = 0;

    while (q.size() > 1) {
        auto p1 = q.top();
        q.pop();
        auto p2 = q.top();
        q.pop();
        sum += p1;
        q.emplace(p1 + p2);
    }
    cout << sum << '\n';

}

signed main() {
    
    FIO;
    int t;
    cin >> t;
    while (t--) solve();

    return 0;
}

/*

  _  _      _     _____    _  _    _ __   _                              
 | \| |    (_)   |_   _|  | || |  | '_ \ | |_      ___     ___    _ _    
 | .` |    | |     | |     \_, |  | .__/ | ' \    / _ \   / _ \  | ' \   
 |_|\_|   _|_|_   _|_|_   _|__/   |_|__  |_||_|   \___/   \___/  |_||_|  
_|"""""|_|"""""|_|"""""|_| """"|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| 
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 

"El Psy Kongroo." -- Hououin Kyoma

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3
1 1 1
4
0 1 0 2
2
100 42

output:

2
1
42

result:

ok 3 number(s): "2 1 42"

Test #2:

score: 0
Accepted
time: 27ms
memory: 3548kb

input:

100000
2
653035426 456936267
2
409660907 250295986
2
347384960 200356123
2
283557883 840123319
2
17610671 987402881
2
136895857 909667348
2
248911778 780375903
2
275329617 285342631
2
561813712 698064200
2
400903421 742043963
2
345893112 519641162
2
14593307 406479738
2
616391850 347632216
2
1973087...

output:

456936267
250295986
200356123
283557883
17610671
136895857
248911778
275329617
561813712
400903421
345893112
14593307
347632216
19730879
421626272
56181583
370600905
308183211
258362299
586922640
40159075
198139063
142754581
51756812
119730671
81065481
143568225
273158312
49357396
14434997
396080587...

result:

ok 100000 numbers

Test #3:

score: -100
Wrong Answer
time: 26ms
memory: 3836kb

input:

10000
17
682602980 427465994 308629394 109001734 104676154 428796022 186854021 449599165 926341494 518520271 848737248 161898549 472666174 717817465 55045664 497142577 155911030
17
175921543 574867131 81827354 668974927 924162354 915237015 544633396 979579177 69438027 7405300 106382140 464417239 180...

output:

12423566762
14198774665
4827602051
455185902
53186501125
3943033222
11143836445
100127402159
38874140457
6669572799
4265974562
6467036407
22419398902
13062171303
8227000490
36795317979
4197118425
7479024482
14837395230
4102958367
35848276348
11824042140
21032634442
1572801098
1238621062
4942166103
1...

result:

wrong answer 1st numbers differ - expected: '6125364442', found: '12423566762'