結果

問題 No.2742 Car Flow
ユーザー 0214sh70214sh7
提出日時 2024-04-21 03:50:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,236 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 195,976 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 03:50:36
合計ジャッジ時間 4,821 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
5,248 KB
testcase_01 AC 32 ms
5,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 35 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 35 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 33 ms
5,376 KB
testcase_10 AC 25 ms
5,376 KB
testcase_11 AC 25 ms
5,376 KB
testcase_12 AC 22 ms
5,376 KB
testcase_13 AC 16 ms
5,376 KB
testcase_14 AC 15 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 32 ms
5,376 KB
testcase_17 AC 31 ms
5,376 KB
testcase_18 AC 4 ms
5,376 KB
testcase_19 WA -
testcase_20 AC 11 ms
5,376 KB
testcase_21 AC 9 ms
5,376 KB
testcase_22 AC 25 ms
5,376 KB
testcase_23 AC 30 ms
5,376 KB
testcase_24 AC 17 ms
5,376 KB
testcase_25 AC 29 ms
5,376 KB
testcase_26 WA -
testcase_27 AC 11 ms
5,376 KB
testcase_28 AC 13 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 WA -
testcase_31 AC 9 ms
5,376 KB
testcase_32 AC 28 ms
5,376 KB
testcase_33 AC 26 ms
5,376 KB
testcase_34 AC 14 ms
5,376 KB
testcase_35 AC 9 ms
5,376 KB
testcase_36 AC 3 ms
5,376 KB
testcase_37 AC 11 ms
5,376 KB
testcase_38 AC 27 ms
5,376 KB
testcase_39 AC 6 ms
5,376 KB
testcase_40 AC 1 ms
5,376 KB
testcase_41 AC 2 ms
5,376 KB
testcase_42 AC 2 ms
5,376 KB
testcase_43 WA -
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 1 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,376 KB
testcase_48 AC 1 ms
5,376 KB
testcase_49 AC 1 ms
5,376 KB
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> PP;
// #define MOD 1000000007
#define MOD 998244353
#define INF 2305843009213693951
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(ll i=0;i<(n);++i)
#define OREP(i,n) for(ll i=1;i<=(n);++i)
#define RREP(i,n) for(ll i=(n)-1;i>=0;--i)
#define ORREP(i,n) for(ll i=(n);i>=1;--i)
#define rep(i,a,b) for(ll i=(a);i<=(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define GOODBYE do { cout << "-1" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug true
#define debug2 false

// void solve(vector<ll> R){
//     ll N = R.size();
//     ll sum = 0;
//     REP(j,N){
//         sum += R[j];
//     }
    
//     REP(i,10){
//         cout << i << ": ";
//         REP(j,N){cout << R[j] << " ";}cout << endl;
        
//         vector<ll> tmp(N,0);
//         REP(j,N){
//             if(R[j]==0 && R[(j-1+N)%N]==1)tmp[j] = 1;
//             if(R[j]==1 && R[(j+1+N)%N]==1)tmp[j] = 1;
//         }
        
//         swap(R,tmp);
        
//         ll num = 0;
//         REP(j,N){
//             num += R[j];
//         }
        
//         assert(sum==num);
        
//     }
//     cout << endl;
// }

long long inverse(long long b){
    // Copyright (c) 2023 0214sh7
    // https://github.com/0214sh7/library/
    long long r=1,e=MOD-2;
    while(e){
        if(e&1){
            r=(r*b)%MOD;
        }
        b=(b*b)%MOD;
        e >>=1;
    }
    return r;
}

int main(void){
    //cin.tie(nullptr);
    //ios::sync_with_stdio(false);

    // rep(i,2,6){
    //     REP(j,1<<i){
    //         vector<ll> s(i,0);
    //         REP(k,i){s[k]=(j>>k)%2;}
    //         solve(s);
    //     }
    // }
    
    ll N;
    cin >> N;
    ll one = 0;
    REP(i,N){
        ll a;
        cin >> a;
        if(a==1)one++;
    }
    
    vector<ll> B(N,0);
    REP(i,min(one,N/2)){
        B[2*i] = 1;
    }
    REP(i,min(one-N/2,(N+1)/2)){
        B[min(2*i+1,N-1)] = 1;
    }
    
    ll Ans = 0;
    REP(i,N){
        Ans += B[(i+1)%N]*(1-B[i]);
    }

    
    Ans = (Ans*inverse(N))%MOD;
    cout << Ans << endl;
    
    return 0;
    
}
0