QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#147408 | #5496. 荷马史诗 | triple321 | 97 | 22ms | 8008kb | C++14 | 1.3kb | 2023-08-23 06:31:15 | 2023-08-25 01:28:47 |
Judging History
answer
// Problem: P4 - Homeric Epics
// Contest: DMOJ - NOI '15
// URL: https://dmoj.ca/problem/noi15p4
// Memory Limit: 512 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define lg long long
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const lg N = 2e5+5;
lg tr[N], par[N];
priority_queue<pair<lg, lg>> pq;
int main()
{
fastio;
lg n, k;
cin >> n >> k;
lg id = n;
while(k > 2 && id%(k-1) != 1)
{
pq.push({0, id});
id++;
}
for(int i = 0; i < n; i++)
{
cin >> tr[i];
pq.push({-tr[i], -i});
}
while(pq.size() > 1)
{
lg s = 0;
for(int i = 0; i < k; i++)
{
lg u = -pq.top().second;
s += tr[u];
pq.pop();
par[u] = id;
}
tr[id] = s;
pq.push({-s, -id});
id++;
}
lg root = -pq.top().second;
lg ans = 0, mxm = 0;
for(int i = 0; i < n; i++)
{
lg idx = i, cur = 0;
while(idx != root)
{
cur++;
idx = par[idx];
}
ans += cur*tr[i];
mxm = max(mxm, cur);
}
cout << ans << '\n' << mxm;
return 0;
}
/*
6
5 2
3 4
0 1
0: 010
1: 011
2: 1
3: 00
0: 002 3
1: 001 3
2: 02 6
3: 000 9
4: 1 9
5: 01 18
*/
詳細信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 5528kb
input:
3 2 1 2 3
output:
9 2
result:
ok Correct Answer.
Test #2:
score: 10
Accepted
time: 0ms
memory: 3632kb
input:
5 2 1 2 1 2 5
output:
23 3
result:
ok Correct Answer.
Test #3:
score: 10
Accepted
time: 1ms
memory: 5584kb
input:
16 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
output:
64 4
result:
ok Correct Answer.
Test #4:
score: 10
Accepted
time: 2ms
memory: 5524kb
input:
1000 2 14595703315 80534380831 17288617047 96364054164 13321445830 86893249112 12443001034 2089068053 30160327449 49676839674 47500435992 33530823897 66417974267 13354465827 58802380258 45331220873 93243099169 60803057858 26327253943 17645598249 50645366634 20814687160 14386178173 62924445593 920727...
output:
481277278083488 19
result:
ok Correct Answer.
Test #5:
score: 10
Accepted
time: 0ms
memory: 5700kb
input:
1000 2 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773123072 58773...
output:
561894565817529 35
result:
ok Correct Answer.
Test #6:
score: 10
Accepted
time: 22ms
memory: 7952kb
input:
100000 2 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 19591041024 195...
output:
32682683660540307 42
result:
ok Correct Answer.
Test #7:
score: 10
Accepted
time: 17ms
memory: 7796kb
input:
100000 2 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 33 ...
output:
55074624 17
result:
ok Correct Answer.
Test #8:
score: 10
Accepted
time: 21ms
memory: 8008kb
input:
100000 2 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 78364164096 783...
output:
130726502977300066 44
result:
ok Correct Answer.
Test #9:
score: 10
Accepted
time: 1ms
memory: 5512kb
input:
7 3 1 1 2 1 2 2 2
output:
20 2
result:
ok Correct Answer.
Test #10:
score: 10
Accepted
time: 1ms
memory: 3640kb
input:
16 3 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98 98
output:
4214 3
result:
ok Correct Answer.
Extra Test:
score: -3
Extra Test Failed : Runtime Error on 3
input:
100000 7 6 6 6 6 24 24 24 24 24 24 24 24 24 24 24 24 312 312 312 312 312 312 2184 2184 2184 2184 2184 2184 2184 2184 2184 2184 2184 2184 28392 28392 28392 28392 28392 28392 198744 198744 198744 198744 198744 198744 198744 198744 198744 198744 198744 198744 2583672 2583672 2583672 2583672 2583672 258...