QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#651507#5414. Stop, Yesterday Please No MoreHojstyerRE 0ms3572kbC++202.1kb2024-10-18 17:46:312024-10-18 17:46:35

Judging History

你现在查看的是最新测评结果

  • [2024-10-18 17:46:35]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3572kb
  • [2024-10-18 17:46:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int walk[4][2] = {{-1, 0}, {0, -1}, {1, 0}, {0, 1}};
map<char, int> mp;

void solve()
{
    int n, m, k;
    cin >> n >> m >> k;
    string s;
    cin >> s;
    int r = s.size();

    int dx = 0, dy = 0, mxl = 0, mxr = 0, mxd = 0, mxu = 0;
    for (int i = 0; i < r; ++i)
    {
        int j = mp[s[i]];
        dx += walk[j][0];
        dy += walk[j][1];
        mxl = min(mxl, dy);
        mxr = max(mxr, dy);
        mxd = min(mxd, dx);
        mxu = max(mxu, dx);
    }

    int xl = 1 + mxu, yl = 1 + mxr, xr = n + mxd, yr = m + mxl;
    if (xl > xr || yl > yr)
    {
        if (k == 0)
            cout << n * m << '\n';
        else
            cout << 0 << '\n';
        return;
    }
    vector<vector<int>> vis(n + 1, vector<int>(m + 1));
    int sx = xl, sy = yl;
    vis[sx][sy] = 1;
    dx = xr - xl + 1, dy = yr - yl + 1;
    int res = dx * dy;
    // cerr << sx << ' ' << sy << "\n";
    // cerr << sx << ' ' << sy << ' ' << sx + dx - 1 << ' ' << sx + dy - 1 << "\n";
    for (int i = 0; i < r; ++i)
    {
        int j = mp[s[i]];
        sx += walk[j][0];
        sy += walk[j][1];
        vis[sx][sy] = 1;
        // cerr << sx << ' ' << sy << "\n";
    }

    vector<vector<int>> a(n + 1, vector<int>(m + 1));
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
        {
            if (!vis[i][j])
                continue;
            a[i + dx - 1][i + dy - 1]++;
            a[i + dx - 1][j - 1]--;
            a[i - 1][j + dy - 1]--;
            a[i - 1][j - 1]++;
        }

    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];

    int ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            ans += (a[i][j] == res - k);

    cout << ans << "\n";
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    mp['R'] = 0, mp['U'] = 1, mp['L'] = 2, mp['D'] = 3;
    int t = 1;
    cin >> t;
    while (t--)
    {
        solve();
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3572kb

input:

3
4 5 3
ULDDRR
4 5 0
UUUUUUU
4 5 10
UUUUUUU

output:

2
20
0

result:

ok 3 number(s): "2 20 0"

Test #2:

score: -100
Runtime Error

input:

1060
19 12 0
UDLDDUUUUDDDLLRDUDUURULUUUDRDUDRDRLRLRLULULLLDLDDRLUUUURUUUDDRLLRUUUDULURUULLRDRLRDDURDUUURRRLURLRUULRRUDURDLUUURDLURDDLUUURDDRLLURRDLRUDLRDRLLRRDRDDLDRURRRLUDULLLRUUDLRRURRDLLRRRDLLRDDDLRLRURURDDDL
11 1 0
UR
3 18 33
UDRLR
17 11 132
RLDRDLDRUU
6 10 13
UULUDDLRDLUUDLDD
1 15 0
D
6 20 50
D...

output:


result: