QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673572#5414. Stop, Yesterday Please No MorecabbageaWA 7ms3992kbC++172.7kb2024-10-25 00:15:092024-10-25 00:15:10

Judging History

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

  • [2024-10-25 00:15:10]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3992kb
  • [2024-10-25 00:15:09]
  • 提交

answer

#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    string s;
    cin >> s;
    int u = 1, d = n, l = 1, r = m;
    bool emp = false;
    for (auto x : s) {
        if ( x == 'U' ) {
            if ( d == 1 ) {
                emp = true;
                break;
            } else {
                u = max(1ll, u - 1), d--;
            }
        } else if ( x == 'D' ) {
            if ( u == n ) {
                emp = true;
                break;
            } else {
                u++, d = min(n, d + 1);
            }
        } else if ( x == 'L' ) {
            if ( r == 1 ) {
                emp = true;
                break;
            } else {
                l = max(1ll, l - 1), r--;
            }
        } else if ( x == 'R' ) {
            if ( l == n ) {
                emp = true;
                break;
            } else {
                l++, r = min(m, r + 1);
            }
        }
    }
    if (emp) {
        if ( k == 0 ) {
            cout << n * m << endl;
        } else {
            cout << 0 << endl;
        }
        return;
    }
    int lv = ( d - u + 1 ) * ( r - l + 1 );
    if ( lv < k ) {
        cout << 0 << endl;
        return;
    }
    reverse(s.begin(), s.end());
    set<PII> st;
    PII p = {0, 0};
    st.insert(p);
    for (auto x : s) {
        if ( x == 'U' ) p.x--;
        else if ( x == 'D' ) p.x++;
        else if ( x == 'L' ) p.y--;
        else if ( x == 'R' ) p.y++;
        st.insert(p);
    }
    int dx = 1 - u + n, dy = 1 - l + m;
    vector< vector<int> > g( n + (d - u) + 1, vector<int>( m + (r - l) + 1 ) );
    vector< vector<int> > sg( n + (d - u) + 1, vector<int>( m + (r - l) + 1 ) );
    for (auto x : st) {
        x.x += dx, x.y += dy;
        if ( x.x > n + (d - u) || x.y > m + (r - l) ) continue;
        g[x.x][x.y] = 1;
    }
    for (int i = 1; i <= n + (d - u); i++) {
        for (int j = 1; j <= m + (r - l); j++) {
            sg[i][j] = sg[i - 1][j] + sg[i][j - 1] - sg[i - 1][j - 1] + g[i][j];
        }
    }
    int cnt = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
            int s = sg[ i + (d - u) ][ j + (r - l) ] - sg[ i - 1 ][ j + (r - l) ] 
                - sg[ i + (d - u) ][ j - 1 ] + sg[ i - 1 ][ j - 1 ];
            if ( lv - s == k ) cnt++;
        }
    }
    cout << cnt << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int t = 1;
    cin >> t;
    while (t--) solve();
    return 0;
}

详细

Test #1:

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

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: 3992kb

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
0
0
3
7
0
30
16
21
0
8
10
9
15
0
320
11
7
3
0
0
12
0
11
0
0
14
0
22
36
51
23
7
6
4
2
0
0
8
63
22
49
13
10
0
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
0
48
30
36
13
0
30
7
8
3
11
16
45
20
34
0
3...

result:

wrong answer 21st numbers differ - expected: '2', found: '0'