#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();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1680 KB |
Output is correct |
2 |
Correct |
0 ms |
1680 KB |
Output is correct |
3 |
Correct |
0 ms |
1680 KB |
Output is correct |
4 |
Correct |
0 ms |
1680 KB |
Output is correct |
5 |
Correct |
0 ms |
1680 KB |
Output is correct |
6 |
Correct |
0 ms |
1680 KB |
Output is correct |
7 |
Correct |
0 ms |
1680 KB |
Output is correct |
8 |
Correct |
0 ms |
1680 KB |
Output is correct |
9 |
Correct |
0 ms |
1680 KB |
Output is correct |
10 |
Correct |
0 ms |
1680 KB |
Output is correct |
11 |
Correct |
0 ms |
1812 KB |
Output is correct |
12 |
Correct |
0 ms |
1812 KB |
Output is correct |
13 |
Correct |
4 ms |
1812 KB |
Output is correct |
14 |
Correct |
0 ms |
1812 KB |
Output is correct |
15 |
Correct |
4 ms |
1812 KB |
Output is correct |
16 |
Correct |
4 ms |
1812 KB |
Output is correct |
17 |
Correct |
4 ms |
1812 KB |
Output is correct |
18 |
Correct |
0 ms |
1812 KB |
Output is correct |
19 |
Correct |
8 ms |
1812 KB |
Output is correct |
20 |
Correct |
8 ms |
1812 KB |
Output is correct |
21 |
Correct |
8 ms |
2068 KB |
Output is correct |
22 |
Correct |
8 ms |
2068 KB |
Output is correct |
23 |
Correct |
12 ms |
2068 KB |
Output is correct |
24 |
Correct |
12 ms |
2068 KB |
Output is correct |
25 |
Correct |
12 ms |
2068 KB |
Output is correct |
26 |
Correct |
12 ms |
2068 KB |
Output is correct |
27 |
Correct |
12 ms |
2068 KB |
Output is correct |
28 |
Correct |
16 ms |
2068 KB |
Output is correct |
29 |
Correct |
16 ms |
2460 KB |
Output is correct |
30 |
Correct |
12 ms |
2460 KB |
Output is correct |
31 |
Correct |
20 ms |
2460 KB |
Output is correct |
32 |
Correct |
20 ms |
2460 KB |
Output is correct |
33 |
Correct |
16 ms |
2460 KB |
Output is correct |
34 |
Correct |
24 ms |
2460 KB |
Output is correct |
35 |
Correct |
24 ms |
2460 KB |
Output is correct |
36 |
Correct |
24 ms |
2460 KB |
Output is correct |
37 |
Correct |
28 ms |
2460 KB |
Output is correct |
38 |
Correct |
24 ms |
2460 KB |
Output is correct |
39 |
Correct |
32 ms |
2460 KB |
Output is correct |
40 |
Correct |
32 ms |
2460 KB |
Output is correct |
41 |
Correct |
36 ms |
3228 KB |
Output is correct |
42 |
Correct |
36 ms |
3228 KB |
Output is correct |
43 |
Correct |
36 ms |
3228 KB |
Output is correct |
44 |
Correct |
40 ms |
3228 KB |
Output is correct |
45 |
Correct |
36 ms |
3228 KB |
Output is correct |
46 |
Correct |
36 ms |
3228 KB |
Output is correct |
47 |
Correct |
36 ms |
3228 KB |
Output is correct |
48 |
Correct |
48 ms |
3228 KB |
Output is correct |
49 |
Correct |
48 ms |
3228 KB |
Output is correct |
50 |
Correct |
52 ms |
3228 KB |
Output is correct |