QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#185264#5414. Stop, Yesterday Please No More_LAP_WA 3ms6604kbC++142.0kb2023-09-21 20:17:102023-09-21 20:17:10

Judging History

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

  • [2023-09-21 20:17:10]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:6604kb
  • [2023-09-21 20:17:10]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const int N = 1e3 + 10;
int n, m, k, len, S[N + N][N + N]; string s;

inline int get(int Lx, int Rx, int Ly, int Ry) {
    Lx += n, Rx += n, Ly += m, Ry += m;
    assert(Lx >= 1 && Rx >= 1 && Ly >= 1 && Ry >= 1);
    assert(Lx <= 2 * n && Rx <= 2 * n && Ly <= 2 * m && Ry <= 2 * m);
    assert(Lx <= Rx && Ly <= Ry);
    return S[Rx][Ry] - S[Lx - 1][Ry] - S[Rx][Ly - 1] + S[Lx - 1][Ly - 1];
}

inline int solve() {
    set<pair<int, int>> Set;
    cin >> n >> m >> k;
    for(int i = 0; i <= 2 * n; i ++) for(int j = 0; j <= 2 * m; j ++) S[i][j] = 0;
    int row_L = 1, row_R = n, col_L = 1, col_R = m;
    cin >> s; len = s.size();
    Set.insert({0, 0});
    for(int i = 0, delta_row = 0, delta_col = 0; i < len; i ++) {
        if(s[i] == 'U') delta_row --, row_R = min(row_R, n + delta_row);
        else if(s[i] == 'D') delta_row ++, row_L = max(row_L, 1 + delta_row);
        else if(s[i] == 'L') delta_col --, col_R = min(col_R, m + delta_col);
        else delta_col ++, col_L = max(col_L, 1 + delta_col);
        Set.insert({-delta_row, -delta_col});        
    }
    if(row_L > row_R || col_L > col_R) return (k == 0 ? n * m : 0);
    int siz = (row_R - row_L + 1) * (col_R - col_L + 1);
    if(siz < k) return 0; siz -= k; // we should delete siz kangaroos
    for(auto &pr : Set) S[pr.first + n][pr.second + m] ++;
    for(int i = 1; i <= 2 * n; i ++) S[i][0] += S[i - 1][0];
    for(int j = 1; j <= 2 * m; j ++) S[0][j] += S[0][j - 1];
    for(int i = 1; i <= 2 * n; i ++) for(int j = 1; j <= 2 * m; j ++) {
        S[i][j] = S[i][j] + S[i - 1][j] + S[i][j - 1] - S[i - 1][j - 1];
    }

    int res = 0;
    for(int i = 1; i <= n; i ++) for(int j = 1; j <= m; j ++) {
        // check if the hole can be in (i, j)
        res += (get(row_L - i, row_R - i, col_L - j, col_R - j) == siz);
    }
    return res;
}

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

    int T; cin >> T;
    while(T --) cout << solve() << '\n';

    return 0;
}

详细

Test #1:

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

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

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
1
99
5
15
16
240
6
0
0
1
11
18
13
0
12
16
108
4
1
1
3
48
1
1
3
4
0
7
10
9
4
5
320
8
5
3
0
0
3
0
11
0
0
6
0
22
36
51
12
5
6
1
2
48
28
8
63
11
49
13
4
2
108
7
9
44
0
1
8
0
4
30
12
99
105
5
1
17
0
66
8
11
28
52
15
56
11
5
56
90
14
0
121
3
48
1
16
10
0
30
1
3
3
7
16
45
9
32
0
19
0
4
0
39
0
20
12
...

result:

wrong answer 3rd numbers differ - expected: '20', found: '1'