QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#50677#1273. It's All Squaresckiseki#RE 3ms7748kbC++2.4kb2022-09-28 15:40:582022-09-28 15:41:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-28 15:41:01]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:7748kb
  • [2022-09-28 15:40:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
static constexpr int maxn = 800 + 5;
static constexpr int maxc = 400 * 400 + 5;

int c[maxc];

int n, m, a[maxn][maxn];
vector<int> ys[maxn];
vector<int> as;

static constexpr int dx[] = {0, 0, -1, 1};
static constexpr int dy[] = {1, -1, 0, 0};
int vis[maxn][maxn], visc;

int ans;
void bfs(int sx, int sy) {
    if (vis[sx][sy] == visc) return;
    queue<pair<int, int>> q;
    auto enqueue = [&](int x, int y){
        vis[x][y] = visc;
        if (c[a[x][y]]++ == 0) ans++;
        as.push_back(a[x][y]);
        q.emplace(x, y);
    };
    enqueue(sx, sy);
    while (not q.empty()) {
        auto [x, y] = q.front(); q.pop();
        for (int d = 0; d < 4; ++d) {
            int nx = x + dx[d], ny = y + dy[d];
            if (vis[nx][ny] == visc) continue;
            nx += dx[d], ny += dy[d];
            if (vis[nx][ny] == visc) continue;
            enqueue(nx, ny);
        }
    }
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int t; cin >> t;
    while (t--) {
        int q; cin >> n >> m >> q;
        for (int i = 0; i < n; ++i)
            for (int j = 0; j < m; ++j)
                cin >> a[2 * i + 1][2 * j + 1];
        while (q--) {
            int ox, oy;
            cin >> ox >> oy;
            string p; cin >> p;

            ++visc;

            ox *= 2, oy *= 2;

            vector<int> xs;
            auto put = [&](int x, int y) {
                if (x & 1) {
                    xs.push_back(x);
                    ys[x].push_back(y);
                }
                vis[x][y] = visc;
            };
            int cx = ox, cy = oy;
            for (auto pi : p) {
                if (pi == 'L') {
                    put(--cx, cy);
                    put(--cx, cy);
                } else if (pi == 'R') {
                    put(++cx, cy);
                    put(++cx, cy);
                } else if (pi == 'D') {
                    put(cx, --cy);
                    put(cx, --cy);
                } else {
                    put(cx, ++cy);
                    put(cx, ++cy);
                }
            }

            for (auto x : xs) {
                for (size_t i = 0; i < ys[x].size(); i += 2) {
                    bfs(x, ys[x][i] + 1);
                }
                ys[x].clear();
            }
            cout << ans << '\n';
            ans = 0;
            for (auto ai : as) c[ai] = 0;
            as.clear();
        }
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 7748kb

input:

1
3 3 2
1 2 3
1 1 2
7 8 9
0 0 RRRUUULLLDDD
0 0 RRUULLDD

output:

6
2

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

10
353 304 4000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98...

output:


result: