10324 - Zeros and Ones
Moderator: Board moderators
Change
to
and make these global variables.
Then change
To
Which is now a little more robust. And also, add #include <string.h>.
Code: Select all
char str1[1000001];
int str2[1000001];
Code: Select all
char str1[1000001];
char str2[1000001];
Then change
Code: Select all
while(gets(str1)!=NULL)
Code: Select all
while(scanf("%s",str1)==1)
your alg has a little flaw, try this: (char would overflow)
The correct answer for that input is Yes.
Code: Select all
0101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
1
500 501
-
- Experienced poster
- Posts: 162
- Joined: Thu Jul 13, 2006 7:07 am
- Location: Campus Area. Dhaka.Bangladesh
- Contact:
why dont you give me simple I/O which can help me to seek out my problem. please check my code. find if there any locical error.
my Turbo c++ compiler is so poor to find critical error.
newton................................ simply the best
my Turbo c++ compiler is so poor to find critical error.
Code: Select all
please help or i will die
newton................................ simply the best
Bug here.
And I think the str2 should be int.
----
calm down.
Code: Select all
printf("Case: %d\n",++Case);
----
calm down.
-
- New poster
- Posts: 4
- Joined: Mon Apr 23, 2007 6:05 am
I have found why I got TLE.
Because the last char. of input file could be space, it won't get EOF
This cause limitless loop
Use while(getline(cin, line)) instead of while(!cin.eof()) and I got Accepted.
Code: Select all
........blahblahblah
while(!cin.eof())
{
getline(cin, line);
........................blahblahblah
This cause limitless loop
Use while(getline(cin, line)) instead of while(!cin.eof()) and I got Accepted.
tle...............help plzzzzzzzzz
for god"s sake can anyone tell y the hell i am getting out of time.......
plzzzzzzzzz help
[/b]
plzzzzzzzzz help
Code: Select all
#include<iostream>
#include<vector>
#include<string>
using namespace std;
int main()
{
int count=0;
string s;
while(cin>>s)
{
if(s[0]=='\n')
return 0;
if(s[0]==' ')
return 0;
count++;
printf("Case %i:\n",count);
int a,b,c;
cin>>a;
for(int i=1;i<=a;++i)
{
cin>>b>>c;
if(b>c)
{
char temp=s[b];
b=c;
c=temp;
}
char a1=s[b];
while(b<=c)
{
if(a1!=s[b])
{
cout<<"No\n";
b=-101;
break;
}
++b;
}
if(b!=-101)
cout<<"Yes\n";
}
}
}
Your algorithm is not ok for this problem. For each query you dont have to run any loop. Just initially check the whole pattern and use some technique. Then you can solve each query in just O(1).
Hope it helps.
Hope it helps.
Ami ekhono shopno dekhi...
HomePage
HomePage
wa now
yes i totally underestimated this problrm.now this time i am sure my algo is right(hope so)
plzzzzzzzz jan telll me y i m getting WA...........
which cases i am missing...................
[/code]
plzzzzzzzz jan telll me y i m getting WA...........
which cases i am missing...................
Code: Select all
/*code removed*/
Last edited by SARKAR on Sun Jun 10, 2007 12:45 pm, edited 1 time in total.
I think your code is correct as well as your algorithm. So, try submitting it again. And don't forget to remove your code.
Ami ekhono shopno dekhi...
HomePage
HomePage