# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
9794 | kkjjkk | Uniting (kriii2_U) | C++98 | 16 ms | 4800 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <cstdio>
using namespace std;
long long h[100005];
long long f[100005], m = 1000000007, nn[100005], tw[100005];
int main()
{
int n;
scanf("%d", &n);
for(int i = 0; i < n; i++) scanf("%lld", &h[i]);
f[1] = 1;
for(int i = 2; i < 100005; i++) { f[i] = f[i - 1] * i; f[i] %= m; }
tw[1] = 2;
for(int i = 2; i < 100005; i++) { tw[i] = tw[i - 1] * 2; tw[i] %= m; }//printf("%lld\n", tw[i]); }
if(n == 1) { printf("0\n"); printf("1"); }
else if(n == 2) { printf("%lld\n", h[0] * h[1]); printf("2"); }
else {
//sort(h, h + n);
long long a = h[0] + h[1];
long long b = h[0] * h[1];
long long c, d;//, m = 1000000007;
for(int i = 2; i < n; i++) {
/*c = a + h[i];
d = ((a % m) * h[i]) % m; //d %= ;
a = c;
b = ((b % m) + (d % m)) % m; //b %= 1000000007;*/
c = a * h[i]; //c %= m;
a += h[i]; b += c; //b %= m;
}
printf("%lld\n", b);
printf("%lld", (f[n] * tw[n - 2]) % m);
/*int t = 0;
nn[0] = 1; t++;
for(int i = 1; i < n; i++) {
if(h[i] != h[i - 1]) { nn[t] = 1; t++; }
else { nn[t - 1]++; }
}
//for(int i = 0; i < t; i++) { printf("%d ", nn[i]); } printf("\n");
if(t == 1) printf("%lld", f[nn[0]]);
else if(t == 2) printf("%lld", f[nn[0] + nn[1]]);
else {
long long s = f[nn[0] + nn[1]];
for(int i = 2; i < t; i++) { s *= f[nn[i]]; s %= m; }
printf("%lld", s);
}*/
}
//printf("-1");
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |