QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#250107#4788. GravityyyzRE 0ms3612kbC++142.2kb2023-11-12 21:26:462023-11-12 21:26:47

Judging History

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

  • [2023-11-12 21:26:47]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3612kb
  • [2023-11-12 21:26:46]
  • 提交

answer

#include <bits/stdc++.h>
#define V vector
#define Vi vector<int>
#define sz(a) ((int)a.size())
#define fi first
#define se second
#define Int pair<int, short>
#define Inf ((int)1e9)
#define pb push_back
#define ins insert
#define For(i, x, y) for (auto i = (x); i <= (y); i++)
#define Rep(i, x, y) for (auto i = (x); i >= (y); i--)
#define all(a) a.begin(), a.end()
#define IO(x) freopen(#x ".in", "r", stdin), freopen(#x ".out", "w", stdout);
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int main() {
#ifndef ONLINE_JUDGE
  IO(1);
#endif
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int n, m;
  cin >> n >> m;
  V<string> st(n + 5);
  For(i, 1, n) cin >> st[i], st[i] = " " + st[i];
  // V<V<Int>> vec(n * m + 5);
  // For(i, 1, m) vec[0].pb({n + 1, i});
  int tot = 0;
  V<Vi> vis(n + 5, Vi(m + 5));
  auto dfs = [&](auto lf, int x, int y) -> void {
    // vec[tot].pb({x, y});
    vis[x][y] = tot;
    For(i, 0, 3) {
      int xx = x + dx[i], yy = y + dy[i];
      if (xx >= 1 && yy >= 1 && xx <= n && yy <= m && !vis[xx][yy] &&
          st[xx][yy] == '#')
        lf(lf, xx, yy);
    }
  };
  For(i, 1, n) For(j, 1, m) if (!vis[i][j] && st[i][j] == '#') tot++,
      dfs(dfs, i, j);
  V<V<Int>> e(tot + 5);
  For(i, 1, n + 1) For(j, 1, m) if (vis[i][j] || i == n + 1) {
    Rep(k, i - 1, 1) if (vis[k][j]) {
      // cout << k << ' ' << vis[k][y] << endl;
      if (vis[k][j] != vis[i][j]) e[vis[i][j]].pb({vis[k][j], i - k - 1});
      break;
    }
  }
  priority_queue<Int, V<Int>, greater<Int>> q;
  Vi dis(tot + 5, Inf);
  q.push({dis[0] = 0, 0});
  V<bool> gg(tot + 5);
  // cout << 111 << endl;
  while (!q.empty()) {
    int x = q.top().se;
    // cout << x << endl;
    q.pop();
    if (gg[x]) continue;
    gg[x] = 1;
    for (auto i : e[x]) {
      // cout << i.fi << ' ' << i.se << endl;
      if (dis[i.fi] > dis[x] + i.se) q.push({dis[i.fi] = dis[x] + i.se, i.fi});
    }
  }
  // For(i, 1, tot) cout << dis[i] << ' ';
  // cout << endl;
  V<V<char>> ch(n + 5, V<char>(m + 5, '.'));
  For(i, 1, n) For(j, 1, m) if (vis[i][j]) ch[i + dis[vis[i][j]]][j] = st[i][j];
  For(i, 1, n) {
    For(j, 1, m) cout << ch[i][j];
    cout << '\n';
  }
}

詳細信息

Test #1:

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

input:

10 10
..........
..######..
..#....#..
..#.#..#..
..#..#.#..
..#....#..
..######..
..........
..#....#..
.......#..


output:

..........
..........
..######..
..#....#..
..#....#..
..#....#..
..#.##.#..
..######..
.......#..
..#....#..

result:

ok 10 lines

Test #2:

score: -100
Runtime Error

input:

1583 1799
#..###..##..#.####.##.##.###..#.....##..#.#.#.#......#.....##..#.##...#.#....#..##.###...#...##.###.#.....#.##.###...#..##.#...###..#.###.#...###..#.......#...#....#.#..#...##........#.#..#..##.....###...#..#.####..####...#..##......#........#..#.##.##..#..#....##.##.##..#..##.....###....#...

output:


result: