結果

問題 No.2723 Fortune-telling by Flowers
ユーザー GOTKAKO
提出日時 2024-04-12 21:44:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 816 bytes
コンパイル時間 1,911 ms
コンパイル使用メモリ 198,096 KB
最終ジャッジ日時 2025-02-21 00:14:35
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

vector<pair<char,int>> RLEa(string &s){
    vector<pair<char,int>> ret;
    char back = s.at(0); int streak = 1;
    for(int i=1; i<s.size(); i++){
        if(back == s.at(i)) streak++;
        else{
            ret.push_back({back,streak});
            back = s.at(i); streak = 1;
        }
    }
    ret.push_back({back,streak});
    return ret;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int T; cin >> T;
    while(T--){
        int N; cin >> N;
        string s; cin >> s; s += '-';       
        auto S = RLEa(s);
        int K = 0,P = 0;
        for(auto[c,len] : S){
            if(c == 'P') P++;
            if(c == 'K') K++;
        }

        if(K >= P) cout << "K" << endl;
        else cout << "P" << endl;
    }
}
0