Submission #44111948
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using pll = pair<long long, long long>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define REP(i, n) for (long long i = 0; i < (long long)(n); ++i)
#define REP2(i, a, b) for (long long i = a; i < (long long)(b); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, deque<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s; }
template<class T> ostream& operator << (ostream &s, multiset<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s; }
// 4-neighbor (or 8-neighbor)
const vector<int> dx = {1, 0, -1, 0, 1, -1, 1, -1};
const vector<int> dy = {0, 1, 0, -1, 1, 1, -1, -1};
// Union-Find
struct UnionFind {
vector<int> par;
UnionFind() { }
UnionFind(int n) : par(n, -1) { }
void init(int n) { par.assign(n, -1); }
int root(int x) {
if (par[x] < 0) return x;
else return par[x] = root(par[x]);
}
bool issame(int x, int y) {
return root(x) == root(y);
}
bool merge(int x, int y) {
x = root(x); y = root(y);
if (x == y) return false;
if (par[x] > par[y]) swap(x, y); // merge technique
par[x] += par[y];
par[y] = x;
return true;
}
int size(int x) {
return -par[root(x)];
}
};
ostream& operator << (ostream& s, UnionFind uf) {
map<int, vector<int> > res;
for (int i = 0; i < uf.par.size(); ++i) {
int r = uf.root(i);
res[r].push_back(i);
}
for (map<int, vector<int> >::iterator it = res.begin(); it != res.end(); ++it) {
s << endl;
for (int j = 0; j < (int)it->second.size(); ++j) {
s << it->second[j] << ", ";
}
}
return s << endl;
}
// modint
template<int MOD> struct Fp {
long long val;
constexpr Fp(long long v = 0) noexcept : val(v % MOD) {
if (val < 0) val += MOD;
}
constexpr int getmod() const { return MOD; }
constexpr Fp operator - () const noexcept {
return val ? MOD - val : 0;
}
constexpr Fp operator + (const Fp& r) const noexcept { return Fp(*this) += r; }
constexpr Fp operator - (const Fp& r) const noexcept { return Fp(*this) -= r; }
constexpr Fp operator * (const Fp& r) const noexcept { return Fp(*this) *= r; }
constexpr Fp operator / (const Fp& r) const noexcept { return Fp(*this) /= r; }
constexpr Fp& operator += (const Fp& r) noexcept {
val += r.val;
if (val >= MOD) val -= MOD;
return *this;
}
constexpr Fp& operator -= (const Fp& r) noexcept {
val -= r.val;
if (val < 0) val += MOD;
return *this;
}
constexpr Fp& operator *= (const Fp& r) noexcept {
val = val * r.val % MOD;
return *this;
}
constexpr Fp& operator /= (const Fp& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b, swap(a, b);
u -= t * v, swap(u, v);
}
val = val * u % MOD;
if (val < 0) val += MOD;
return *this;
}
constexpr bool operator == (const Fp& r) const noexcept {
return this->val == r.val;
}
constexpr bool operator != (const Fp& r) const noexcept {
return this->val != r.val;
}
friend constexpr istream& operator >> (istream& is, Fp<MOD>& x) noexcept {
is >> x.val;
x.val %= MOD;
if (x.val < 0) x.val += MOD;
return is;
}
friend constexpr ostream& operator << (ostream& os, const Fp<MOD>& x) noexcept {
return os << x.val;
}
friend constexpr Fp<MOD> modpow(const Fp<MOD>& r, long long n) noexcept {
if (n == 0) return 1;
if (n < 0) return modpow(modinv(r), -n);
auto t = modpow(r, n / 2);
t = t * t;
if (n & 1) t = t * r;
return t;
}
friend constexpr Fp<MOD> modinv(const Fp<MOD>& r) noexcept {
long long a = r.val, b = MOD, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b, swap(a, b);
u -= t * v, swap(u, v);
}
return Fp<MOD>(u);
}
};
// Binomial coefficient
template<class T> struct BiCoef {
vector<T> fact_, inv_, finv_;
constexpr BiCoef() {}
constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
init(n);
}
constexpr void init(int n) noexcept {
fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
int MOD = fact_[0].getmod();
for(int i = 2; i < n; i++){
fact_[i] = fact_[i-1] * i;
inv_[i] = -inv_[MOD%i] * (MOD/i);
finv_[i] = finv_[i-1] * inv_[i];
}
}
constexpr T com(int n, int k) const noexcept {
if (n < k || n < 0 || k < 0) return 0;
return fact_[n] * finv_[k] * finv_[n-k];
}
constexpr T fact(int n) const noexcept {
if (n < 0) return 0;
return fact_[n];
}
constexpr T inv(int n) const noexcept {
if (n < 0) return 0;
return inv_[n];
}
constexpr T finv(int n) const noexcept {
if (n < 0) return 0;
return finv_[n];
}
};
//const int MOD = 1000000007;
const int MOD = 998244353;
using mint = Fp<MOD>;
BiCoef<mint> bc;
int main() {
int N;
string S;
cin >> N >> S;
for (int i = 0; i < N; ++i) S += "AB";
set<int> alr;
int res = 0, aback = -1, bback = -1;
for (int k = 1; k <= N; ++k) {
if (k % 2 == 1) {
// Alice's turn (place B)
while (bback < 0 || S[bback] != 'B') ++bback;
alr.insert(bback++);
while (alr.count(res)) ++res;
} else {
// Bob's turn (place A)
while (aback < 0 || S[aback] != 'A') ++aback;
alr.insert(aback++);
while (alr.count(res)) ++res;
}
// cout << "-------------" << endl; COUT(k); COUT(aback); COUT(bback); COUT(alr); COUT(res);
cout << (S[res] == 'A' ? "Alice" : "Bob") << endl;
}
}
Submission Info
Submission Time
2023-07-30 21:26:06+0900
Task
A - Mex Game
User
drken
Language
C++ (GCC 9.2.1)
Score
300
Code Size
7290 Byte
Status
AC
Exec Time
400 ms
Memory
13204 KB
Compile Error
./Main.cpp: In function ‘std::ostream& operator<<(std::ostream&, UnionFind)’:
./Main.cpp:63:23: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::vector<int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
63 | for (int i = 0; i < uf.par.size(); ++i) {
| ~~^~~~~~~~~~~~~~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
300 / 300
Status
Set Name
Test Cases
Sample
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt
All
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_small_01.txt, 02_small_02.txt, 02_small_03.txt, 02_small_04.txt, 03_rand_01.txt, 03_rand_02.txt, 03_rand_03.txt, 03_rand_04.txt, 03_rand_05.txt, 04_max_rand_01.txt, 04_max_rand_02.txt, 04_max_rand_03.txt, 04_max_rand_04.txt, 04_max_rand_05.txt, 05_half_half_01.txt, 05_half_half_02.txt, 05_half_half_03.txt, 05_half_half_04.txt, 05_half_half_05.txt, 06_hand_01.txt, 06_hand_02.txt, 06_hand_03.txt, 06_hand_04.txt, 06_hand_05.txt, 06_hand_06.txt, 06_hand_07.txt, 06_hand_08.txt
Case Name
Status
Exec Time
Memory
01_sample_01.txt
AC
8 ms
3440 KB
01_sample_02.txt
AC
2 ms
3436 KB
01_sample_03.txt
AC
2 ms
3460 KB
02_small_01.txt
AC
3 ms
3512 KB
02_small_02.txt
AC
3 ms
3492 KB
02_small_03.txt
AC
3 ms
3440 KB
02_small_04.txt
AC
2 ms
3500 KB
03_rand_01.txt
AC
40 ms
4224 KB
03_rand_02.txt
AC
216 ms
8980 KB
03_rand_03.txt
AC
198 ms
8312 KB
03_rand_04.txt
AC
256 ms
9972 KB
03_rand_05.txt
AC
156 ms
7364 KB
04_max_rand_01.txt
AC
390 ms
13112 KB
04_max_rand_02.txt
AC
375 ms
13048 KB
04_max_rand_03.txt
AC
386 ms
13108 KB
04_max_rand_04.txt
AC
374 ms
13108 KB
04_max_rand_05.txt
AC
378 ms
13048 KB
05_half_half_01.txt
AC
383 ms
13108 KB
05_half_half_02.txt
AC
389 ms
13168 KB
05_half_half_03.txt
AC
400 ms
13036 KB
05_half_half_04.txt
AC
387 ms
13112 KB
05_half_half_05.txt
AC
397 ms
13132 KB
06_hand_01.txt
AC
380 ms
13040 KB
06_hand_02.txt
AC
374 ms
13036 KB
06_hand_03.txt
AC
377 ms
13140 KB
06_hand_04.txt
AC
387 ms
13104 KB
06_hand_05.txt
AC
379 ms
13168 KB
06_hand_06.txt
AC
384 ms
13204 KB
06_hand_07.txt
AC
385 ms
13100 KB
06_hand_08.txt
AC
381 ms
13040 KB