結果

問題 No.1855 Intersected Lines
ユーザー 👑 potato167potato167
提出日時 2022-02-25 23:32:47
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 48 ms / 2,000 ms
コード長 2,054 bytes
コンパイル時間 2,162 ms
コンパイル使用メモリ 206,264 KB
実行使用メモリ 8,824 KB
最終ジャッジ日時 2023-09-16 19:04:52
合計ジャッジ時間 4,964 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 43 ms
5,072 KB
testcase_09 AC 46 ms
7,628 KB
testcase_10 AC 42 ms
5,140 KB
testcase_11 AC 42 ms
7,880 KB
testcase_12 AC 39 ms
5,060 KB
testcase_13 AC 39 ms
4,376 KB
testcase_14 AC 41 ms
5,288 KB
testcase_15 AC 45 ms
8,484 KB
testcase_16 AC 46 ms
8,292 KB
testcase_17 AC 45 ms
7,548 KB
testcase_18 AC 45 ms
8,228 KB
testcase_19 AC 47 ms
7,356 KB
testcase_20 AC 46 ms
8,044 KB
testcase_21 AC 47 ms
7,548 KB
testcase_22 AC 48 ms
7,352 KB
testcase_23 AC 38 ms
8,824 KB
testcase_24 AC 37 ms
7,432 KB
testcase_25 AC 36 ms
7,960 KB
testcase_26 AC 37 ms
7,944 KB
testcase_27 AC 36 ms
7,816 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}


ll jyo(ll x,ll y,ll z){
  ll H=y; //ここから
       ll a=1,b=x%z,c=1;
       while(H>0){
         a*=2;
         if(H%a!=0){
           H-=a/2;
           c*=b;
           c%=z;
         }
        b*=b;
         b%=z;
      } //ここまで
 return c;
}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	ll N,X;
	cin>>N>>X;
	vector<ll> C(2);
	vector<pair<ll,ll>> p;
	int L=-1;
	rep(i,X){
		char c;
		ll a;
		int b=0;
		cin>>c>>a;
		if(c=='R') b=1;
		if(p.size()==0||p[L].first!=b){
			p.push_back({b,a});
			L++;
		}else p[L].second+=a;
		C[b]+=a;
	}
	ll ans=0;
	rep(i,2){
		ll tmp=(C[i]-1)*(C[i]-3);
		tmp=jyo(((tmp%mod)*24ll)%mod,mod-2,mod);
		rep(k,4){
			tmp=(tmp*(C[i]-k))%mod;
		}
		ans+=tmp;
	}
	//cout<<(15ll*ans)%mod<<"\n";
	L++;
	vector<ll> dp(10);
	dp[0]=1,dp[1]=1;
	rep(i,L){
		for(int j=7-p[i].first;j>=0;j-=2){
			dp[(j^1)+2]+=(dp[j]*p[i].second)%mod;
			dp[(j^1)+2]%=mod;
		}
	}
	ans+=(((dp[8]+dp[9])%mod)*jyo((C[0]-1)*(C[1]-1),mod-2,mod))%mod;
	cout<<(ans%mod+mod)%mod<<"\n";
}
0