纪念我逝去的21分
掉到了1300
C. Yet Another Walking Robot
我和题解很接近了
这题也很容易想到用map<点坐标,位置>来做
每经过一个点就把点坐标放进去,如果坐标已经被标记过了,就证明这是一个可行答案
然后O(n)的扫一遍,取长度最小的答案即可
(我因为加了取消同步输入输出,而且既用了puts又用了cout,所以wa到最后。。。
一定要记得:
cout和printf(puts)不能一起用!!!
cin和scanf不能一起用!!!
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define rg register
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
A ans=1;
for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
return ans;
}
inline int read()
{
int X=0,w=1;
char c=getchar();
while(c<'0'||c>'9')
{
if (c=='-')
{
w=-1;
}
c=getchar();
}
while(c>='0'&&c<='9')
{
X=(X<<3)+(X<<1)+(c^48);
c=getchar();
}
return X*w;
}
//inline void w(int x) { if(x>9) w(x/10); putchar(x%10+'0'); }
int t,n;
char str[200005];
//char biao[]={'D','L','R','U'};
map<pair<int,int> ,int>um;
void solve(){
um.clear();
cin>>n>>str;
bool f=0;
int x=0,y=0,l=0,r=1e9,tl=-1,tr=-1;
// um[make_pair(0,0)]=1;
for(int i=0;i<=n;i++){
// um[make_pair(x,y)]=1+i;
if(um.count(make_pair(x,y))){
tl=um[make_pair(x,y)];
tr=i;
if(tr-tl<r-l){
/* if(tl!=1){
tl++;
}
*/
r=tr;
l=tl;
}
}
um[make_pair(x,y)]=i+1;
if(i==n){
break;
}
if(str[i]=='L'){
x--;
}else if(str[i]=='R'){
x++;
}else if(str[i]=='U'){
y++;
}else {
y--;
}
}
if(l==0){
printf("-1\n");
// cout<<"-1"<<endl;
}else{
printf("%d %d\n",l,r);
// cout<<l<<" "<<r<<endl;
}
}
int main(){
std::ios::sync_with_stdio(0);
cin>>t;
while(t--){
solve();
}
return 0;
}