Page 8 of 10
Re: 111 Why WA??
Posted: Wed Dec 31, 2008 4:38 pm
by lnr
Would someone please tell me how to take input for this problem?
How to check end of input for this problem after taking integer n?
Re: 111 Why WA??
Posted: Wed Dec 31, 2008 4:58 pm
by tryit1
lnr wrote:Would someone please tell me how to take input for this problem?
How to check end of input for this problem after taking integer n?
Did you read the complete problem and thread ?
Code: Select all
n= read first integer
for(j=0;j<n;j++) { read the ranking into an array; }
for(i=0;i<n-1;i++) {
for(k=0;k<n;k++) { read the sequence into array }
}
Re: 111 Why WA??
Posted: Wed Dec 31, 2008 7:21 pm
by lnr
tryit1 wrote:lnr wrote:Would someone please tell me how to take input for this problem?
How to check end of input for this problem after taking integer n?
Did you read the complete problem and thread ?
Code: Select all
n= read first integer
for(j=0;j<n;j++) { read the ranking into an array; }
for(i=0;i<n-1;i++) {
for(k=0;k<n;k++) { read the sequence into array }
}
May be you are wrong.
In the problem the input was like this:
10
3 1 2 4 9 5 10 6 8 7
1 2 3 4 5 6 7 8 9 10
4 7 2 3 10 6 9 1 5 8
3 1 2 4 9 5 10 6 8 7
2 10 1 3 8 4 9 5 7 6
Here n=10
And there are five rows.
111 History Grading Runtime error
Posted: Fri Jan 02, 2009 1:49 pm
by lnr
Code removed.
Re: 111 History Grading Runtime error
Posted: Sat Jan 03, 2009 12:11 pm
by newkid
your code doesnt get RTE. The judge just simply replies WA..
Few things:
1. You actually dont need to read the line in string and then process to integers. what if there are tabs/more than one spaces to separate them?
2. i didnt get why you did m = _index-1, for LCS the for loops runs from 1 to arraylength..

(wait i get it now.. your _index starts from 1)
Re: 111 Why WA??
Posted: Fri Jan 30, 2009 12:36 pm
by lnr
Code removed.
Re: 111 Why WA??
Posted: Fri Jan 30, 2009 9:54 pm
by newkid
@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
Re: 111 Why WA??
Posted: Sat Jan 31, 2009 9:28 am
by lnr
newkid wrote:@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
I modified my input taking code.
This time I used "strtok(char *)" function and got accepted.
Many thanks for your reply because your input taking code was better, (no need to cast the string to integer).
Re: 111 Why WA??
Posted: Wed Feb 04, 2009 9:18 pm
by theharshest
I am getting WA for the following code.. Please help..
Re: 111 Why WA??
Posted: Wed Feb 04, 2009 10:43 pm
by newkid
I think the culprit line is
why? cause the problem statement says there might be 'one or more spaces' between two integers. so for input line like "1<10 spaces>2<10 spaces>3" your will resize to (20+3)/2 = 11. thus your str1.size() will return 11 which you have used in mat[str2.size()][str1.size()].
Anyway you already know the size of the vector, right? its 'n'. so use the following instead
Further, you don't need the matrix size to be 1010.. just make it 32 (problem statement says n <= 20)
And
Code: Select all
for(int i=0;i<=str1.size();i++)
mat[0][i]=0;
for(int i=0;i<=str2.size();i++)
mat[i][0]=0;
these lines are redundant as you already set it to zero using memset.
another note..
Code: Select all
else
mat[i][j]=max(mat[i-1][j],mat[i][j-1]);;
try to avoid this kind of bug.. two semicolons. Its not a problem in this code but believe me when this happens its really hard to find and fix.
Re: 111 Why WA??
Posted: Wed Feb 04, 2009 10:49 pm
by theharshest
Thanks newkid..
I got AC

Re: 111 Why WA??
Posted: Sat May 16, 2009 3:55 am
by asqwzxdfercv
lnr wrote:newkid wrote:@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
I modified my input taking code.
This time I used "strtok(char *)" function and got accepted.
Many thanks for your reply because your input taking code was better, (no need to cast the string to integer).
I also got problem in my input
The problem is, if the last sequence ends in space(' '), !cin.eof() is true so an extra line is outputed.
How should I modify my code?
btw, how do ppl get 0.000 runtime for their codes? My fastest program in #10038(ugly number) takes even 0.008s to just cout a line
Code: Select all
manage to solve with stupid method :(
Re: 111 Why WA??
Posted: Sat Jan 22, 2011 11:24 pm
by valkov
Just got AC. So for those of you who are having trouble reading the input and do not care particularly about the speed of it:
Code: Select all
cin >> n;
unsigned t;
for(unsigned i = 0; i < n; i++) {
cin >> t;
a[t] = i;
}
while(true) {
for(unsigned i = 0; i < n; i++) {
if(!(cin >> t)) {
return 0;
}
b[t] = i;
}
cout << call your function in order to solve the problem << endl;
}
where a, b and n are defined as
Code: Select all
unsigned n;
unsigned a[25];
unsigned b[25];
Good luck and have fun!
111 Wrong answer
Posted: Tue Apr 05, 2011 3:02 pm
by Burgi12345
Submition says my answer is wrong. Im sure its not.
I've made a lot of tests and any answer was correct.
Maybe input or output is incorrect?
Code: Select all
public static void main(String[] args) throws IOException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
int numberOfEvents = Integer.parseInt(reader.readLine());
ArrayList<Integer> ratingOfStudents = new ArrayList<Integer>() ;
//get the correct grading
String[] arr = reader.readLine().split(" ");
int[] correctGradingOfEvents = new int[numberOfEvents];
int counter = 0;
for (int i = 0; i < arr.length; i++)
{
if (!arr[i].equals(""))
{
correctGradingOfEvents[counter] = Integer.parseInt(arr[i]);
counter ++;
}
}
//get the ratings of the students
while(reader.ready())
{
arr = reader.readLine().split(" ");
ratingOfStudents.add(findLongestComonSequence(numberOfEvents, arr, correctGradingOfEvents));
}
//output
for (int i = 0; i < ratingOfStudents.size(); i++)
{
System.out.println(ratingOfStudents.get(i));
}
}
Thanks for help
Re: 111 Wrong answer
Posted: Tue Apr 12, 2011 7:55 am
by jfvs
Maybe you are ignoring some special case... thats all that I can tell you, because I can't really analice your code, there are missing parts like the method 'findLongestComonSequence' maybe It is a java method, but Im more of a c++ programmer so...