Page 12 of 12

Re: 10324 - Zeros and Ones

Posted: Thu May 22, 2014 6:54 am
by Faithkeeper_Rangwan
I got TLE with this one

Code: Select all

[color=#40FF80]AC'd[/color]
does it is because the algorithm is too slow or the improper input handling (and the program stuck in the loop)?

Re: 10324 - Zeros and Ones

Posted: Thu May 22, 2014 8:20 am
by uDebug
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)?
It might be because of all the "cin"s you have. Try replacing them with "scanf"s instead.

Re: 10324 - Zeros and Ones WHy WA

Posted: Tue Jul 01, 2014 9:36 am
by Blief.S
Getting WA...... Every i/o is correct.... Why WA plz help......

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;
}




I think i got WA for "new line" fact. plz help me to overcome.....i have tried many ways..........

Re: 10324 - Zeros and Ones

Posted: Tue Jul 01, 2014 12:04 pm
by uDebug
Blief.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..........
Change Line #9 to

Code: Select all

while(scanf("%s",str)!=EOF){
It's what you probably mean to do.

Also, you have both a variable and an array called "flag". Get rid of the variable since you're not using it. Incidentally, you're not using the variable named "siz", also.

Finally, it's probably a good idea to give some leeway on the array sizes. I know the problem states that the string of characters will 1,000,000 but you might want to make it 1,000,010 - just to be completely safe, you know.

Re: 10324 - Zeros and Ones

Posted: Tue Jul 08, 2014 1:18 am
by brianfry713
Maybe there are more than 1000 queries.

Re: 10324 - Zeros and Ones

Posted: Sun Aug 03, 2014 8:21 pm
by rafid059
I'm getting WA. I took the string as character by character and checked if there is any "change" in the string. I saved the index of the "change" and later compared with the pair values of i and j. All the sample i/o are correct but i'm getting WA.

One more thing. Will there be any i or j which will be greater than the length of the main string? Thanks in advance :)

Code: Select all

Got Accepted!  :D

Re: 10324 - Zeros and Ones

Posted: Tue Aug 05, 2014 12:28 am
by brianfry713
Instead of:
i = fmin(i, j);
j = fmax(i, j);
Try:
if(i > j)
swap(i, j);

Re: 10324 - Zeros and Ones

Posted: Tue Aug 05, 2014 1:44 am
by rafid059
brianfry713 wrote:Instead of:
i = fmin(i, j);
j = fmax(i, j);
Try:
if(i > j)
swap(i, j);
Thanks again, Guru! :D i'm new to c++. Can you please explain the difference between the two codes?

Re: 10324 - Zeros and Ones

Posted: Tue Aug 05, 2014 8:56 pm
by brianfry713
For one thing I would use min and max instead of fmin and fmax when working with ints.

if i <= j then this code would have no effect:
i = min(i, j);
j = max(i, j);

However if i > j then:
i = min(i, j);
//now i = j
j = max(i, j);
//Instead of j getting i's previous value which is overwritten by j, now both i and j equal j's previous value.

Re: 10324 - Zeros and Ones

Posted: Fri Jan 02, 2015 7:55 pm
by gautamzero
why WA???
:(
this is my code:

Code: Select all

erased

Re: 10324 - Zeros and Ones

Posted: Sat Jan 03, 2015 9:58 am
by lighted
Check input in uDebug. http://www.udebug.com/UVa/10324

Re: 10324 - Zeros and Ones

Posted: Sat Jan 03, 2015 5:49 pm
by gautamzero
i have tested the I/O s given in the random inputs at udebug...
but still WA :(

Re: 10324 - Zeros and Ones

Posted: Wed Jan 07, 2015 4:09 am
by brianfry713
change line 21 to:
a = b;

Re: 10324 - Zeros and Ones

Posted: Wed Jan 07, 2015 1:15 pm
by gautamzero
thnx..again :D
i'm just making silly mistake again&again... :oops:

Re: 10324 - Zeros and Ones

Posted: Thu Dec 17, 2015 10:59 am
by mano129
I am getting wrong answer.pls help

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;

 }