QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#589363#5414. Stop, Yesterday Please No MoreLuckyblockWA 5ms7728kbC++202.4kb2024-09-25 17:25:472024-09-25 17:25:47

Judging History

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

  • [2024-09-25 17:25:47]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:7728kb
  • [2024-09-25 17:25:47]
  • 提交

answer

//
/*
By:Luckyblock
*/
#include <bits/stdc++.h>
#define LL long long
const int kN = 2e3 + 10;
//=============================================================
int n, m, k;
std::string s;
int cnt[kN << 1][kN << 1];
int d, len, delta[5];
std::map <char, int> ex, ey;
//=============================================================
void init() {
  d = std::max(n, m) + 2;
  for (int i = -n - 2; i <= n + 2; ++ i) {
    for (int j = -m - 2; j <= m + 2; ++ j) {
      cnt[i + d][j + d] = 0;
    }
  }

  len = s.length() - 1;
  cnt[0 + d][0 + d] = 1;
  delta[0] = delta[1] = delta[2] = delta[3] = 0;
  int x = 0, y = 0;
  for (int i = 1; i <= len; ++ i) {
    x -= ex[s[i]], y -= ey[s[i]];
    delta[0] = std::min(delta[0], x);
    delta[1] = std::max(delta[1], x);
    delta[2] = std::min(delta[2], y);
    delta[3] = std::max(delta[3], y);

    if (x > - n && y > - m && x < n && y < m) {
      cnt[x + d][y + d] = 1;
    }
  }
  for (int i = -n; i <= n; ++ i) {
    for (int j = -m; j <= m; ++ j) {
      cnt[i + d][j + d] += cnt[i - 1 + d][j + d] + 
                           cnt[i + d][j - 1 + d] -
                           cnt[i - 1 + d][j - 1 + d];
    }
  }
}
//=============================================================
int main() {
  // freopen("1.txt", "r", stdin);
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  ex['U'] = -1, ex['D'] = 1, ex['L'] = 0, ex['R'] = 0;
  ey['U'] = 0, ey['D'] = 0, ey['L'] = -1, ey['R'] = 1;

  int T; std::cin >> T;
  while (T --) {
    std::cin >> n >> m >> k;
    std::cin >> s; s = "$" + s;
    init();

    int ans = 0; 
    int c1 = (n + delta[0] - delta[1]) * (m + delta[2] - delta[3]);
    if (c1 <= 0) {
      std::cout << (k == 0 ? n * m : 0) << "\n";
      continue;
    }

    for (int i = 1; i <= n; ++ i) {
      for (int j = 1; j <= m; ++ j) {
        int c3 = cnt[(n - i) + delta[0] + d][(m - j) + delta[2] + d] - 
                 cnt[(n - i) + delta[0] + d][-(j - 1) - 1 + delta[3] + d] - 
                 cnt[-(i - 1) - 1 + delta[1] + d][(m - j) + delta[2] + d] + 
                 cnt[-(i - 1) - 1 + delta[1] + d][-(j - 1) - 1 + delta[3] + d];
        // c3 = c2 - c3;
        if (c1 - c3 == k) {
          ++ ans;
          // std::cout << i << " " << j << "\n";
        }
      }
    }
    std::cout << ans << "\n";
  }
  return 0;
}
/*
1
3 3 4
LU

1
4 5 0
UUUUUUU

1
4 5 3
ULDDRR
*/

詳細信息

Test #1:

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

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

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
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
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
...

result:

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