提出 #46379630


ソースコード 拡げる

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <ctype.h>
#include <cmath>
#include <vector>
#include <queue>
#include <numeric>
#include <map>
#include <set>
#include <iostream>

char ST;
//#define int long long
#define ll long long
#define inf 0x3f3f3f3f
//#define inf 0x3f3f3f3f3f3f3f3f
int read()
{
	int x = 0, f = 1;
	char c = getchar();
	for(; !isdigit(c); c = getchar()) if(c == '-') f = -1;
	for(;  isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48);
	return x * f;
}

int readstr(char *str, int base)
{
	int len = base - 1;
	char c = getchar();
	for(; !isalpha(c) && !isdigit(c) && c != '.' && c != '*' && c != '#'; c = getchar());
	for(;  isalpha(c) ||  isdigit(c) || c == '.' || c == '*' || c == '#'; c = getchar()) str[++len] = c;
	return len - base + 1;
}

void write(int x, char c)
{
	if(c) putchar(c);
	if(x >= 10) write(x / 10, 0);
	putchar(x % 10 + 48);
}

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define gline debug("now is #%d\n", __LINE__)
#define pii std::pair <int, int>
#define mkp std::make_pair
#define fi first
#define se second
#define pb push_back 

template <typename T> void ckmax(T &x, T y) { x = x > y ? x : y; }
template <typename T> void ckmin(T &x, T y) { x = x < y ? x : y; }
template <typename T> T max(T x, T y) { return x > y ? x : y; }
template <typename T> T min(T x, T y) { return x < y ? x : y; }
#define mod 998244353
//#define mod 1000000007

void plus_(int &x, int y) { x = x + y >= mod ? x + y - mod : x + y; }
void mul_(int &x, int y) { x = 1ll * x * y % mod; }
int ksm(int a, int b)
{
	int res = 1;
	for(; b; b >>= 1, mul_(a, a)) if(b & 1) mul_(res, a);
	return res;
}

#define N 200010
int n;
char s[N], t[N];
#define NO { printf("No\n"); return; }
void solve()
{
//	memset(h, idx = -1, sizeof(h));
	n = read();
	n = readstr(s, 1); n = readstr(t, 1);
	for(int i = 1; i <= n; i++) if(t[i] == 'C' && s[i] != 'C') NO;
	for(int l = 1, r; l <= n; l = r + 1)
	{
		r = l;
		if(t[l] == 'C') continue;
		for(; r < n && t[r + 1] != 'C'; r++);
		int tot = 0;
		for(int i = l; i <= r; i++) tot += (t[i] == 'A') - (s[i] == 'A');
		for(int i = l; i <= r; i++)
		{
			if(s[i] != 'C') continue;
			if(tot > 0) tot--, s[i] = 'A';
			else s[i] = 'B';
//			printf("s[%d] = %c\n", i, s[i]);
		}
		int sum = 0;
		for(int i = l; i <= r; i++) sum += (s[i] == 'A') - (t[i] == 'A');
		if(sum) NO;
		for(int i = l, now = 0; i <= r; i++)
		{
			now += (s[i] == 'A');
			if(t[i] == 'A') now--;
			if(now < 0) NO;
		}
	}
	printf("Yes\n");
}

void init()
{
	
}

char ED;
signed main()
{
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
//	freopen("tmp.out", "w", stdout);
#endif
	debug("%.3f MB\n", abs(&ST - &ED) / 1024.0 / 1024);
	init(); 
	for(int T = read(); T; solve(), T--);
	return 0;
}

提出情報

