Submission #9517

# Submission time Handle Problem Language Result Execution time Memory
9517 2014-09-28T06:59:48 Z maniac Uniting (kriii2_U) C++
1 / 4
48 ms 3228 KB
#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;
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 *= 2;
			cnt %=mod;
			mp[a]--;
			mp[b]--;
		}
		re += (a*b);
		//re%=mod;
		if( !q.empty() ){
			q.push( -(a+b) );
			mp[a+b]++;
		}
	}
	printf("%lld\n%lld\n",re,cnt);
}

int main(){
	
	solve();

}
# Verdict Execution time Memory Grader output
1 Partially correct 0 ms 1680 KB Output is partially correct
2 Partially correct 0 ms 1680 KB Output is partially correct
3 Partially correct 0 ms 1680 KB Output is partially correct
4 Partially correct 0 ms 1680 KB Output is partially correct
5 Partially correct 0 ms 1680 KB Output is partially correct
6 Partially correct 0 ms 1680 KB Output is partially correct
7 Partially correct 0 ms 1680 KB Output is partially correct
8 Partially correct 0 ms 1680 KB Output is partially correct
9 Partially correct 0 ms 1680 KB Output is partially correct
10 Partially correct 0 ms 1680 KB Output is partially correct
11 Partially correct 0 ms 1812 KB Output is partially correct
12 Partially correct 0 ms 1812 KB Output is partially correct
13 Partially correct 4 ms 1812 KB Output is partially correct
14 Partially correct 0 ms 1812 KB Output is partially correct
15 Partially correct 4 ms 1812 KB Output is partially correct
16 Partially correct 4 ms 1812 KB Output is partially correct
17 Partially correct 4 ms 1812 KB Output is partially correct
18 Partially correct 4 ms 1812 KB Output is partially correct
19 Partially correct 4 ms 1812 KB Output is partially correct
20 Partially correct 8 ms 1812 KB Output is partially correct
21 Partially correct 8 ms 2068 KB Output is partially correct
22 Partially correct 8 ms 2068 KB Output is partially correct
23 Partially correct 8 ms 2068 KB Output is partially correct
24 Partially correct 12 ms 2068 KB Output is partially correct
25 Partially correct 12 ms 2068 KB Output is partially correct
26 Partially correct 8 ms 2068 KB Output is partially correct
27 Partially correct 12 ms 2068 KB Output is partially correct
28 Partially correct 16 ms 2068 KB Output is partially correct
29 Partially correct 12 ms 2460 KB Output is partially correct
30 Partially correct 16 ms 2460 KB Output is partially correct
31 Partially correct 16 ms 2460 KB Output is partially correct
32 Partially correct 20 ms 2460 KB Output is partially correct
33 Partially correct 16 ms 2460 KB Output is partially correct
34 Partially correct 24 ms 2460 KB Output is partially correct
35 Partially correct 24 ms 2460 KB Output is partially correct
36 Partially correct 24 ms 2460 KB Output is partially correct
37 Partially correct 28 ms 2460 KB Output is partially correct
38 Partially correct 28 ms 2460 KB Output is partially correct
39 Partially correct 28 ms 2460 KB Output is partially correct
40 Partially correct 32 ms 2460 KB Output is partially correct
41 Partially correct 32 ms 3228 KB Output is partially correct
42 Partially correct 36 ms 3228 KB Output is partially correct
43 Partially correct 36 ms 3228 KB Output is partially correct
44 Partially correct 40 ms 3228 KB Output is partially correct
45 Partially correct 40 ms 3228 KB Output is partially correct
46 Partially correct 36 ms 3228 KB Output is partially correct
47 Partially correct 36 ms 3228 KB Output is partially correct
48 Partially correct 44 ms 3228 KB Output is partially correct
49 Partially correct 48 ms 3228 KB Output is partially correct
50 Partially correct 40 ms 3228 KB Output is partially correct