QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#773081 | #7751. Palindrome Path | Crysfly | WA | 45ms | 4412kb | C++14 | 2.7kb | 2024-11-23 00:38:36 | 2024-11-23 00:38:37 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define ll __int128
//#define ull unsigned long long
#define int long long
#define SZ(x) ((int)((x).size()))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
return f?-x:x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<ll,ll>pii;
typedef vector<int>vi;
#define maxn 500005
#define inf 0x3f3f3f3f
int n,m,sx,sy,tx,ty;
int a[33][33];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
string opt="DRUL";
bool vis[33][33],vis2[33][33];
string res;
int vis3[33][33],sum3,nd;
bool mov(int d){
int sum=0;
memset(vis2,0,sizeof vis2);
For(i,1,n)For(j,1,m)if(vis[i][j]){
if(!a[i+dx[d]][j+dy[d]]) vis2[i][j]=1;
if(a[i-dx[d]][j-dy[d]]) vis2[i-dx[d]][j-dy[d]]=1;
}
For(i,1,n)For(j,1,m)sum+=vis2[i][j];
if(!sum) return 0;
memcpy(vis,vis2,sizeof vis2);
res+=opt[d];
if(a[sx+dx[d]][sy+dy[d]]) sx+=dx[d],sy+=dy[d];
if(!vis3[sx][sy]) vis3[sx][sy]=1,++sum3;
if(vis[sx][sy] && sum3==nd) {
string rev=res;
reverse(rev.begin(),rev.end());
cout<<res+rev<<"\n";
exit(0);
}
// cout<<"now "<<sx<<" "<<sy<<"\n";
// For(i,1,n)For(j,1,m)cout<<vis2[i][j]<<" \n"[j==m];
if(res.size()>500000){
puts("-1");
exit(0);
}
return 1;
}
bool vs[33][33];
void dfs(int x,int y){
// cout<<"DFS "<<x<<" "<<y<<"\n";
vs[x][y]=1;
while(1){
bool ok=0;
For(i,0,3)
if(a[x+dx[i]][y+dy[i]] && !vs[x+dx[i]][y+dy[i]]) {
if(mov(i)) {
dfs(x+dx[i],y+dy[i]);
assert(mov(i^2));
ok=1;
}
}
if(!ok)break;
}
}
mt19937_64 rnd(64);
void work()
{
n=read(),m=read();
For(i,1,n){
string s;cin>>s;
For(j,1,m)a[i][j]=(s[j-1]&1),nd+=a[i][j];
}
sx=read(),sy=read(),tx=read(),ty=read();
vis[tx][ty]=1;
vis3[sx][sy]=1; sum3=1;
dfs(sx,sy);
while(1){
int d=rnd()%4;
For(_,1,max(n,m)) mov(d);
}
}
/*
*/
signed main()
{
// freopen("my.out","w",stdout);
int T=1;
while(T--)work();
return 0;
}
/*
9 30
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
100000000000000000000000000000
111111111111111111111111111111
000000000000000000000000000001
111111111111111111111111111111
1 1 9 30
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3556kb
input:
2 2 11 11 1 1 2 2
output:
DRUURD
result:
ok Valid Solution (Length = 6).
Test #2:
score: 0
Accepted
time: 20ms
memory: 4412kb
input:
2 2 10 01 1 1 2 2
output:
-1
result:
ok No Solution.
Test #3:
score: 0
Accepted
time: 1ms
memory: 3624kb
input:
1 1 1 1 1 1 1
output:
RR
result:
ok Valid Solution (Length = 2).
Test #4:
score: -100
Wrong Answer
time: 45ms
memory: 4176kb
input:
5 4 1111 1111 1111 1111 1111 4 2 4 2
output:
-1
result:
wrong answer Solution Exists, But -1 Found.