QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#731407#9564. Hey, Have You Seen My Kangaroo?ucup-team3215WA 1098ms39532kbC++202.6kb2024-11-10 03:26:412024-11-10 03:26:42

Judging History

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

  • [2024-11-10 03:26:42]
  • 评测
  • 测评结果:WA
  • 用时:1098ms
  • 内存:39532kb
  • [2024-11-10 03:26:41]
  • 提交

answer

#define tm xndisfbcgsf
#include <bits/stdc++.h>
#undef tm

using namespace std;

constexpr int N = 2e5, L = 20;

string s, a;
int n, m, k, jump[L][N], mark[N], tm;
vector<int> preim[N];
vector<int> merges;

void adv(int& i, int& j, int k) {
  int di = s[k] == 'U'? -1: s[k] == 'D';
  int dj = s[k] == 'L'? -1: s[k] == 'R';
  if (i + di >= 0 && i + di < n && j + dj >= 0 && j + dj < m && a[(i + di) * m + j + dj] == '1') i += di, j += dj;
}

int getpos(int i, int t) {
  for (int l = L; l--; ) if (t >> l & 1) i = jump[l][i];
  return i;
}

//int sz(const vector<int>& v, int t) {
//  ++tm;
//  int res = 0;
//  for (auto v: v) {
//    v = getpos(v, t);
//    res += mark[v] != tm;
//    mark[v] = tm;
//  }
//  return res;
//}

vector<int> shrink(const vector<int>& v, int l) {
  vector<int> res;
  ++tm;
  for (auto v: v) {
    v = jump[l][v];
    if (mark[v] != tm) res.push_back(v);
    mark[v] = tm;
  }
  return res;
}

void solve1(vector<int> v, int t) {
  vector<int> u;
  for (int i = 0; i < k; ++i) {
    ++tm;
    for (auto v: v) {
      int r = v / m, j = v % m;
      adv(r, j, i);
      v = r * m + j;
      if (mark[v] != tm) u.push_back(v), mark[v] = tm;
      else merges.push_back(t * k + i + 1);
    }
    swap(v = {}, u);
  }
  assert(v.size() == 1);
}

void solve(vector<int> v, int t) {
  int dt = 0;
  auto u = v;
  for (int l = L; l--; ) {
    auto w = shrink(u, l);
    if (w.size() * 2 >= v.size() && w.size() > 1) dt += 1 << l, swap(u, w);
  }
  if (!dt) u = shrink(u, 0), dt = 1;
  if (u.size() == v.size()) return;
  if (u.size() == 1 && dt == 1) return solve1(move(v), t);
  solve(u, t + dt);
  for (auto v: v) preim[getpos(v, dt)].push_back(v);
  vector<pair<int, vector<int>>> val;
  for (auto v: u) val.emplace_back(v, move(preim[v]));
  for (auto& [u, v]: val) solve(move(v), t);
}

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> m >> k >> s;
  string t;
  for (int i = 0; i < n; ++i) cin >> t, a += t;
  vector<int> all;
  for (int i = 0; i < n; ++i)
  for (int j = 0; j < m; ++j) if (a[i * m + j] == '1') {
    all.push_back(i * m + j);
    int ti = i, tj = j;
    for (int i = 0; i < k; ++i) adv(ti, tj, i);
    jump[0][i * m + j] = ti * m + tj;
  }
  for (int l = 0; l < L - 1; ++l)
  for (int i = 0; i < n * m; ++i) jump[l + 1][i] = jump[l][jump[l][i]];
  solve(all, 0);
  sort(merges.begin(), merges.end());
  vector<int> ans(all.size(), -1);
  copy(merges.begin(), merges.end(), ans.rbegin());
  ans.erase(ans.begin());
  ans.resize(n * m);
  for (auto ans: ans) cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3 6
ULDDRR
010
111
010

output:

-1
4
2
1
0
0
0
0
0

result:

ok 9 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 17964kb

input:

3 3 6
ULDDRR
010
111
011

output:

7
4
2
1
1
0
0
0
0

result:

ok 9 numbers

Test #3:

score: 0
Accepted
time: 0ms
memory: 17996kb

input:

1 5 1
R
11111

output:

4
3
2
1
0

result:

ok 5 number(s): "4 3 2 1 0"

Test #4:

score: 0
Accepted
time: 1098ms
memory: 39532kb

input:

1 200000 200
RDRLDRULURDLDRULLRULLRRULRULRDLLDLRUDDLRURLURLULDRUUURDLUDUDLLLLLURRDURLUDDRRLRRURUUDDLLDDUUUDUULRLRUDULRRUURUDDDDLULULLLLLLLLLLLUDURLURLRLLRRRURUURLUDULDUULRRLULLRUDRDRUUDDRUDRDLLDLURDDDURLUULDRRDLDD
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

3999923
3999865
3999864
3999740
3999729
3999728
3999727
3999726
3999725
3999724
3999723
3999665
3999664
3999540
3999529
3999528
3999527
3999526
3999525
3999524
3999523
3999465
3999464
3999340
3999329
3999328
3999327
3999326
3999325
3999324
3999323
3999265
3999264
3999140
3999129
3999128
3999127
3999...

result:

ok 200000 numbers

Test #5:

score: -100
Wrong Answer
time: 677ms
memory: 34292kb

input:

2 100000 200
UULDRDLURDLDDRDRDUULDLUUULLRURLUUDDDRURURLLRRUDLDDDUDDRRUUURDDULURURLRULLUDLULURUUDURLDRRRDULRDLRRLDUUUDDUUDUDRDRUDLDRRUDRDLDRDLDRRDLRRDRDLRRLUDUDRULLRRLDDLUDDULDRLLLDLURRDDULDDUDULLRRRUURLRRRLURDLRLU
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

wrong answer 16th numbers differ - expected: '384513', found: '-1'