# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
9591 | maniac | Uniting (kriii2_U) | C++98 | 52 ms | 3228 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<cassert>
#include<cstring>
#include<map>
#include<set>
#include<time.h>
#include<algorithm>
#include<stack>
#include<queue>
#include<utility>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<limits>
using namespace std;
#define LL long long
#define mod 1000000007
LL n,re,cnt,add,sum;
priority_queue <LL> q;
map <LL,LL > mp;
long long gcd( long long b, long long s ){
return (s!=0) ? gcd( s, b%s ) : b;
}
void solve(){
scanf("%lld",&n);
cnt = 1;
for(LL i = 1; i <= n; i++){
LL a ;
scanf("%lld",&a);
mp[a] ++;
q.push(-a);
}
if( n == 1){
re = 0;
cnt = 1;
printf("%lld\n%lld\n",re,cnt);
return ;
}
while( !q.empty() ){
LL a,b;
a = -q.top(); q.pop();
b = -q.top(); q.pop();
if( a == b){
cnt *= (mp[a]*(mp[a]-1))%mod;
cnt %=mod;
mp[a]-=2;
}
else{
cnt *= (mp[a]*mp[b])%mod;
cnt%=mod;
cnt *= 2;
cnt %=mod;
mp[a]--;
mp[b]--;
}
re += (a*b);
//re%=mod;
if( !q.empty() ){
q.push( -(a+b) );
mp[a+b]++;
}
}
if( n == 2)
cnt = 2;
else{
cnt = 12;
add = 12;
sum = 8;
for(int i = 4; i<=n; i++){
cnt*=add;
cnt%=mod;
add+=sum;
sum+=2;
add%=mod;
sum%=mod;
}
cnt%=mod;
}
printf("%lld\n%lld\n",re,cnt);
}
int main(){
//freopen("in.txt", "r", stdin);
//freopen("input.txt", "r", stdin);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |