Code: Select all
[color=#40FF80]AC'd[/color]
Moderator: Board moderators
Code: Select all
[color=#40FF80]AC'd[/color]
It might be because of all the "cin"s you have. Try replacing them with "scanf"s instead.Faithkeeper_Rangwan wrote:I got TLE with this one does it is because the algorithm is too slow or the improper input handling (and the program stuck in the loop)?
Code: Select all
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int n,i,j,cas=0,flag,mini,macs,k,l,siz;
char str[1000001];
char c[100];
while(scanf("%s",&str)!=EOF){
gets(c);
if(c[0]=='\n')
return 0;
scanf("%d",&n);
int flag[1000]={0};
cas++;
l=n;
while(n--){
scanf("%d %d",&i,&j);
if(i>j){
mini=j;
macs=i;
}
else if(i<j){
mini=i;
macs=j;
}
else {
flag[n]=1;
continue;
}
for(k=mini;k<macs;k++){
if(str[k]==str[k+1]) flag[n]=1;
else {
flag[n]=0;
break;
}
}
}
printf("Case %d:\n",cas);
while(l--){
if(flag[l]==1) printf("Yes\n");
else printf("No\n");
}
}
return 0;
}
Change Line #9 toBlief.S wrote:Getting WA...... Every i/o is correct.... Why WA plz help......I think i got WA for "new line" fact. plz help me to overcome.....i have tried many ways..........
Code: Select all
while(scanf("%s",str)!=EOF){
Code: Select all
Got Accepted! :D
Thanks again, Guru!brianfry713 wrote:Instead of:
i = fmin(i, j);
j = fmax(i, j);
Try:
if(i > j)
swap(i, j);
Code: Select all
//10324 Zeros and Ones
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <algorithm>
#include <sstream>
#include <set>
#include <climits>
#include <cstdio>
#include <string>
#include <fstream>
using namespace std;
int main(void){
// //std::ios_base::sync_with_stdio(false);
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
//string str;
char strarray[1000010];
int num;
int i = 0;
while(scanf("%s",strarray) != EOF){
cin >> num;
cout << "Case " << ++i <<":"<<endl;
// char strarray[1000010];
// strcpy(strarray, str.c_str());
int min,max;
int a=0;
char temp = 0;
for (int i=0; i<num; i++){
scanf("%d %d",&min,&max);
//cin >> min >> max;
if(min == max){
cout << "Yes"<<endl;
}
else{
int state=1;
temp = strarray[min];
//If max position value greater than minimum
if(max > min){
for(a=min; a<=max; a++){
if(strarray[a] != temp){
cout << "No" << endl;
state = 0;
break;
}
else if(a==max && state!=0){
cout << "Yes"<<endl;
break;
}
}
}
else{
for(a=max; a<=min; a++){
if(strarray[a] != temp){
cout << "No" << endl;
state = 0;
break;
}
else if(a==max && state!=0){
cout << "Yes"<<endl;
break;
}
}
}
}
}
}
return 0;
}