QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#74412#5414. Stop, Yesterday Please No Moremagicduck#WA 12ms4564kbC++142.6kb2023-02-01 13:44:492023-02-01 13:44:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-01 13:44:51]
  • 评测
  • 测评结果:WA
  • 用时:12ms
  • 内存:4564kb
  • [2023-02-01 13:44:49]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
template <typename T> inline void read(T &F) {
    int R = 1; F = 0; char CH = getchar();
    for(; !isdigit(CH); CH = getchar()) if(CH == '-') R = -1;
    for(; isdigit(CH); CH = getchar()) F = F * 10 + CH - 48;
    F *= R;
}
inline void file(string str) {
    freopen((str + ".in").c_str(), "r", stdin);
    freopen((str + ".out").c_str(), "w", stdout);
}
const int N = 2e3 + 10, M = 1e6 + 10;
char s[M]; int n, m, k, res[N][N]; vector<int> v[N];
struct BIT {
    int c[N];
    void add(int x) {
        for(; x <= m * 2 - 1; x += (x & -x)) c[x]++;
    }
    int qry(int x) {
        int r = 0;
        for(; x; x -= (x & -x))
            r += c[x];
        return r;
    }
    int qry(int l, int r) {
        return qry(r) - qry(l - 1);
    }
}tr;
struct mat {
    int l, r, x, y, op;
}; vector<mat> g[N];
int main() {
    //file("");
    int T; read(T);
    while(T--) {
        read(n), read(m), read(k);
        for(int i = 0; i <= 2 * n; i++) v[i].clear(), g[i].clear();
        scanf("%s", s + 1); int p = strlen(s + 1);
        int X = 0, Y = 0, xl = 1, xr = n, yl = 1, yr = m; 
        v[n].emplace_back(m);
        for(int i = 1; i <= p; i++) {
            if(s[i] == 'U') X--, xl = max(xl, -X + 1);
            else if(s[i] == 'D') X++, xr = min(xr, n - X);
            else if(s[i] == 'L') Y--, yl = max(yl, -Y + 1);
            else Y++, yr = min(yr, m - Y);
            if(X > -n && X < n && Y > -m && Y < m)
                v[n - X].emplace_back(m - Y);
        }
        if(xl > xr || yl > yr) {
            if(k == 0) cout << n * m << '\n';
            else puts("0");
            continue;
        }
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++) {
                int l = xl - i + n, r = xr - i + n;
                int ll = yl - j + m, rr = yr - j + m;
                g[l - 1].push_back((mat){ll, rr, i, j, -1});
                g[r].push_back((mat){ll, rr, i, j, 1});
                res[i][j] = 0;
            }
        for(int i = 1; i <= 2 * m - 1; i++)  tr.c[i] = 0;
        for(int i = 1; i <= 2 * n; i++) {
            for(int j : v[i]) tr.add(j);
            for(auto j : g[i])
                res[j.x][j.y] += tr.qry(j.l, j.r) * j.op;
        }
        int ans = 0; const int sum = (xr - xl + 1) * (yr - yl + 1);
        for(int i = 1; i <= n; i++)
            for(int j = 1; j <= m; j++)
                if(sum - res[i][j] == k) ans++;
        cout << ans << '\n';
    }
    
    #ifdef _MagicDuck
        fprintf(stderr, "# Time: %.3lf s", (double)clock() / CLOCKS_PER_SEC);
    #endif
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
17
9
18
15
21
240
14
0
0
5
1
18
3
16
1
31
108
8
1
2
3
7
0
29
4
20
0
8
10
9
6
5
320
3
5
3
0
0
7
0
11
0
0
8
128
22
18
51
23
5
6
3
9
48
28
8
1
22
49
13
10
2
12
6
18
44
0
14
5
0
4
30
14
99
105
2
27
17
0
66
10
11
28
52
32
8
22
14
0
90
15
0
22
3
48
29
20
9
0
30
6
8
3
10
16
45
16
17
0
20
0
21
0
6
0
...

result:

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