| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 8409 | cki86201 | Uniting (kriii2_U) | C++98 | 0 ms | 40268 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<stdio.h>
#include<queue>
using namespace std;
#define ll long long
#define MOD 1000000007
int a[10000001];
ll ans[2];
priority_queue <int> pq;
int main()
{
// freopen("input.txt","r",stdin);
int n;scanf("%d",&n);
int i;
for(i=0;i<n;i++){
int x;scanf("%d",&x);a[x]++;pq.push(-x);
}
for(i=1;i<n;i++){
int t1 = -pq.top();pq.pop();
int t2 = -pq.top();pq.pop();
if(t1 != t2)ans[1] += (ll)a[t1]*a[t2]*2;
else ans[1] += (ll)a[t1]*(a[t1]-1);
ans[1] %= MOD;
a[t1]--, a[t2]--, a[t1+t2]++;
pq.push(-t1-t2);
ans[0] += t1*t2;
}
printf("%lld\n%lld",ans[0],ans[1]);
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
