111 - History Grading
Moderator: Board moderators
Re: 111 Why WA??
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?
How to check end of input for this problem after taking integer n?
Re: 111 Why WA??
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??
May be you are wrong.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 } }
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
Code removed.
Last edited by lnr on Sun Jan 04, 2009 2:08 pm, edited 1 time in total.
Re: 111 History Grading Runtime error
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)
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..

hmm..
Re: 111 Why WA??
Code removed.
Last edited by lnr on Sat Jan 31, 2009 9:17 am, edited 1 time in total.
Re: 111 Why WA??
@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
hmm..
Re: 111 Why WA??
I modified my input taking code.newkid wrote:@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
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).
-
- New poster
- Posts: 20
- Joined: Thu Jan 17, 2008 10:47 pm
- Location: India
Re: 111 Why WA??
I am getting WA for the following code.. Please help..
Code: Select all
deleted after AC..
Last edited by theharshest on Wed Feb 04, 2009 10:49 pm, edited 1 time in total.
"if u r goin thru hell, keep goin"
Re: 111 Why WA??
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
these lines are redundant as you already set it to zero using memset.
another note..
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.
Code: Select all
str1.resize(tmp.length()/2);
Anyway you already know the size of the vector, right? its 'n'. so use the following instead
Code: Select all
str1.resize(n);
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;
another note..
Code: Select all
else
mat[i][j]=max(mat[i-1][j],mat[i][j-1]);;
hmm..
-
- New poster
- Posts: 20
- Joined: Thu Jan 17, 2008 10:47 pm
- Location: India
-
- New poster
- Posts: 3
- Joined: Sat May 16, 2009 3:40 am
Re: 111 Why WA??
I also got problem in my inputlnr wrote:I modified my input taking code.newkid wrote:@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
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).

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??
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:
where a, b and n are defined as
Good luck and have fun!
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;
}
Code: Select all
unsigned n;
unsigned a[25];
unsigned b[25];
-
- New poster
- Posts: 1
- Joined: Tue Apr 05, 2011 2:51 pm
111 Wrong answer
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?
Thanks for help
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
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...