Submission #45347657


Source Code Expand

#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 110;

int dp[N][N][N];

void solve() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int r = 0, b = 0;
	vector<int> ans;
	reverse(ALL(s));
	memset(dp, 0, sizeof(dp));
	for (int i = 0; i < N; ++i) {
		dp[0][0][i] = 1;
	}
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == 'R') {
			++r;
		} else {
			++b;
		}
		if (r == 0 || b == 0) {
			ans.push_back(0);
		} else {
			int m = 0;
			while (m < N && dp[r - 1][b][m] == dp[r][b - 1][m]) {
				++m;
			}
			if (m == N) {
				ans.push_back(N);
			} else {
				ans.push_back(m + 1);
			}
		}
		for (int j = 0; j <= i + 1; ++j) {
			int k = i + 1 - j;
			int cur = 0;
			if (j == 0 || k == 0) {
				cur = 0;
			} else {
				int m = 0;
				while (m < N && dp[j - 1][k][m] == dp[j][k - 1][m]) {
					++m;
				}
				if (m == N) {
					cur = N;
				} else {
					cur = m + 1;
				}
			}
			auto check = [&] (int x, int y, int m) {
				if (x < 0 || y < 0) {
					return 0;
				}
				return dp[x][y][m];
			};
			for (int m = 0; m < N; ++m) {
				if ((check(j - 1, k, m) || check(j, k - 1, m)) && (min(m, cur) == min(m, ans.back()))) {
					dp[j][k][m] = 1;
				} else {
					dp[j][k][m] = 0;
				}
			}
		}
	}
	reverse(ALL(ans));
	for (int i : ans) {
		if (i == N) {
			cout << 0;
		} else {
			cout << 1;
		}
	}
	cout << "\n";
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
	int tt;
	cin >> tt;
	for (int i = 0; i < tt; ++i) {
		solve();
	}
	return 0;
}


Submission Info

Submission Time
Task A - Hat Puzzle
User LHiC
Language C++ 20 (gcc 12.2)
Score 1000
Code Size 2005 Byte
Status AC
Exec Time 83 ms
Memory 8748 KiB

Compile Error

Main.cpp: In function ‘void solve()’:
Main.cpp:41:27: warning: comparison of integer expressions of different signedness: ‘int’ and ‘std::__cxx11::basic_string<char>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   41 |         for (int i = 0; i < s.size(); ++i) {
      |                         ~~^~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 1000 / 1000
Status
AC × 1
AC × 24
Set Name Test Cases
Sample 00-sample-001.txt
All 00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt
Case Name Status Exec Time Memory
00-sample-001.txt AC 5 ms 8624 KiB
01-001.txt AC 40 ms 8688 KiB
01-002.txt AC 39 ms 8620 KiB
01-003.txt AC 81 ms 8556 KiB
01-004.txt AC 80 ms 8680 KiB
01-005.txt AC 80 ms 8684 KiB
01-006.txt AC 80 ms 8644 KiB
01-007.txt AC 81 ms 8668 KiB
01-008.txt AC 79 ms 8692 KiB
01-009.txt AC 80 ms 8748 KiB
01-010.txt AC 83 ms 8548 KiB
01-011.txt AC 80 ms 8680 KiB
01-012.txt AC 80 ms 8608 KiB
01-013.txt AC 78 ms 8628 KiB
01-014.txt AC 78 ms 8700 KiB
01-015.txt AC 78 ms 8680 KiB
01-016.txt AC 78 ms 8608 KiB
01-017.txt AC 78 ms 8684 KiB
01-018.txt AC 78 ms 8680 KiB
01-019.txt AC 79 ms 8688 KiB
01-020.txt AC 78 ms 8748 KiB
01-021.txt AC 78 ms 8620 KiB
01-022.txt AC 78 ms 8616 KiB
01-023.txt AC 78 ms 8700 KiB