QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#720562 | #9564. Hey, Have You Seen My Kangaroo? | Chinese_zjc_ | ML | 1ms | 7716kb | C++14 | 2.1kb | 2024-11-07 13:18:46 | 2024-11-07 13:18:46 |
Judging History
answer
// This Code was made by Chinese_zjc_.
#include <bits/stdc++.h>
int n, m, k, mv[200005][205], in[200005], p[200005], q[200005], vis[200005];
long long ANS[200005];
char a[200005];
std::string s;
std::vector<int> g;
int move(int pos, char c)
{
int x = pos / m, y = pos % m;
switch (c)
{
case 'U':
--x;
break;
case 'D':
++x;
break;
case 'L':
--y;
break;
case 'R':
++y;
break;
}
return x >= 0 && x < n && y >= 0 && y < m && a[x * m + y] == '1' ? x * m + y : pos;
}
signed main()
{
std::ios::sync_with_stdio(false);
std::cin >> n >> m >> k >> s;
for (int i = 0; i != n * m; ++i)
std::cin >> a[i];
for (int i = 0; i != n * m; ++i)
if (a[i] == '1')
{
mv[i][0] = i;
for (int j = 0; j != k; ++j)
mv[i][j + 1] = move(mv[i][j], s[j]);
++in[mv[i][k]];
}
std::queue<int> que;
for (int i = 0; i != n * m; ++i)
if (a[i] == '1' && !in[i])
que.push(i);
while (!que.empty())
{
int now = que.front();
que.pop();
g.push_back(now);
if (!--in[mv[now][k]])
que.push(mv[now][k]);
}
for (auto i : g)
p[mv[i][k]] = p[i] + 1;
for (int i = 0; i != n * m; ++i)
if (in[i])
p[i] = n * m + 1, g.push_back(i);
std::reverse(g.begin(), g.end());
for (int i = 1; i <= k; ++i)
for (auto j : g)
{
if (!q[j] && vis[mv[j][i]] == i)
q[j] = i;
vis[mv[j][i]] = i;
}
std::vector<long long> ans;
for (auto i : g)
if (q[i])
for (int j = 0; j <= p[i]; ++j)
ans.push_back(1ll * j * k + q[i]);
std::sort(ans.begin(), ans.end());
std::fill(ANS, ANS + g.size() - ans.size(), -1);
for (std::size_t i = 0; i != ans.size(); ++i)
ANS[g.size() - i - 1] = ans[i];
for (int i = 1; i <= n * m; ++i)
std::cout << ANS[i] << std::endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5908kb
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: 1ms
memory: 5872kb
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: 1ms
memory: 7716kb
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: -100
Memory Limit Exceeded
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...