Submission #3473034


Source Code Expand

Copy
#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#define MAX_N 100001
#define INF 2147483647
#define REP(i,n) for(int i=0;i<(int)(n);i++)
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
int dx[4] = {1,0,0,-1};
int dy[4] = {0,1,-1,0};
using namespace std;
typedef long long ll;
struct edge{
  int from,to,cost;
};
typedef vector<vector<edge> > AdjList;
AdjList graph;
typedef pair<int , int> P;
bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}

long long int MOD = 1000000007;
long long int ruiseki[200001];
void ncrset(){
  ruiseki[0] = 1;
  for(int i=1;i<200001;i++){
    ruiseki[i] = (ruiseki[i-1] * i) % MOD;
  }
}

long long int powld(long long int x,long long int n,long long int mod){
  long long int ans = 1;
  while(n > 0){
    if((n&1) == 1){
      ans = (ans*x)  % mod;
    }
    x = (x*x) % mod;
    n >>= 1;
  }
  return ans % mod;
}


int main()
{
  ll N,K,A[100001],res=0;
  cin >> N;
  REP(i,N)cin >> A[i];
  ll sum[100001];
  sum[0] = 0;
  sum[1] = 1;
  for(int i=2;i<=100000;i++){
    sum[i] = (sum[i-1] + powld(i,MOD-2,MOD))%MOD;
  }
 
  ncrset();
  for(int i=1;i<=N;i++){
    res = ((res + (((((ruiseki[N]*(sum[N-i+1]-1))%MOD + ((sum[i])*ruiseki[N])%MOD))%MOD)*A[i-1])%MOD))%MOD;
  }
  cout << res << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

Submission Info

Submission Time
Task B - Removing Blocks
User makss
Language C++14 (GCC 5.4.1)
Score 600
Code Size 2008 Byte
Status
Exec Time 106 ms
Memory 3328 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt
All 600 / 600 sample-01.txt, sample-02.txt, sample-03.txt, sample-01.txt, sample-02.txt, sample-03.txt, subtask01-01.txt, subtask01-02.txt, subtask01-03.txt, subtask01-04.txt, subtask01-05.txt, subtask01-06.txt, subtask01-07.txt, subtask01-08.txt, subtask01-09.txt, subtask01-10.txt, subtask01-11.txt, subtask01-12.txt, subtask01-13.txt
Case Name Status Exec Time Memory
sample-01.txt 61 ms 2560 KB
sample-02.txt 61 ms 2560 KB
sample-03.txt 61 ms 2560 KB
subtask01-01.txt 60 ms 2560 KB
subtask01-02.txt 94 ms 3200 KB
subtask01-03.txt 87 ms 3072 KB
subtask01-04.txt 94 ms 3200 KB
subtask01-05.txt 72 ms 2816 KB
subtask01-06.txt 79 ms 2944 KB
subtask01-07.txt 71 ms 2816 KB
subtask01-08.txt 106 ms 3328 KB
subtask01-09.txt 105 ms 3328 KB
subtask01-10.txt 105 ms 3328 KB
subtask01-11.txt 106 ms 3328 KB
subtask01-12.txt 106 ms 3328 KB
subtask01-13.txt 106 ms 3328 KB