Uva 11661 - Burger Time?
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define sf scanf
#define pf printf
using namespace std;
typedef long long LL;
char ch[2000000+5];
int main()
{
LL t,i;
while(~sf("%lld",&t) and t)
{
getchar();
for(i=1;i<=t;i++)
{
sf("%c",&ch[i]);
}
bool f=false;
LL dist_r=0, dist_d=0, mn=2000000000;
for(i=1;i<=t;i++)
{
if(ch[i] == 'Z')
{
f=true;
break;
}
else
{
if(ch[i] == 'R')
{
dist_r=i;
if(dist_d)
{
mn = min(mn, abs(dist_r - dist_d));
}
}
if(ch[i] == 'D')
{
dist_d = i;
if(dist_r)
{
mn = min(mn, abs(dist_r - dist_d));
}
}
//cout << mn << " ";
}
}
if(f)
{
pf("0\n");
}
else
{
pf("%lld\n", mn);
}
}
return 0;
}
#include<cstdio>
#include<cstring>
#include<algorithm>
#define sf scanf
#define pf printf
using namespace std;
typedef long long LL;
char ch[2000000+5];
int main()
{
LL t,i;
while(~sf("%lld",&t) and t)
{
getchar();
for(i=1;i<=t;i++)
{
sf("%c",&ch[i]);
}
bool f=false;
LL dist_r=0, dist_d=0, mn=2000000000;
for(i=1;i<=t;i++)
{
if(ch[i] == 'Z')
{
f=true;
break;
}
else
{
if(ch[i] == 'R')
{
dist_r=i;
if(dist_d)
{
mn = min(mn, abs(dist_r - dist_d));
}
}
if(ch[i] == 'D')
{
dist_d = i;
if(dist_r)
{
mn = min(mn, abs(dist_r - dist_d));
}
}
//cout << mn << " ";
}
}
if(f)
{
pf("0\n");
}
else
{
pf("%lld\n", mn);
}
}
return 0;
}
Comments
Post a Comment