QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#725327#5414. Stop, Yesterday Please No MoreMoemi_WA 8ms3828kbC++202.7kb2024-11-08 17:08:392024-11-08 17:08:40

Judging History

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

  • [2024-11-08 17:08:40]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:3828kb
  • [2024-11-08 17:08:39]
  • 提交

answer

#include <iostream>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <cmath>
#include <stack>
#include <cstring>
#include <iomanip>
#include <unordered_map>
#include <numeric>

#define sc_int(x) scanf("%d", &x)

#define x first
#define y second
#define pb push_back

using namespace std;

const int N = 2e5 + 10, M = 5010, MOD = 1e9 + 7;
const int inf = 1e9;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
typedef pair<LL, LL> PLL;
typedef pair<double, double> PDD;
typedef pair<char, int> PCI;
typedef pair<string, string> PSS;

LL n, m, k, c, d;

void solve()
{
    cin >> n >> m >> k;
    string s;
    cin >> s;
    vector<vector<int>> dp(n * 2, vector<int>(m * 2));
    int x = n, y = m;
    dp[n][m] = 1;
    int up = 1, down = n, l = 1, r = m;
    int x1 = 1, x2 = n, y1 = 1, y2 = m;
    for(auto t : s)
    {
        if(t == 'U') x ++, down --, up --;
        else if(t == 'D') x --, up ++, down ++;
        else if(t == 'L') y ++, r --, l --;
        else y --, l ++, r ++;
        x1 = max(x1, up), x2 = min(x2, down), y1 = max(y1, l), y2 = min(y2, r);
        if(x < n * 2 && x >= 1 && y < m * 2 && y >= 1) dp[x][y] = 1;
    }

    if(x1 > x2 || y1 > y2)
    {
        if(k == 0) cout << n * m << endl;
        else cout << 0 << endl;
        return;
    }

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

    int d1 = x2 - x1 + 1, d2 = y2 - y1 + 1;
    int sum = d1 * d2;
    // cout << sum << endl;
    for(int i = 1; i < n * 2; i ++)
        for(int j = 1; j < m * 2; j ++)
        {
            dp[i][j] += dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1];
            // cout << dp[i][j] << " ";
            // if(j == m * 2 - 1) cout << endl;
        }

    LL ans = 0;
    for(int i = 1; i < n * 2; i ++)
        for(int j = 1; j < m * 2; j ++)
        {
            if(i + d1 - 1 < 2 * n && j + d2 - 1 < 2 * m)
            {
                int p1 = i + d1 - 1, p2 = j + d2 - 1;
                if(p1 < n * 2 && p2 < m * 2 && sum - (dp[p1][p2] - dp[p1][j - 1] - dp[i - 1][p2] + dp[i - 1][j - 1]) == k) 
                {
                    ans ++;
                }
            }
        }
    cout << ans << endl;
}


int main()
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int T = 1;
    cin >> T;
    while(T --)
    {
        solve();
    }
}

詳細信息

Test #1:

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

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

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
31
19
108
8
2
2
3
81
1
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...

result:

wrong answer 17th numbers differ - expected: '1', found: '31'