QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#725295#5414. Stop, Yesterday Please No MoreMoemi_WA 7ms4032kbC++202.6kb2024-11-08 17:00:482024-11-08 17:00:48

Judging History

This is the latest submission verdict.

  • [2024-11-08 17:00:48]
  • Judged
  • Verdict: WA
  • Time: 7ms
  • Memory: 4032kb
  • [2024-11-08 17:00:48]
  • Submitted

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;
    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 = x1; i < n + x1; i ++)
        for(int j = y1; j < n + y1; j ++)
        {
            if(i + d1 - 1 < 2 * n && j + d2 - 1 < 2 * m)
            {
                int p1 = i + d1 - 1, p2 = j + d2 - 1;
                if(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();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

result:

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