QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#657092#5414. Stop, Yesterday Please No Morerxzfn639WA 7ms3796kbC++232.4kb2024-10-19 14:11:392024-10-19 14:11:43

Judging History

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

  • [2024-10-19 14:11:43]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3796kb
  • [2024-10-19 14:11:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
ll n, m, k, l, r, u, d, A;
string s;
const ll inf = 2e18;
void solve() {
    cin >> n >> m >> k >> s;
    //先用边界杀袋鼠
    ll maxh = -inf, minh = inf, maxw = -inf, minw = inf, h = 0, w = 0;
    for(auto c:s) {
        if(c == 'L') w--;
        else if(c == 'R') w++;
        else if(c == 'U') h--;
        else if(c == 'D') h++;
        maxh = max(maxh, h), minh = min(minh, h);
        maxw = max(maxw, w), minw = min(minw, w);
    }

    if(minw < 0) l = abs(minw) + 1; else l = 1;
    if(maxw > 0) r = m - maxw; else r = m;
    if(minh < 0) u = abs(minh) + 1; else u = 1;
    if(maxh > 0) d = n - maxh; else d = n;

    if(l > m || r < 1 || u > n || d < 1) {
        if(k == 0) {
            cout << n * m << endl;
        } else {
            cout << 0 << endl;
        }
        return ;
    }
    A = (r - l + 1) * (d - u + 1);
    // cout << l << " " << r << " " << u << " " << d << " " << A << endl;

    //下面确定cave的移动轨迹
    vector<vector<int> > a(2 * n + 10, vector<int> (2 * m + 10, 0));
    h = n + 2, w = m + 2;
    a[h][w] = 1;
    for(auto c:s) {
        if(c == 'U') {
            h++;
        } else if(c == 'D') {
            h--;
        } else if(c == 'L') {
            w++;
        } else if(c == 'R') {
            w--;
        }
        a[h][w] = 1;
    }

    //求前缀和
    for(int i = 1; i <= 2 * n + 9; ++i) {
        for(int j = 1; j <= 2 * m + 9; ++j) {
            a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
        }
    }

    // for(int i = 1; i <= 2 * n + 9; ++i) {
    //     for(int j = 1; j <= 2 * m + 9; ++j) {
    //         cout << a[i][j] << " ";
    //     }
    //     cout << endl;
    // }


    ll ans = 0;
    for(int i = 1, h1, h2; i <= n; ++i) {
        for(int j = 1, w1, w2; j <= m; ++j) {
            h1 = (n + 2) - i + u, h2 = (n + 2) - i + d;
            w1 = (m + 2) - j + l, w2 = (m + 2) - j + r;
            if(A - (a[h2][w2] - a[h1 - 1][w2] - a[h2][w1 - 1] + a[h1 - 1][w1 - 1]) == k) {
                // cout << i << " " << j << endl;
                ans++;
            }
        }
    }
    cout << ans << endl;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int _ = 1;
    cin >> _;
    while(_--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 7ms
memory: 3700kb

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:

21
11
20
99
18
15
34
0
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
0
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
38...

result:

wrong answer 1st numbers differ - expected: '228', found: '21'