QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268810#7751. Palindrome Pathucup-team134#WA 0ms3816kbC++175.6kb2023-11-28 21:41:382023-11-28 21:41:38

Judging History

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

  • [2023-11-28 21:41:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2023-11-28 21:41:38]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ld long double
#define li __int128

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<int D, typename T>struct vec : public vector<vec<D - 1, T>> {template<typename... Args>vec(int n = 0, Args... args) : vector<vec<D - 1, T>>(n, vec<D - 1, T>(args...)) {}};
template<typename T>struct vec<1, T> : public vector<T> {vec(int n = 0, T val = T()) : vector<T>(n, val) {}};
template<class T1,class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const deque<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const set<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T> ostream& operator<<(ostream& os, const multiset<T,greater<T> >& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
template<class T1,class T2> ostream& operator<<(ostream& os, const map<T1,T2>& a) {os << '{';int i=0;for(auto p:a){if(i>0&&i<sz(a))os << ", ";os << p;i++;}os << '}';return os;}
int ri(){int x;scanf("%i",&x);return x;}
void rd(int&x){scanf("%i",&x);}
void rd(long long&x){scanf("%lld",&x);}
void rd(double&x){scanf("%lf",&x);}
void rd(long double&x){scanf("%Lf",&x);}
void rd(string&x){cin>>x;}
void rd(char*x){scanf("%s",x);}
template<typename T1,typename T2>void rd(pair<T1,T2>&x){rd(x.first);rd(x.second);}
template<typename T>void rd(vector<T>&x){for(T&p:x)rd(p);}
template<typename C,typename...T>void rd(C&a,T&...args){rd(a);rd(args...);}
//istream& operator>>(istream& is,__int128& a){string s;is>>s;a=0;int i=0;bool neg=false;if(s[0]=='-')neg=true,i++;for(;i<s.size();i++)a=a*10+s[i]-'0';if(neg)a*=-1;return is;}
//ostream& operator<<(ostream& os,__int128 a){bool neg=false;if(a<0)neg=true,a*=-1;ll high=(a/(__int128)1e18);ll low=(a-(__int128)1e18*high);string res;if(neg)res+='-';if(high>0){res+=to_string(high);string temp=to_string(low);res+=string(18-temp.size(),'0');res+=temp;}else res+=to_string(low);os<<res;return os;}

const int N=30;
bool in[N][N];
int n,m;
bool visited[N][N];
string dir="ULDR";
vector<pair<int,int>> di={{-1,0},{0,-1},{1,0},{0,1}};
pair<int,int> makeMove(pair<int,int> a,int d){
	pair<int,int> b=a;
	a.f+=di[d].f;
	a.s+=di[d].s;
	if(a.f>=0&&a.f<n&&a.s>=0&&a.s<m&&in[a.f][a.s]){
		return a;
	}
	return b;
}
vector<int> moves;
int totalVis=0;
void dfs(pair<int,int> a){
	visited[a.f][a.s]=1;
	totalVis++;
	//cout << a << endl;
	for(int i=0;i<4;i++){
		pair<int,int> nxt=makeMove(a,i);
		//cout << "nxt "<< nxt << endl;
		if(!visited[nxt.f][nxt.s]){
			moves.pb(i);
			dfs(nxt);
			moves.pb((i+2)%4);
		}
	}
}
bool dist[N][N][N][N];
pair<pair<pair<int,int>,pair<int,int>>,int> par[N][N][N][N];
int main()
{
	rd(n,m);
	int cnt=0;
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		for(int j=0;j<m;j++){
			in[i][j]=s[j]=='1';
			cnt+=in[i][j];
		}
	}
	pair<int,int> s,e;
	rd(s,e);
	s.f--;
	s.s--;
	e.f--;
	e.s--;
	dfs(e);
	if(cnt!=totalVis){
		printf("-1\n");
		return 0;
	}
	for(auto p:moves){
		s=makeMove(s,p);
	}
	dist[s.f][s.s][e.f][e.s]=1;
	queue<pair<pair<int,int>,pair<int,int>>> q;
	q.push({s,e});
	pair<pair<int,int>,pair<int,int>> fin;
	bool finished=0;
	int extraMove=-1;
	while(sz(q)&&!finished){
		auto tr=q.front();
		auto s=tr.f;
		auto e=tr.s;
		q.pop();
		if(s==e){
			fin=tr;
			finished=1;
			break;
		}
		for(int i=0;i<4;i++){
			pair<int,int> s2=makeMove(s,i);
			if(s2==e){
				extraMove=i;
				fin=tr;
				finished=1;
				break;
			}
			pair<int,int> e2=makeMove(e,(i+2)%4);
			if(dist[s2.f][s2.s][e2.f][e2.s]==0){
				dist[s2.f][s2.s][e2.f][e2.s]=1;
				par[s2.f][s2.s][e2.f][e2.s]={tr,i};
				q.push({s2,e2});
			}
		}
		for(int i=0;i<4;i++){
			if(makeMove(e,i)==e){
				pair<int,int> s2=makeMove(s,i);
				pair<int,int> e2=e;
				if(dist[s2.f][s2.s][e2.f][e2.s]==0){
					dist[s2.f][s2.s][e2.f][e2.s]=1;
					par[s2.f][s2.s][e2.f][e2.s]={tr,i};
					q.push({s2,e2});
				}
			}
		}
		
	}
	if(!finished){
		assert(0);
	}
	vector<int> a;
	while(fin.f!=s||fin.s!=e){
		a.pb(par[fin.f.f][fin.f.s][fin.s.f][fin.s.s].s);
		fin=par[fin.f.f][fin.f.s][fin.s.f][fin.s.s].f;
	}
	reverse(all(a));
	for(auto p:a)
		moves.pb(p);
	for(auto p:moves){
		printf("%c",dir[p]);
	}
	if(extraMove!=-1)printf("%c",dir[extraMove]);
	reverse(all(moves));
	for(auto p:moves){
		printf("%c",dir[p]);
	}
	printf("\n");
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3816kb

input:

2 2
11
11
1 1 2 2

output:

ULDURDDRUDLU

result:

wrong answer End Point Is (1,1), Not (er = 2, ec = 2)