Submission #3401177

Source Code Expand

Copy
#include <bits/stdc++.h>
using namespace std;

const int64_t MOD = 1e9+7;

int64_t extgcd(int64_t a, int64_t b, int64_t& x, int64_t& y){
    int64_t d = a;
    if(b != 0){
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    }else{
        x = 1; y = 0;
    }
    return d;
}

int64_t mod_inv(int64_t a){
    int64_t x, y;
    extgcd(a, MOD, x, y);
    return (MOD + x%MOD) % MOD;
}

void add(int64_t& a, int64_t b){
    a = (a+b+MOD) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int main(){
    int i, j, k;
    int N;
    const int MAX = 100001;
    cin >> N;
    int64_t A[MAX];
    for(i=1; i<=N; i++) scanf("%lld", &A[i]);

    int64_t invsum[MAX];
    invsum[0] = 0;
    for(i=1; i<=N; i++){
        invsum[i] = (invsum[i-1] + mod_inv(i)) % MOD;
    }

    int64_t ans = 0;
    for(i=1; i<=N; i++){
        add(ans, A[i] * (invsum[i] + invsum[N+1-i] - 1) % MOD);
    }
    for(i=2; i<=N; i++) mul(ans, i);
    cout << ans << endl;
    return 0;
}

Submission Info

Submission Time
Task B - Removing Blocks
User betrue12
Language C++14 (GCC 5.4.1)
Score 600
Code Size 1030 Byte
Status
Exec Time 33 ms
Memory 1792 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:36:44: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘int64_t* {aka long int*}’ [-Wformat=]
     for(i=1; i<=N; i++) scanf("%lld", &A[i]);
                                            ^
./Main.cpp:36:45: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     for(i=1; i<=N; i++) scanf("%lld", &A[i]);
                                             ^

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 1 ms 256 KB
sample-02.txt 1 ms 256 KB
sample-03.txt 1 ms 256 KB
subtask01-01.txt 1 ms 256 KB
subtask01-02.txt 25 ms 1408 KB
subtask01-03.txt 19 ms 1152 KB
subtask01-04.txt 24 ms 1408 KB
subtask01-05.txt 8 ms 640 KB
subtask01-06.txt 13 ms 896 KB
subtask01-07.txt 8 ms 640 KB
subtask01-08.txt 33 ms 1792 KB
subtask01-09.txt 33 ms 1792 KB
subtask01-10.txt 33 ms 1792 KB
subtask01-11.txt 33 ms 1792 KB
subtask01-12.txt 33 ms 1792 KB
subtask01-13.txt 33 ms 1792 KB