結果

問題 No.2524 Stripes
ユーザー MasKoaTSMasKoaTS
提出日時 2023-09-27 23:53:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 999 ms / 7,000 ms
コード長 2,522 bytes
コンパイル時間 4,643 ms
コンパイル使用メモリ 255,844 KB
実行使用メモリ 37,428 KB
最終ジャッジ日時 2023-09-27 23:53:20
合計ジャッジ時間 14,575 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,356 KB
testcase_01 AC 1 ms
4,356 KB
testcase_02 AC 2 ms
4,356 KB
testcase_03 AC 534 ms
23,664 KB
testcase_04 AC 18 ms
4,416 KB
testcase_05 AC 269 ms
15,592 KB
testcase_06 AC 503 ms
23,384 KB
testcase_07 AC 784 ms
34,300 KB
testcase_08 AC 767 ms
34,876 KB
testcase_09 AC 143 ms
9,928 KB
testcase_10 AC 423 ms
20,420 KB
testcase_11 AC 16 ms
4,356 KB
testcase_12 AC 112 ms
8,500 KB
testcase_13 AC 878 ms
36,868 KB
testcase_14 AC 880 ms
37,428 KB
testcase_15 AC 896 ms
36,988 KB
testcase_16 AC 999 ms
37,296 KB
testcase_17 AC 689 ms
36,452 KB
testcase_18 AC 2 ms
4,356 KB
testcase_19 AC 1 ms
4,356 KB
testcase_20 AC 2 ms
4,352 KB
testcase_21 AC 2 ms
4,352 KB
testcase_22 AC 2 ms
4,356 KB
testcase_23 AC 2 ms
4,356 KB
testcase_24 AC 2 ms
4,352 KB
testcase_25 AC 2 ms
4,352 KB
testcase_26 AC 2 ms
4,356 KB
testcase_27 AC 2 ms
4,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/convolution>
#define MOD 998244353ll
using namespace std;
using namespace atcoder;
using ll = long long;


struct Vector2 {
	vector<ll> v1;
	vector<ll> v2;

	Vector2(void) {
        
	}

	Vector2(vector<ll> v1, vector<ll> v2) {
		this->v1 = v1;
		this->v2 = v2;
	}
};


ll n;
vector<ll> operator*(const vector<ll>& left, const vector<ll>& right){
    vector<ll> ret = convolution<MOD>(left, right);
    while(ret.size() > n + 1){
        ret.pop_back();
    }
    return ret;
}

vector<ll> operator+(const vector<ll>& left, const vector<ll>& right){
    vector<ll> ret(max(left.size(), right.size()));
    for(int i = 0; i < left.size(); ++i){
        ret[i] += left[i];
    }
    for(int i = 0; i < right.size(); ++i){
        ret[i] += right[i];
        ret[i] %= MOD;
    }
    return ret;
}


struct Matrix22 {
    vector<ll> v11, v12, v21, v22;

    Matrix22(void) {
        
	}

	Matrix22(vector<ll> v11, vector<ll> v12, vector<ll> v21, vector<ll> v22) {
		this->v11 = v11;
        this->v12 = v12;
        this->v21 = v21;
        this->v22 = v22;
	}

	Matrix22 operator*(const Matrix22 other) const {
		return Matrix22((this->v11 * other.v11) + (this->v12 * other.v21),
            (this->v11 * other.v12) + (this->v12 * other.v22),
            (this->v21 * other.v11) + (this->v22 * other.v21),
            (this->v21 * other.v12) + (this->v22 * other.v22));
	}

    Vector2 operator*(const Vector2 other) const {
        return Vector2((this->v11 * other.v1) + (this->v12 * other.v2),
            (this->v21 * other.v1) + (this->v22 * other.v2));
    }
};


int main(){
    cin >> n;
    string s;  cin >> s;

    vector<Matrix22> M(n, Matrix22());
    for(int i = 0; i < n; ++i){
        if(s[i] == 'R'){
            M[i] = Matrix22({1}, {0, 1},
                {0}, {1});
        }
        else{
            M[i] = Matrix22({1}, {0},
                {0, 1}, {1});
        }
    }

    Vector2 v_init({1}, {1});
    while(M.size() > 1){
        vector<Matrix22> M_next = {};
        for(int i = 0; i < M.size(); i += 2){
            if(i == M.size() - 1){
                M_next.push_back(M[i]);
                continue;
            }
            M_next.push_back(M[i + 1] * M[i]);
        }
        M = M_next;
    }

    Vector2 v = M[0] * v_init;
    vector<ll> ans = v.v1 + v.v2;
    for(int i = 1; i < n + 1; ++i){
        if(i >= ans.size()){
            cout << 0 << endl;
            continue;
        }
        cout << ans[i] << endl;
    }

    return 0;
}
0