QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725451#5414. Stop, Yesterday Please No MoreMoemi_WA 4ms3804kbC++203.4kb2024-11-08 17:53:462024-11-08 17:53:46

Judging History

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

  • [2024-11-08 17:53:46]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3804kb
  • [2024-11-08 17:53:46]
  • 提交

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 x1 = 1, x2 = n, y1 = 1, y2 = m;
    bool flag = true;
    for(auto t : s)
    {
        if(t == 'U') 
        {
            x ++, x1 --, x2 --;
            if(x2 == 0) 
            {
                flag = false;
                break;
            }
            if(x1 == 0)
            {
                x1 = 1;
            }
        }
        else if(t == 'D') 
        {
            x --, x1 ++, x2 ++;
            if(x1 == n + 1)
            {
                flag = false;
                break;
            }
            if(x2 == n + 1) x2 = n;
        }
        else if(t == 'L') 
        {
            y ++, y1 --, y2 --;
            if(y2 == 0) 
            {
                flag = false;
                break;
            }
            if(y1 == 0)
            {
                y1 = 1;
            }
        }
        else 
        {
            y --, y1 ++, y2 ++;
            if(y1 == m + 1)
            {
                flag = false;
                break;
            }
            if(y2 == m + 1)
            {
                y2 = m;
            }
        }
        
        if(x < n * 2 && x >= 1 && y < m * 2 && y >= 1) dp[x][y] = 1;
    }

    if(!flag)
    {
        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;

    // cout << x1 << " " << x2 << endl;
    // cout << y1 << " " << y2 << endl;

    // cout << endl;

    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];
        }

    LL ans = 0;
    for(int i = 1; i < 2 * n; i ++)
        for(int j = 1; j < 2 * m; j ++)
        {
            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) 
            {
                // cout << i << ' ' << j << endl;
                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();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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'