結果

問題 No.2742 Car Flow
ユーザー 0214sh7
提出日時 2024-04-21 03:50:31
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 2,236 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 195,652 KB
最終ジャッジ日時 2025-02-21 07:45:58
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 40 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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