結果

問題 No.2723 Fortune-telling by Flowers
ユーザー anago-pieanago-pie
提出日時 2024-09-25 02:13:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 184 ms / 2,000 ms
コード長 3,432 bytes
コンパイル時間 2,195 ms
コンパイル使用メモリ 215,312 KB
実行使用メモリ 9,916 KB
最終ジャッジ日時 2024-09-25 02:13:42
合計ジャッジ時間 3,617 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 8 ms
6,812 KB
testcase_02 AC 43 ms
6,940 KB
testcase_03 AC 168 ms
6,944 KB
testcase_04 AC 184 ms
6,940 KB
testcase_05 AC 14 ms
6,940 KB
testcase_06 AC 13 ms
6,944 KB
testcase_07 AC 29 ms
9,916 KB
testcase_08 AC 29 ms
9,792 KB
testcase_09 AC 43 ms
6,940 KB
testcase_10 AC 28 ms
6,940 KB
testcase_11 AC 25 ms
6,944 KB
testcase_12 AC 26 ms
6,940 KB
testcase_13 AC 30 ms
7,492 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define debug 0
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
using ll = long long;
using ld = long double;
const int mod = 998244353;
const int MOD = 1000000007;
const double pi = atan2(0, -1);
const int inf = 1 << 31-1;
const ll INF = 1LL << 63 - 1;
#include <time.h>
#include <chrono>

//vectorの中身を空白区切りで出力
template<typename T>
void printv(vector<T> v) {
	for (int i = 0; i < v.size(); i++) {
		cout << v[i];
		if (i < v.size() - 1) {
			cout << " ";
		}
	}
	cout << endl;
}

//vectorの中身を改行区切りで出力
template<typename T>
void print1(vector<T> v) {
	for (auto x : v) {
		cout << x << endl;
	}
}

//二次元配列を出力
template<typename T>
void printvv(vector<vector<T>> vv) {
	for (vector<T> v : vv) {
		printv(v);
	}
}

//vectorを降順にソート
template<typename T>
void rsort(vector<T>& v) {
	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());
}

//昇順priority_queueを召喚
template<typename T>
struct rpriority_queue {
	priority_queue<T, vector<T>, greater<T>> pq;

	void push(T x) {
		pq.push(x);
	}

	void pop() {
		pq.pop();
	}

	T top() {
		return pq.top();
	}

	size_t size() {
		return pq.size();
	}

	bool empty() {
		return pq.empty();
	}
};

//mod mod下で逆元を算出する
//高速a^n計算(mod ver.)
ll power(ll a, ll n) {
	if (n == 0) {
		return 1;
	}
	else if (n % 2 == 0) {
		ll x = power(a, n / 2);
		x *= x;
		x %= mod;
		return x;
	}
	else {
		ll x = power(a, n - 1);
		x *= a;
		x %= mod;
		return x;
	}
}
//フェルマーの小定理を利用
ll modinv(ll p) {
	return power(p, mod - 2) % mod;
}

//Mexを求める
struct Mex {
	map<int, int> mp;
	set<int> s;
	Mex(int Max) {
		for (int i = 0; i <= Max; i++) {
			s.insert(i);
		}
	}

	int _mex = 0;
	void Input(int x) {
		mp[x]++;
		s.erase(x);
		if (_mex == x) {
			_mex = *begin(s);
		}
	}

	void Remove(int x) {
		if (mp[x] == 0) {
			cout << "Mex ERROR!: NO VALUE WILL BE REMOVED" << endl;
		}
		mp[x]--;
		if (mp[x] == 0) {
			s.insert(x);
			if (*begin(s) == x) {
				_mex = x;
			}
		}
	}

	int mex(){
		return _mex;
	}
};

//Union-Find
struct UnionFind {
	vector<int> par;
	UnionFind(int N) : par(N) {
		for (int i = 0; i < N; i++) {
			par[i] = -1;
		}
	}

	//root(x):xの根を求める関数
	int root(int x) {
		if (par[x] == -1) {
			return x;
		}
		else {
			return par[x] = root(par[x]);
		}
	}

	//isSame(x,y):xとyが同じグループならtrueを返す関数
	bool isSame(int x, int y) {
		if (root(x) == root(y)) {
			return true;
		}
		else {
			return false;
		}
	}

	//Union(x,y):xとyの根をつなげる関数
	void Union(int x, int y) {
		int X = root(x);
		int Y = root(y);
		if (X == Y) {
			return;
		}
		if (X < Y) {
			swap(X, Y);
		}
		par[X] = Y;
	}
};

int main() {
	int T;
	cin >> T;
	rep(t, T) {
		int N;
		string S;
		cin >> N >> S;
		S += '-';
		vector<vector<int>> chank;
		int l = -1;
		rep(i, N+1) {
			if (S[i] != '-') {
				if (l == -1) {
					l = i;
				}
			}
			if (S[i] == '-') {
				if (l != -1) {
					chank.push_back({ l,i - 1 });
					l = -1;
				}
			}
		}

		int k_win = 0;
		for (vector<int> v : chank) {
			if (S[v[0]] == 'K' && S[v[1]] == 'K') {
				k_win++;
			}
			if (S[v[0]] == 'P' && S[v[1]] == 'P') {
				k_win--;
			}
		}

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