QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#89428#5414. Stop, Yesterday Please No MoreIanD#WA 12ms5728kbC++144.6kb2023-03-20 03:20:052023-03-20 03:20:06

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-20 03:20:06]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:5728kb
  • [2023-03-20 03:20:05]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define pb push_back
#define mp make_pair

#define MAXN 1010

int n, m, k, l;
string s;

bool vis[2*MAXN][2*MAXN];
int prex[2*MAXN][2*MAXN];
int prey[2*MAXN][2*MAXN];

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t;
    cin >> t;

    while (t--) {

    cin >> n >> m >> k >> s;
    rep(i, 0, 2*n+1) rep(j, 0, 2*n+1) vis[i][j] = false;

    pii xbounds = mp(0, n-1);
    pii ybounds = mp(0, m-1);
    int posx = 0;
    int posy = 0;

    vis[n][m] = true;
    for (char c : s) {
        if (c == 'D') {
            // move grid up, eats bottom
            // eats posx + n-1;
            xbounds.second = min(xbounds.second, posx+n-2);
            posx--;
        } else if (c == 'U') {
            // eats top... posx
            xbounds.first = max(xbounds.first, posx+1);
            posx++;
            //cout << "here" << endl;
        } else if (c == 'L') {
            // eats left... posy
            ybounds.first = max(ybounds.first, posy+1);
            posy++;
        } else if (c == 'R') {
            // eats right.. posy + m-1
            ybounds.second = min(ybounds.second, posy+m-2);
            posy--;
        }
        int indx = posx + n;
        int indy = posy + m;
        if (indx >= 0 && indy >= 0 && indx <= 2*n && indy <= 2*m) {
            vis[indx][indy] = true;
        }
    }
    if (xbounds.first > xbounds.second || ybounds.first > ybounds.second) {
        if (k == 0) {
            cout << n*m << '\n';
        } else {
            cout << 0 << '\n';
        }
        continue;
    }
    //cout << xbounds.first << ' ' << xbounds.second << ' ' << ybounds.first << ' ' << ybounds.second << endl;



    rep(i, 0, 2*n+1) {
        prex[i][0] = 0;
        if (vis[i][0]) prex[i][0] = 1;
        rep(j, 1, 2*m+1) {
            prex[i][j] = prex[i][j-1];
            if (vis[i][j]) prex[i][j]++;
        }
    }

    rep(j, 0, 2*m+1) {
        prey[0][j] = 0;
        if (vis[0][j]) prey[0][j] = 1;
        rep(i, 1, 2*n+1) {
            prey[i][j] = prey[i-1][j];
            if (vis[i][j]) prey[i][j]++;
        }
    }

    int beforeeating = (xbounds.second-xbounds.first+1)*(ybounds.second-ybounds.first+1);

    int numeaten = 0;
    rep(i, xbounds.first, xbounds.second+1) rep(j, ybounds.first, ybounds.second+1) {
        if (vis[i+n][j+m]) numeaten++;
    }

    int lastizero = numeaten;
    int out = 0;

    rep(i, 0, n) {
        if (i != 0) {
            // shift up
            numeaten = lastizero;
            // get rid of (xbounds.second-(i-1)) x [ybounds.first, ybounds.second]
            numeaten -= prex[xbounds.second-(i-1)+n][ybounds.second+m];
            if (ybounds.first+m != 0) {
                numeaten += prex[xbounds.second-(i-1)+n][ybounds.first-1+m];
            }

            // add in (xbounds.first-i) x [ybounds.first, ybounds.second]
            numeaten += prex[xbounds.first-i+n][ybounds.second+m];
            if (ybounds.first+m != 0) {
                numeaten -= prex[xbounds.first-i+n][ybounds.first-1+m];
            }

            lastizero = numeaten;
        }
        rep(j, 0, m) {
            if (j != 0) {
                // shift left
                // get rid of [xbounds.first-i, xbounds.second-i] x (ybounds.second-(j-1))
                numeaten -= prey[xbounds.second-i+n][ybounds.second-(j-1)+m];
                if (xbounds.first-i+n != 0) {
                    numeaten += prey[xbounds.first-i-1+n][ybounds.second-(j-1)+m];
                }

                // add in [xbounds.first-i, xbounds.second-i] x (ybounds.first-j)
                numeaten += prey[xbounds.second-i+n][ybounds.first-j+m];
                if (xbounds.first-i+n != 0) {
                    numeaten -= prey[xbounds.first-i-1+n][ybounds.first-j+m];
                }
            }
        // hole starts at (i, j)
        
        // if hole starts at (0, 0)

        // then I query [xbounds.first, xbounds.second] x [ybounds.first, ybounds.second]

        // if hole starts at (0, 1)

        // then I query [xbounds.first, xbounds.second] x [ybounds.first-1, ybounds.second-1] 
            //cout << i << ' ' << j << ' ' << numeaten << endl;
            if (beforeeating-numeaten == k) {
                out++;
                //cout << i << ' ' << j << endl;
            }
        }
    }

    cout << out << '\n';



    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3464kb

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: 12ms
memory: 5728kb

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
26
240
15
0
0
13
14
18
26
16
1
19
108
8
2
1
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
19
36
13
0
30
7
8
3
11
16
45
20
34
0...

result:

wrong answer 7th numbers differ - expected: '34', found: '26'