QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#722032#9564. Hey, Have You Seen My Kangaroo?ucup-team902WA 4ms17880kbC++203.8kb2024-11-07 17:30:542024-11-07 17:30:54

Judging History

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

  • [2024-11-07 17:30:54]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:17880kb
  • [2024-11-07 17:30:54]
  • 提交

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]=1,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));
	}
	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(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]){
				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);
	freopen("1.out","w",stdout);
	#endif
    int T = 1;
    while (T--) solve();
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 17880kb

input:

3 3 6
ULDDRR
010
111
010

output:

6
4
4
2
2
1
1
1
0

result:

wrong answer 1st numbers differ - expected: '-1', found: '6'