I keep record of every position of D and R. Then use sort algorithm and search for the minimun.naseef_07cuet wrote:I already got accepted before your post.
By the way thank you.
This taks O(NlgN),so i get WA. Can you guys tell me the AC algorithm?
Moderator: Board moderators
I keep record of every position of D and R. Then use sort algorithm and search for the minimun.naseef_07cuet wrote:I already got accepted before your post.
By the way thank you.
Code: Select all
// Code removed after AC!
Code: Select all
3
RDZ
0
Code: Select all
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
#define MAX_N 2000000
int main(){
int l,i;
int dist,finalDist;
char c;
bool jackpot,rest;
/*
freopen("burger.in","r",stdin);
freopen("burger.out","w",stdout);
//*/
while(scanf("%d\n",&l)!=EOF){
if(!l) break;
finalDist = l;
dist = 0;
rest = false;
jackpot = false;
for(i=0;i<l;i++){
scanf("%c",&c);
if(jackpot) continue;
if(c=='Z'){
finalDist = 0;
jackpot = true;
continue;
}
if(c=='R'){
if(rest){
dist = 1; //reset
}
else{
rest = true;
if(dist) finalDist = min(finalDist,dist);
dist = 1;
}
}
else if(c=='D'){
if(rest){
rest = false;
finalDist = min(finalDist,dist);
}
else{
dist = 1; //reset
}
}
else if(c=='.' && dist){
dist++;
}
}
scanf("\n");
printf("%d\n",finalDist);
}
return 0;
}
Code: Select all
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
#define MAX_N 2000000
int main(){
int l,i;
int dist,finalDist;
char c;
bool jackpot,rest;
/*
freopen("burger.in","r",stdin);
freopen("burger.out","w",stdout);
//*/
while(scanf("%d\n",&l)!=EOF){
if(!l) break;
finalDist = l;
dist = 0;
rest = false;
jackpot = false;
for(i=0;i<l;i++){
scanf("%c",&c);
if(jackpot) continue;
if(c=='Z'){
finalDist = 0;
jackpot = true;
continue;
}
if(c=='R'){
if(rest){
dist = 1; //reset
}
else{
rest = true;
if(dist) finalDist = min(finalDist,dist);
dist = 1;
}
}
else if(c=='D'){
if(rest){
rest = false;
finalDist = min(finalDist,dist);
}
else{
dist = 1; //reset
}
}
else if(c=='.' && dist){
dist++;
}
}
scanf("\n");
printf("%d\n",finalDist);
}
return 0;
}
Code: Select all
2
RD
5
..Z..
10
.R......D.
10
.R..Z...D.
10
...D..R...
25
..D...R.RR...DD...D.R...R
3
RDZ
8
R.D...RD
5
RD...
5
DR...
6
DDDDDR
6
RRRRRD
12
DDDDRRRRZDRD
20
D..R...DR..D.......R
20
R..R...R..D....R..DR
20
D..R...R..D....R..RD
20
D..R...R..D....R..RZ
20
R..D...R.DD........R
0
Code: Select all
1
0
7
0
3
2
0
1
1
1
1
1
0
1
1
1
0
2
Code: Select all
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int t,temp;
char a,flag;
while(cin>>t,t)
{
cin.ignore();
flag=0; temp=t;
for(int i=0,j=0;i<t;i++)
{
a=getche();
if(a=='Z'||flag==5){flag=5;temp=0;}
else if(a=='R')
{
if(flag==0)
{
flag='R';
j=i;
}
else if(flag=='R') j=i;
else if(flag=='D')
{
flag='R';
if(i-j<temp)temp=i-j;
j=i;
}
}
else if(a=='D')
{
if(flag==0)
{
flag='D';
j=i;
}
else if(flag=='D') j=i;
else if(flag=='R')
{
flag='D';
if(i-j<temp)temp=i-j;
j=i;
}
}
if(i==t-1) cin.ignore();
}
if(flag==0)
cout<<'0'<<endl;
else cout<<temp<<endl;
}
return 0;
}
So, first: You can find what exactly your compile error is by clicking on "My submissions" when logged into UVa. This way at least you'll know what the issue is next time.axelblaze wrote:why my code is getting compile error..?![]()
![]()
I pasted the conio.h header file on my system(kubuntu 14.04) to use getche(). is it because of that???
plz help....
Well done! Glad you figured it out!axelblaze wrote:got ac...![]()
![]()