QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#796815 | #9564. Hey, Have You Seen My Kangaroo? | fryan | WA | 227ms | 52216kb | C++14 | 4.8kb | 2024-12-02 05:52:53 | 2024-12-02 05:52:54 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
#define int long long
#define V vector
const int inf = 1e9;
const int mxn = 4e5+50;
void chmin(int &a, int b) {
a = min(a,b);
}
int n,m,k;
V<V<int>> g;
string s;
V<V<int>> gg[2];
V<array<int,2>> mg;
int kil[mxn],to[mxn];
int in_deg[mxn];
int depth[mxn];
vector<int> adj[mxn];
vector<array<int,3>> iter_order;
queue<int> topsort;
int cnt = 0, ans[mxn];
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin>>n>>m>>k>>s;
g.resize(n+5);
g[0].resize(m+5);
g[n+1].resize(m+5);
for (int i=1; i<=n; i++) {
g[i].resize(m+5);
for (int j=1; j<=m; j++) {
char c; cin>>c;
g[i][j] = c-'0';
if (g[i][j]) cnt++;
}
}
//macro
for (int x=1; x<=n; x++)
for (int y=1; y<=m; y++) {
if (!g[x][y]) continue;
int cx = x, cy = y;
for (int i=0; i<k; i++) {
if (s[i]=='U') {if (g[cx-1][cy]) cx--;}
else if (s[i]=='D') {if (g[cx+1][cy]) cx++;}
else if (s[i]=='L') {if (g[cx][cy-1]) cy--;}
else if (s[i]=='R') {if (g[cx][cy+1]) cy++;}
}
to[x*m+y] = cx*m+cy;
in_deg[cx*m+cy]++;
adj[cx*m+cy].push_back(x*m+y);
}
for (int x=1; x<=n; x++)
for (int y=1; y<=m; y++)
if (g[x][y] && !in_deg[x*m+y])
topsort.push(x*m+y);
fill(depth,depth+mxn,1);
while (sz(topsort)) {
int v = topsort.front(); topsort.pop();
depth[to[v]] = max(depth[to[v]],depth[v]+1);
in_deg[to[v]]--;
if (!in_deg[to[v]]) {topsort.push(to[v]);}
}
for (int x=1; x<=n; x++)
for (int y=1; y<=m; y++)
if (g[x][y] && in_deg[x*m+y])
depth[x*m+y] = inf;
//micro
int cp = 0, pp = 1;
gg[0].resize(n+5); gg[1].resize(n+5);gg[0][0].resize(m+5);
gg[0][n+1].resize(m+5);gg[1][0].resize(m+5);gg[1][n+1].resize(m+5);
for (int i=1; i<=n; i++) {
gg[0][i].resize(m+5);
gg[1][i].resize(m+5);
for (int j=1; j<=m; j++) if (g[i][j]) gg[cp][i][j] = i*m+j;
}
fill(kil,kil+mxn,inf);
// memset(kil,0x3f,sizeof(kil));
for (int i=0; i<k; i++) {
swap(cp,pp);
for (int x=1; x<=n; x++)
for (int y=1; y<=m; y++)
gg[cp][x][y] = 0;
for (int x=1; x<=n; x++)
for (int y=1; y<=m; y++) {
if (!gg[pp][x][y]) continue;
if (s[i]=='U') {
if (g[x-1][y]) {
if (gg[cp][x-1][y]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x-1][y]]) {swap(gg[pp][x][y],gg[cp][x-1][y]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x-1][y] = gg[pp][x][y];
} else {
if (gg[cp][x][y]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x][y]]) {swap(gg[pp][x][y],gg[cp][x][y]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x][y] = gg[pp][x][y];
}
} else if (s[i]=='D') {
if (g[x+1][y]) {
if (gg[cp][x+1][y]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x+1][y]]) {swap(gg[pp][x][y],gg[cp][x+1][y]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x+1][y] = gg[pp][x][y];
} else {
if (gg[cp][x][y]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x][y]]) {swap(gg[pp][x][y],gg[cp][x][y]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x][y] = gg[pp][x][y];
}
} else if (s[i]=='L') {
if (g[x][y-1]) {
if (gg[cp][x][y-1]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x][y-1]]) {swap(gg[pp][x][y],gg[cp][x][y-1]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x][y-1] = gg[pp][x][y];
} else {
if (gg[cp][x][y]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x][y]]) {swap(gg[pp][x][y],gg[cp][x][y]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x][y] = gg[pp][x][y];
}
} else if (s[i]=='R') {
if (g[x][y+1]) {
if (gg[cp][x][y+1]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x][y+1]]) {swap(gg[pp][x][y],gg[cp][x][y+1]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x][y+1] = gg[pp][x][y];
} else {
if (gg[cp][x][y]) {
if (depth[gg[pp][x][y]] > depth[gg[cp][x][y]]) {swap(gg[pp][x][y],gg[cp][x][y]);}
kil[gg[pp][x][y]] = i;
} else gg[cp][x][y] = gg[pp][x][y];
}
}
}
}
for (int x=1; x<=n; x++)
for (int y=1; y<=m; y++)
if (g[x][y] && sz(adj[x*m+y]))
iter_order.push_back({depth[x*m+y],x,y});
vector<int> kill_times;
sort(all(iter_order));
for (auto [D,X,Y] : iter_order) {
int lock = adj[X*m+Y][0];
for (int i : adj[X*m+Y]) {
if (depth[i] > depth[lock]) lock = i;
}
for (int i : adj[X*m+Y]) {
if (i==lock) continue;
for (int j=0; j<depth[i]; j++) {
kill_times.push_back(kil[i]+j*k+1);
}
}
}
sort(all(kill_times));
reverse(all(kill_times));
int cn = cnt;
while (sz(kill_times)) {
int t = kill_times.back();
ans[--cn] = t;
kill_times.pop_back();
}
for (int i=1; i<cn; i++) ans[i] = -1;
for (int i=1; i<=m*n; i++) {
cout<<ans[i]<<"\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 21296kb
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: 3ms
memory: 19148kb
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: 6ms
memory: 19508kb
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: 227ms
memory: 52216kb
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: 0
Accepted
time: 223ms
memory: 46904kb
input:
2 100000 200 UULDRDLURDLDDRDRDUULDLUUULLRURLUUDDDRURURLLRRUDLDDDUDDRRUUURDDULURURLRULLUDLULURUUDURLDRRRDULRDLRRLDUUUDDUUDUDRDRUDLDRRUDRDLDRDLDRRDLRRDRDLRRLUDUDRULLRRLDDLUDDULDRLLLDLURRDDULDDUDULLRRRUURLRRRLURDLRLU 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 384513 384490 384313 384290 384113 384090 383913 383890 383713 383690 383513 383490 383313 383290 383113 383090 382913 382890 382713 382690 382513 382490 382313 382290 382113 382090 381913 381890 381713 381690 381513 381490 381313 381290 381113 381090 380...
result:
ok 200000 numbers
Test #6:
score: -100
Wrong Answer
time: 191ms
memory: 41576kb
input:
5 40000 200 URDDRRUDURLDLUUDUUDDLRRRURULURDRRURRURULUULRRLDLLDUURRDRUULRULULUDRURRRURDDLLDDRLLLUDUDLLDDULUUUULDLDUDLULLDRURRDRDULURLLLUDLRRRDRLUDDUURULURRRDLDRUDLURUUULDLURDDDRRLLLDLRRDLDLDRRURRRRDLRRLLULRRLDUULD 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
1000000001 1000000001 1000000001 1000036 999836 999636 999436 999236 999036 998836 998636 998436 998236 998036 997836 997636 997436 997236 997036 996836 996636 996436 996236 996036 995836 995636 995436 995236 995036 994836 994636 994436 994236 994036 993836 993636 993436 993236 993036 992836 992636 ...
result:
wrong answer 1st numbers differ - expected: '1000036', found: '1000000001'