結果
| 問題 | No.2742 Car Flow |
| コンテスト | |
| ユーザー |
0214sh7
|
| 提出日時 | 2024-04-21 04:10:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 47 ms / 2,000 ms |
| コード長 | 2,661 bytes |
| コンパイル時間 | 2,535 ms |
| コンパイル使用メモリ | 207,976 KB |
| 最終ジャッジ日時 | 2025-02-21 07:46:33 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 50 |
ソースコード
#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
map<pair<ll,ll>,set<ll>> Mp;
void solve(vector<ll> R){
ll N = R.size();
ll sum = 0;
REP(j,N){
sum += R[j];
}
REP(i,10){
// cout << setw(2) << 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);
}
ll Ans = 0;
REP(i,N){
Ans += R[(i+1)%N]*(1-R[i]);
}
// cout << Ans << endl;
Mp[{N,sum}].insert(Ans);
// 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,10){
// REP(j,1<<i){
// vector<ll> s(i,0);
// REP(k,i){s[k]=(j>>k)%2;}
// solve(s);
// }
// }
// rep(i,2,10){
// REP(j,i+1){
// cout << i MM j << ": ";
// for(ll s:Mp[{i,j}]){
// cout << s << " ";
// }
// cout << endl;
// }
// }
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]);
// }
ll Ans = min(one,N-one);
Ans = (Ans*inverse(N))%MOD;
cout << Ans << endl;
return 0;
}
0214sh7