Submission #36276866


Source Code Expand

#pragma GCC target("arch=skylake-avx512") //アーキテクチャーの指定
#pragma GCC optimize("O3") //03最適化
#include <stdio.h>
using ll = long long;
#define MOD 998244353
#define MAX 200001


int main(){
    //inv[i] = (mod上のiの逆数)
    int inv[MAX]{1, 1};
    for(int i = 2; i < MAX; i++){
        inv[i] = MOD - (ll(MOD / i) * inv[MOD % i] % MOD);
    }

    //入力
    int N;
    scanf("%d", &N);
    int A[N + 1]{};
    for(int i = 1; i <= N; i++){
        scanf("%d", A + i);
    }

    //公式解説におけるmax(Ai, Aj)の総和
    ll sum_all = 0;
    //公式解説の解法1
    for(int K = 1; K <= N; K++){
        //max(Ai, AK)の総和を愚直に計算
        ll sum_temp = 0;
        for(int i = 1; i < K; i++){
            sum_temp += (A[i] > A[K] ? A[i] : A[K]);
        }
        //max(Ai, Aj)の総和を更新
        sum_all = (sum_all + sum_temp * 2 + A[K]) % MOD;
        //Kの逆数を2回かけて答えを求める
        int ans = sum_all * inv[K] % MOD * inv[K] % MOD;
        printf("%d\n", ans);
    }

    return 0;
}

Submission Info

Submission Time
Task F - Double Chance
User math_hiyoko
Language C++ (GCC 9.2.1)
Score 500
Code Size 1115 Byte
Status AC
Exec Time 1668 ms
Memory 3852 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:18:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   18 |     scanf("%d", &N);
      |     ~~~~~^~~~~~~~~~
./Main.cpp:21:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   21 |         scanf("%d", A + i);
      |         ~~~~~^~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 30
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 6 ms 2440 KiB
example_01.txt AC 4 ms 2436 KiB
hand_00.txt AC 1570 ms 3280 KiB
hand_01.txt AC 1563 ms 3212 KiB
hand_02.txt AC 1616 ms 3824 KiB
hand_03.txt AC 1585 ms 3828 KiB
hand_04.txt AC 5 ms 2408 KiB
hand_05.txt AC 6 ms 2436 KiB
hand_06.txt AC 3 ms 2484 KiB
hand_07.txt AC 3 ms 2448 KiB
random_00.txt AC 1586 ms 3748 KiB
random_01.txt AC 1577 ms 3828 KiB
random_02.txt AC 1577 ms 3804 KiB
random_03.txt AC 1573 ms 3840 KiB
random_04.txt AC 1641 ms 3796 KiB
random_05.txt AC 1573 ms 3828 KiB
random_06.txt AC 1612 ms 3772 KiB
random_07.txt AC 1585 ms 3800 KiB
random_08.txt AC 1618 ms 3828 KiB
random_09.txt AC 1584 ms 3832 KiB
random_10.txt AC 1587 ms 3828 KiB
random_11.txt AC 1668 ms 3800 KiB
random_12.txt AC 1591 ms 3852 KiB
random_13.txt AC 1619 ms 3820 KiB
random_14.txt AC 1575 ms 3824 KiB
random_15.txt AC 1581 ms 3796 KiB
random_16.txt AC 1601 ms 3824 KiB
random_17.txt AC 1581 ms 3836 KiB
random_18.txt AC 1591 ms 3820 KiB
random_19.txt AC 1605 ms 3852 KiB