提出日時
問題 A - Replace C or Swap AB
ユーザ ningago
言語 C++ 20 (gcc 12.2)
得点 400
コード長 2876 Byte
結果 AC
実行時間 4 ms
メモリ 4224 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 40
セット名 テストケース
Sample 01_sample_01.txt, 01_sample_02.txt
All 01_sample_01.txt, 01_sample_02.txt, 02_small_1_01.txt, 02_small_1_02.txt, 03_small_2_01.txt, 03_small_2_02.txt, 03_small_2_03.txt, 03_small_2_04.txt, 04_rand_1_01.txt, 04_rand_1_02.txt, 04_rand_1_03.txt, 04_rand_1_04.txt, 04_rand_1_05.txt, 05_rand_max_1_01.txt, 05_rand_max_1_02.txt, 05_rand_max_1_03.txt, 05_rand_max_1_04.txt, 05_rand_max_1_05.txt, 05_rand_max_1_06.txt, 05_rand_max_1_07.txt, 05_rand_max_1_08.txt, 05_rand_max_1_09.txt, 05_rand_max_1_10.txt, 06_rand_2_01.txt, 06_rand_2_02.txt, 06_rand_2_03.txt, 06_rand_2_04.txt, 06_rand_2_05.txt, 07_rand_max_2_01.txt, 07_rand_max_2_02.txt, 07_rand_max_2_03.txt, 07_rand_max_2_04.txt, 07_rand_max_2_05.txt, 07_rand_max_2_06.txt, 07_rand_max_2_07.txt, 07_rand_max_2_08.txt, 07_rand_max_2_09.txt, 07_rand_max_2_10.txt, 08_max_step_01.txt, 08_max_step_02.txt
ケース名 結果 実行時間 メモリ
01_sample_01.txt AC 1 ms 3756 KiB
01_sample_02.txt AC 1 ms 3720 KiB
02_small_1_01.txt AC 4 ms 3636 KiB
02_small_1_02.txt AC 4 ms 3708 KiB
03_small_2_01.txt AC 3 ms 3840 KiB
03_small_2_02.txt AC 3 ms 3720 KiB
03_small_2_03.txt AC 3 ms 3836 KiB
03_small_2_04.txt AC 4 ms 3720 KiB
04_rand_1_01.txt AC 3 ms 3712 KiB
04_rand_1_02.txt AC 3 ms 3660 KiB
04_rand_1_03.txt AC 3 ms 3660 KiB
04_rand_1_04.txt AC 3 ms 3644 KiB
04_rand_1_05.txt AC 3 ms 3772 KiB
05_rand_max_1_01.txt AC 4 ms 4212 KiB
05_rand_max_1_02.txt AC 2 ms 4100 KiB
05_rand_max_1_03.txt AC 4 ms 4088 KiB
05_rand_max_1_04.txt AC 2 ms 4092 KiB
05_rand_max_1_05.txt AC 2 ms 4136 KiB
05_rand_max_1_06.txt AC 2 ms 4080 KiB
05_rand_max_1_07.txt AC 4 ms 4112 KiB
05_rand_max_1_08.txt AC 2 ms 4212 KiB
05_rand_max_1_09.txt AC 4 ms 4136 KiB
05_rand_max_1_10.txt AC 2 ms 4224 KiB
06_rand_2_01.txt AC 4 ms 3708 KiB
06_rand_2_02.txt AC 4 ms 3764 KiB
06_rand_2_03.txt AC 4 ms 3720 KiB
06_rand_2_04.txt AC 4 ms 3844 KiB
06_rand_2_05.txt AC 4 ms 3712 KiB
07_rand_max_2_01.txt AC 2 ms 4080 KiB
07_rand_max_2_02.txt AC 2 ms 4112 KiB
07_rand_max_2_03.txt AC 4 ms 4188 KiB
07_rand_max_2_04.txt AC 4 ms 4096 KiB
07_rand_max_2_05.txt AC 4 ms 4216 KiB
07_rand_max_2_06.txt AC 4 ms 4120 KiB
07_rand_max_2_07.txt AC 4 ms 4084 KiB
07_rand_max_2_08.txt AC 4 ms 4040 KiB
07_rand_max_2_09.txt AC 4 ms 4096 KiB
07_rand_max_2_10.txt AC 4 ms 4024 KiB
08_max_step_01.txt AC 3 ms 4100 KiB
08_max_step_02.txt AC 3 ms 4212 KiB