QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#721998 | #9564. Hey, Have You Seen My Kangaroo? | ucup-team902 | WA | 518ms | 42488kb | C++20 | 3.9kb | 2024-11-07 17:25:14 | 2024-11-07 17:25:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define cs const
#define re register
#define pb push_back
#define y0 sxxxxx
#define pii pair<int, int>
#define ll long long
#define fi first
#define se second
#define bg begin
namespace IO{
cs int RLEN=1<<22|1;
char ibuf[RLEN],*ib,*ob;
inline char gc(){
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return (ib==ob)?EOF:*ib++;
}
inline int read(){
char ch=gc();
int res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline ll readll(){
char ch=gc();
ll res=0;bool f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res*10)+(ch^48),ch=gc();
return f?res:-res;
}
inline char readchar(){
char ch=gc();
while(isspace(ch))ch=gc();
return ch;
}
inline int readstring(char *s){
int top=0;char ch=gc();
while(isspace(ch))ch=gc();
while(!isspace(ch)&&ch!=EOF)s[++top]=ch,ch=gc();
s[top+1]='\0';return top;
}
}
using IO::read;
using IO::readll;
using IO::readchar;
using IO::readstring;
template <typename tp>
inline void chemx(tp &a, tp b) { (a < b) ? (a = b) : 0; }
template <typename tp>
inline void chemn(tp &a, tp b) { (a > b) ? (a = b) : 0; }
cs int N=200005;
vector<vector<int>>a,g;
int n,m,k;
char s[205],ss[N];
vector<int>e[N];
set<int>son[N];
int inq[N],d[N],sn[N];
int ans;
int out[N];
pii ps[N];
int id(int i,int j){
return (i-1)*m+j;
}
void solve(){
n=read(),m=read(),k=read();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
ps[id(i,j)]=pii(i,j);
a.resize(n+2);g.resize(n+2);
for(int i=0;i<=n+1;i++)a[i].resize(m+2,0),g[i].resize(m+2,0);
readstring(s);
for(int i=1;i<=n;i++){
readstring(ss);
for(int j=1;j<=m;j++)a[i][j]=ss[j]-'0',ans+=a[i][j];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)if(a[i][j]==1){
int x=i,y=j;
for(int l=1;l<=k;l++){
int px=x,py=y;
if(s[l]=='U'){
px--;
}
if(s[l]=='D'){
px++;
}
if(s[l]=='L'){
py--;
}
if(s[l]=='R'){
py++;
}
if(px<1||px>n||py<1||py>m)continue;
if(a[px][py]==0)continue;
x=px,y=py;
}
d[id(x,y)]++;
sn[id(x,y)]++;
son[id(x,y)].insert(id(i,j));
e[id(i,j)].pb(id(x,y));
// cout<<id(i,j)<<" "<<id(x,y)<<'\n';
}
queue<int> q;
for(int i=1;i<=n*m;i++)inq[i]=1;
for(int i=1;i<=n*m;i++)if(!d[i])q.push(i);
while(q.size()){
int u=q.front();q.pop();
inq[u]=0;
for(int v:e[u]){
d[v]--;
if(d[v]==0)q.push(v);
}
}
vector<int> leaf;//nd:deg>1
set<int>nd;
for(int i=1;i<=n*m;i++)if(sn[i]>1)nd.insert(i);
for(int i=1;i<=n*m;i++)if(!inq[i]&&sn[i]==0)leaf.pb(i);
int ti=0;
for(int t=1;t<=n*m;t++){
if(!leaf.size())break;
vector<pii> idx;
for(int x:nd){
for(int y:son[x]){
idx.pb(ps[y]);
}
}
//for(pii v:idx)cout<<v.fi<<" "<<v.se<<'\n';
for(int i=1;i<=k;i++){
// cout<<"Now "<<i<<'\n';
vector<pii> nid;
for(pii v:idx){
int px=v.fi,py=v.se;
if(s[i]=='U'){
px--;
}
if(s[i]=='D'){
px++;
}
if(s[i]=='L'){
py--;
}
if(s[i]=='R'){
py++;
}
if(px<1||px>n||py<1||py>m);
else if(a[px][py]==0);
else v=pii(px,py);
// cout<<v.fi<<" "<<v.se<<'\n';
if(g[v.fi][v.se]){
ans--;
out[ans]=i+(t-1)*k;
}
else{
g[v.fi][v.se]=1;
nid.pb(v);
}
}
for(pii v:nid){
g[v.fi][v.se]=0;
}
idx=nid;
}
vector<int>newleaf;
for(int x:leaf){
for(int v:e[x])if(!inq[v]){
sn[v]--;
if(sn[v]==0)newleaf.pb(v);
if(sn[v]==1)nd.erase(nd.find(v));
son[v].erase(son[v].find(x));
}
}
leaf=newleaf;
}
for(int i=1;i<ans;i++)out[i]=-1;
for(int i=1;i<=n*m;i++)cout<<out[i]<<'\n';
}
int main() {
#ifdef Stargazer
freopen("1.in","r",stdin);
#endif
int T = 1;
while (T--) solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 15816kb
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: 4ms
memory: 17952kb
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: 17884kb
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
Wrong Answer
time: 518ms
memory: 42488kb
input:
1 200000 200 RDRLDRULURDLDRULLRULLRRULRULRDLLDLRUDDLRURLURLULDRUUURDLUDUDLLLLLURRDURLUDDRRLRRURUUDDLLDDUUUDUULRLRUDULRRUURUDDDDLULULLLLLLLLLLLUDURLURLRLLRRRURUURLUDULDUULRRLULLRUDRDRUUDDRUDRDLLDLURDDDURLUULDRRDLDD 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
2857123 2857065 2857064 2857063 2857062 2857034 2857021 2856940 2856929 2856928 2856927 2856926 2856925 2856924 2856923 2856865 2856864 2856863 2856862 2856834 2856821 2856740 2856729 2856728 2856727 2856726 2856725 2856724 2856723 2856665 2856664 2856663 2856662 2856634 2856621 2856540 2856529 2856...
result:
wrong answer 1st numbers differ - expected: '3999923', found: '2857123'