QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#879883#5414. Stop, Yesterday Please No MoreThe_8th_HorcruxWA 330ms12560kbC++231.9kb2025-02-02 17:09:382025-02-02 17:09:40

Judging History

This is the latest submission verdict.

  • [2025-02-02 17:09:40]
  • Judged
  • Verdict: WA
  • Time: 330ms
  • Memory: 12560kb
  • [2025-02-02 17:09:38]
  • Submitted

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

constexpr int MAXN = 1005;

string op;
int n, m, k;
int U, D, L, R;
int U_, D_, L_, R_;
bool st[MAXN][MAXN];
int g[MAXN][MAXN];

void add(int X1, int Y1, int X2, int Y2){
    if (st[X1][Y1])
        return;
    st[X1][Y1] = true;
    g[X1][Y1]++, g[X2 + 1][Y1]--, g[X1][Y2 + 1]--, g[X2 + 1][Y2 + 1]++;
}

void solve() {
    cin >> n >> m >> k >> op;
    U_ = L_ = U = L = 1, R_ = R = m, D_ = D = n;
    memset(st, false, sizeof st), memset(g, 0, sizeof g);
    //确定边界
    for (auto i: op){
        if (i == 'L')
            L_++, R_++;
        else if (i == 'R')
            L_--, R_--;
        else if (i == 'U')
            U_++, D_++;
        else
            U_--, D_--;
        L = max(L, L_), R = min(R, R_), U = max(U, U_), D = min(D, D_);
    }
    //无袋鼠剩余情况
    if (U > D || L > R){
        if (k)
            puts("0");
        else
            cout << n * m << endl;
        return;
    }
    //统计袋鼠经过格子的情况
    int x = (D - U + 1) * (R - L + 1), cnt = 0;
    add(U, L, D, R);
    for (auto i: op){
        if (i == 'L')
            L--, R--;
        else if (i == 'R')
            L++, R++;
        else if (i == 'U')
            U--, D--;
        else
            U++, D++;
        add(U, L, D, R);
    }
    //二位前缀和+统计答案
    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            g[i][j] += g[i - 1][j] + g[i][j - 1] - g[i - 1][j - 1];

    for (int i = 1; i <= n; i ++ )
        for (int j = 1; j <= m; j ++ )
            if (x - g[i][j] == k)
                 cnt++;
    cout << cnt << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;

    while(t--) {
        solve();
    }

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 12444kb

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
Wrong Answer
time: 330ms
memory: 12560kb

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:

228
11
20
99
18
15
34
240
15
0
0
13
14
18
26
16
1
19
108
8
2
2
3
7
0
30
16
21
0
8
10
9
15
5
320
11
7
3
0
0
12
0
11
0
0
14
0
22
36
51
23
7
6
4
2
48
28
8
63
22
49
13
10
4
108
10
18
44
15
9
0
4
30
14
99
105
10
14
17
0
66
10
11
28
52
34
56
33
14
56
90
14
0
121
3
48
30
36
13
0
30
7
8
3
11
16
45
20
34
0
3...

result:

wrong answer 69th numbers differ - expected: '0', found: '15'