QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640522#6253. Appeal to the Audience dohoon#WA 16ms12592kbC++17828b2024-10-14 13:56:502024-10-14 13:56:51

Judging History

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

  • [2024-10-14 13:56:51]
  • 评测
  • 测评结果:WA
  • 用时:16ms
  • 内存:12592kb
  • [2024-10-14 13:56:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MXN = 1e5+5;
vector<int> E[MXN];
int num[MXN], cnt[MXN];
void dfs(int x){
    int mxc = -1;
    for(int i : E[x]) {
        dfs(i);
        cnt[num[i]]++;
        if(mxc == -1 || cnt[num[i]]>cnt[num[mxc]]) mxc = num[i];
    }
    if(mxc!=-1) num[x] = mxc;
}
signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int n, k; cin >> n >> k;
    vector<int> v(k);
    for(auto &i : v) cin >> i;
    sort(v.begin(),v.end());
    for(int i=1;i<n;i++){
        int p; cin >> p;
        E[p].push_back(i);
    }
    int s = 0;
    for(int i=0;i<n;i++) if(E[i].size()==0)
        num[i] = s++;
    dfs(0);
    sort(cnt,cnt+k);
    int ans = 0;
    for(int i=0;i<k;i++) {
        ans += v[i]*cnt[i];
    }
    cout << ans;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 7200kb

input:

5 3
5 4 3
0
0
1
1

output:

17

result:

ok single line: '17'

Test #2:

score: 0
Accepted
time: 1ms
memory: 6212kb

input:

11 7
30 5 15 1 3 100 50
0
0
1
0
2
5
2
5
5
1

output:

454

result:

ok single line: '454'

Test #3:

score: 0
Accepted
time: 14ms
memory: 12592kb

input:

99999 50000
776281622 281552176 560818893 743574034 28371581 29065388 861522831 399277410 127891403 337521653 333045937 201722127 532376484 866178821 488930207 533328467 280762095 777881963 698720876 926181033 678638871 483709812 805740065 609341704 534943664 598002301 497944186 842902577 127602924 ...

output:

74974456112141

result:

ok single line: '74974456112141'

Test #4:

score: -100
Wrong Answer
time: 16ms
memory: 8640kb

input:

99999 50000
736607525 495413566 242981382 180522920 383406277 904059123 14931844 827592097 658904858 421611178 971164496 29212802 260869571 599952745 698370584 221201211 757581076 82619003 133169367 222890026 743399318 195978288 931589194 603744278 535433139 56057976 986499544 9144818 148181561 4159...

output:

66676540245138

result:

wrong answer 1st lines differ - expected: '66676571833058', found: '66676540245138'