Cu ball
by chat_jinxuan @ 2024-04-25 16:59:41
# mistake1
输入字符时用了
```cpp
scanf("%c", a + i)
```
%c会读入 **行末回车和空格**
可以换成
```cpp
scanf("%s", a + 1);
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;
}
```
以后一定会长记性的qwq
# mistake2
应该是手误,2和3搞错了
```cpp
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[2][now] == 1));
```
改成
```
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));
```
by ZYLZPP @ 2024-04-25 18:39:19
@[IOI_ILJYT](/user/902351)
改好后:
```cpp
#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];
signed main()
{
scanf("%lld%lld", &n, &m);
for (int i = 1; i <= n; i++)
scanf("%lld", t + i), t[i] += 200000, id[t[i]] = i;
scanf("%s", a + 1);
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 k = -2; k <= 2; k++)
{
if (!k)
continue;
now = k + 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[k + 2][now]++, sum[k + 2] += (cnt[k + 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;
}
```
by ZYLZPP @ 2024-04-25 18:41:42
@[ZYLZPP](/user/932511) thx 已关
by IOI_ILJYT @ 2024-04-26 15:34:29