結果

問題 No.1855 Intersected Lines
ユーザー 沙耶花沙耶花
提出日時 2022-02-25 23:19:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 221 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 4,451 ms
コンパイル使用メモリ 275,744 KB
実行使用メモリ 5,624 KB
最終ジャッジ日時 2023-09-16 18:47:49
合計ジャッジ時間 10,002 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 177 ms
4,456 KB
testcase_09 AC 199 ms
5,424 KB
testcase_10 AC 179 ms
4,644 KB
testcase_11 AC 201 ms
5,432 KB
testcase_12 AC 153 ms
4,524 KB
testcase_13 AC 132 ms
4,380 KB
testcase_14 AC 164 ms
4,480 KB
testcase_15 AC 217 ms
5,484 KB
testcase_16 AC 204 ms
5,484 KB
testcase_17 AC 217 ms
5,416 KB
testcase_18 AC 216 ms
5,508 KB
testcase_19 AC 215 ms
5,624 KB
testcase_20 AC 219 ms
5,488 KB
testcase_21 AC 221 ms
5,468 KB
testcase_22 AC 221 ms
5,416 KB
testcase_23 AC 176 ms
5,508 KB
testcase_24 AC 179 ms
5,428 KB
testcase_25 AC 180 ms
5,508 KB
testcase_26 AC 183 ms
5,488 KB
testcase_27 AC 186 ms
5,468 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001

int main(){
	
	int n,x;
	cin>>n>>x;
	
	vector<char> c;
	vector<long long> v;
	rep(i,x){
		char C;
		long long V;
		cin>>C>>V;
		if(c.size()==0 || c.back()!=C){
			c.push_back(C);
			v.push_back(V);
		}
		else{
			v.back() += V;
		}
	}
	mint ans = 0;
	rep(i,2){
		char cc;
		if(i==0)cc = 'B';
		else cc = 'R';
		long long sum = 0LL;
		rep(j,c.size()){
			if(c[j]==cc)sum += v[j];
		}
		if(sum <= 3)continue;
		mint t = sum;
		t *= sum-1;
		t *= sum-2;
		t *= sum-3;
		t /= 24;
		t /= sum-1;
		t /= sum-3;
		ans += t;
	}
	
	map<string,mint> mp;
	mp[""] = 1;
	
	rep(i,c.size()){
		map<string,mint> nmp = mp;
		for(auto a:mp){
			string ss = a.first;
			if(ss.size()>0 && ss.back()==c[i])continue;
			ss += c[i];
			if(ss.size()>=5)continue;
			nmp[ss] += a.second * v[i];
		}
		swap(mp,nmp);
	}
	{
		mint tt = mp["RBRB"] + mp["BRBR"];
		int R = 0,B = 0;
		rep(i,c.size()){
			if(c[i]=='R')R += v[i];
			else B += v[i];
		}
		tt /= R-1;
		tt /= B-1;
		ans += tt;
	}
	
	cout<<ans.val()<<endl;
	
	return 0;
}
0