求问快读哪里写错了?
  • 板块灌水区
  • 楼主Little_x_starTYJ
  • 当前回复21
  • 已保存回复21
  • 发布时间2024/4/26 15:19
  • 上次更新2024/4/26 18:26:50
查看原帖
求问快读哪里写错了?
902351
Little_x_starTYJ楼主2024/4/26 15:19
#include <stdio.h>
#include <iostream>
#define int long long
int n, m, now = 200000, ans, k;
bool flag[300010];
int t[100010], id[300010];
int cnt[10][300010], sum[10];
char a[100010];
inline int read() {
    char c = 'a';
    int t = 0;
    short k = 1;
    while (c < '0' || c > '9') {
        c = getchar();
        if (c == '-')
        	k = -k;
    }
    while (c >= '0' && c <= '9')
        t = t * 10 + c - 48, c = getchar();
    return t * k;
}
signed main()
{
	n = read(), m = read();
	for (int i = 1; i <= n; i++)
		t[i] = read(), t[i] += 200000, id[t[i]] = i;
	char c = getchar();
	while (c == ' ' || c == '\n')
		c = getchar();
	a[1] = c;
	for (int i = 2; i <= m; i++) {
		a[i] = getchar();
	}
	for (int i = 1; i <= m; i++)
	{
		if (a[i] == 'L')
			now--;
		if (a[i] == 'R')
			now++;
		if (a[i] == 'F' && id[now] && !flag[now])
			k++, flag[now] = 1;
	}
	for (int j = -2; j <= 2; j++)
	{
		if (!j)
			continue;
		now = j + 200000;
		for (int i = 1; i <= m; i++)
		{
			if (a[i] == 'L')
				now--;
			if (a[i] == 'R')
				now++;
			if (a[i] == 'F')
				if (id[now])
					cnt[j + 2][now]++, sum[j + 2] += (cnt[j + 2][now] == 1);
		}
	}
	now = 200000;
	for (int i = 1; i <= m; i++)
	{
		if (a[i] == 'L')
			ans = std::max(ans, sum[4]), ans = std::max(ans, sum[3] + (id[now] > 0 && !cnt[3][now]));
		if (a[i] == 'R')
			ans = std::max(ans, sum[0]), ans = std::max(ans, sum[1] + (id[now] > 0 && !cnt[1][now]));
		if (a[i] == 'F')
			ans = std::max(ans, sum[1] - (id[now] > 0 && cnt[1][now] == 1)), ans = std::max(ans, sum[3] - (id[now] > 0 && cnt[3][now] == 1));
		if (a[i] == 'L')
			now--;
		if (a[i] == 'R')
			now++;
		if (a[i] == 'F')
		{
			for (int j = -2; j <= 2; j++)
			{
				if (!j)
					continue;
				if (id[now])
					cnt[j + 2][now]++, sum[j + 2] += (cnt[j + 2][now] == 1);
				if (id[now + j])
					cnt[j + 2][now + j]--, sum[j + 2] -= (!cnt[j + 2][now + j]);
			}
		}
	}
	printf("%lld", std::max(ans, k));
	return 0;
}

本地对,一交就WA

2024/4/26 15:19
加载中...