結果

問題 No.1855 Intersected Lines
ユーザー kai4096_don
提出日時 2022-02-25 23:48:26
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 2,956 bytes
コンパイル時間 3,367 ms
コンパイル使用メモリ 234,328 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-03 18:49:11
合計ジャッジ時間 6,918 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//const long nPrime = 1000000007;
const long nPrime = 998244353;
typedef long long ll;
const long long nMod = nPrime;
class ModInt {
public:
long long x;
public:
ModInt(long long x=0) : x((x%nMod+nMod)%nMod) {}
ModInt operator-() const {
return ModInt(-x);
}
ModInt& operator+=(const ModInt& a) {
if ((x += a.x) >= nMod) x -= nMod;
return *this;
}
ModInt& operator-=(const ModInt& a) {
if ((x += nMod-a.x) >= nMod) x -= nMod;
return *this;
}
ModInt& operator*=(const ModInt& a) {
(x *= a.x) %= nMod;
return *this;
}
ModInt operator+(const ModInt& a) const {
ModInt res(*this);
return res+=a;
}
ModInt operator-(const ModInt& a) const {
ModInt res(*this);
return res-=a;
}
ModInt operator*(const ModInt& a) const {
ModInt res(*this);
return res*=a;
}
ModInt Pow(long long t) const {
if (!t) return 1;
ModInt a = Pow(t>>1);
a *= a;
if (t&1) a *= *this;
return a;
}
// for prime nMod
ModInt Inv() const {
return Pow(nMod-2);
}
ModInt& operator/=(const ModInt& a) {
return (*this) *= a.Inv();
}
ModInt operator/(const ModInt& a) const {
ModInt res(*this);
return res/=a;
}
friend ostream& operator<<(ostream& os, const ModInt& m){
os << m.x;
return os;
}
};
void MakeTable(vector<ModInt> &viInv, vector<ModInt> &viFctr,
vector<ModInt> &viFctrInv, bool bUseFctr = false,
const long nTableSize = 1000000){
viInv.resize(nTableSize+1, 1);
for(long i = 2; i < nTableSize+1; i++){
long p = nPrime/i;
long q = nPrime%i;
viInv[i] = -p;
viInv[i] *= viInv[q];
}
if(!bUseFctr){
return;
}
viFctr.resize(nTableSize+1, 1);
viFctrInv.resize(nTableSize+1, 1);
for(long i = 1; i < nTableSize+1; i++){
viFctr[i] = viFctr[i-1] * i;
}
viFctrInv[nTableSize] /= viFctr[nTableSize];
for(long i = nTableSize; i >= 1; i--){
viFctrInv[i-1] = viFctrInv[i]*i;
}
}
int main() {
long n,x;
cin >> n >> x;
ModInt B=0,R=0,BR=0,RB=0,BRB=0,RBR=0,BRBR=0,RBRB=0;
for(long i = 0; i < x; i++){
string s;
cin >> s;
long v;
cin >> v;
if(s[0] == 'B'){
B+=v;
RB += R*v;
BRB += BR*v;
RBRB += RBR*v;
} else {
R+=v;
BR += B*v;
RBR += RB*v;
BRBR += BRB*v;
}
}
ModInt nAns = 0;
if(R.x >= 2 && B.x >= 2){
nAns += (RBRB+BRBR)/(R-1)/(B-1);
}
nAns += B*(B-ModInt(2))/24;
nAns += R*(R-ModInt(2))/24;
cout << nAns << endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0