General

# Author Problem Lang Verdict Time Memory Sent Judged
35370185 Practice:
sansae
938E - 22 GNU C++14 Accepted 2808 ms 13560 KB 2018-02-16 20:17:40 2018-02-17 16:56:10

→ Source
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <vector>
#define mod 1000000007
using namespace std;

void codeforces_edu38_A(){
int n;
cin>>n;
char c[n];
scanf("%s", c);
int ccc=0;
for(int i=0;i<n;i++){
if(c[i]!='a'&&c[i]!='e'&&c[i]!='i'&&c[i]!='o'&&c[i]!='u'&&c[i]!='y'){
printf("%c", c[i]);
ccc=0;
}
else{
if(ccc==0){
printf("%c", c[i]);
ccc=1;
}
}
}
}

void codeforces_edu38_B(){
int n;
cin>>n;
int a[n];
int min=1000000000;
for(int i=0;i<n;i++){
cin>>a[i];
if(abs(1000001-2*a[i])<min){
min=abs(1000001-2*a[i]);
}
}
printf("%d", (1000001-2-min)/2);
}

int isSquare(int x){
int t=(int)floor(sqrt((float)x))-1;
if(x==t*t||x==(t+1)*(t+1)||x==(t+2)*(t+2)){
return 1;
}
return -1;
}

int findroot(int x){
int t=(int)floor(sqrt((float)x))-1;
for(int y=t;y<t+4;y++){
if(x==y*y){
return y;
}
}
return 0;
}

void codeforces_edu38_C(){
int t;
cin>>t;
for(int i=0;i<t;i++){
int x;
cin>>x;
int nn=-1;
int mm=-1;
for(int n=(int)floor(sqrt((float)x))-1;n<=(int)ceil(sqrt((float)4.0/3.0*(float)x))+1;n++){
if(isSquare(n*n-x)==1){
int u=findroot(n*n-x);
if(u!=0){
for(int m=n/(u+1)-1;m<n/u+1;m++){
if(m!=0){
if(n/m==u){
nn=n;
mm=m;
break;
break;
}}
}
}
}
}
if(nn==-1 && mm==-1){
printf("-1\n");
}
else{
printf("%d %d\n", nn, mm);
}
}
}

void codeforces_edu38_D(){

}

int power(int a, unsigned int b)
{
if (b == 0){
return 1;
}
int p;
p=power(a, b/2)%(mod);
p=((long long)p*(long long)p)%((long long)mod);
return (b%2 == 0)? (long long)p : ((long long)a * (long long)p) % (long long)mod;
}

int gcd(int a, int b)
{
if (a == 0)
return b;
return gcd(b%a, a);
}

int modInverse(int a, int m)
{
int g = gcd(a, m);
if (g != 1)
return 0;
else
{
return power(a, m-2);
}
}

int compare(const void *a, const void *b)    // 오름차순 비교 함수 구현
{
int num1 = *(int *)a;    // void 포인터를 int 포인터로 변환한 뒤 역참조하여 값을 가져옴
int num2 = *(int *)b;    // void 포인터를 int 포인터로 변환한 뒤 역참조하여 값을 가져옴

if (num1<num2)    // a가 b보다 작을 때는
return -1;      // -1 반환

if (num1>num2)    // a가 b보다 클 때는
return 1;       // 1 반환

return 0;    // a와 b가 같을 때는 0 반환
}

int fac(int n, int c){
long long res=1;
for(int i=1;i<=n;i++){
if(i!=n-c){
res=(res*i)%mod;
}
}
return (int)res;
}

void codeforces_edu38_E(){
int n;
cin>>n;
long long facn=1;
for(int i=1;i<=n;i++){
facn=(facn*i)%mod;
}
int a[n];
int b[n];
int c[n];
for(int i=0;i<n;i++){
cin>>a[i];
b[i]=0;
c[i]=0;
}
qsort(a, sizeof(a)/sizeof(int), sizeof(int), compare); //오름차순됨
int index=0;
int current=0;
int cn=-1;
for(int i=0;i<n;i++){
if(current==0){
b[index]=a[i];
cn=a[i];
c[index]++;
current=1;
}
else{
if(a[i]==cn){
c[index]++;
}
else{
index++;
cn=a[i];
b[index]=a[i];
c[index]++;
}
}
}
index++; //b[i]에는 숫자, c[i]에는 개수, b[i] 오름차순. 0~index-1까지 있음
long long ans=0;
int sumc=0;
for(int i=0;i<index-1;i++){
ans=(ans+((((long long)(((long long)b[i]*c[i])%mod)*facn))%mod)*modInverse(n-sumc, mod))%mod;
sumc+=c[i];
}
printf("%d", (int)ans);
}

void codeforces_edu38_F(){

}

void codeforces_edu38_G(){

}

int main() {
//	codeforces_edu38_A();
//	codeforces_edu38_B();
//	codeforces_edu38_C();
//	codeforces_edu38_D();
codeforces_edu38_E();
//	codeforces_edu38_F();
//	codeforces_edu38_G();
return 0;
}

?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
?
?
?