111 - History Grading

All about problems in Volume 1. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 111 Why WA??

Post by lnr » Wed Dec 31, 2008 4:38 pm

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?

User avatar
tryit1
Experienced poster
Posts: 119
Joined: Sun Aug 24, 2008 9:09 pm

Re: 111 Why WA??

Post by tryit1 » Wed Dec 31, 2008 4:58 pm

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

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 111 Why WA??

Post by lnr » Wed Dec 31, 2008 7:21 pm

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.

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

111 History Grading Runtime error

Post by lnr » Fri Jan 02, 2009 1:49 pm

Code removed.
Last edited by lnr on Sun Jan 04, 2009 2:08 pm, edited 1 time in total.

newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 111 History Grading Runtime error

Post by newkid » Sat Jan 03, 2009 12:11 pm

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)
hmm..

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 111 Why WA??

Post by lnr » Fri Jan 30, 2009 12:36 pm

Code removed.
Last edited by lnr on Sat Jan 31, 2009 9:17 am, edited 1 time in total.

newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 111 Why WA??

Post by newkid » Fri Jan 30, 2009 9:54 pm

@lnr..
Have you checked your messages. I sent you a pm earlier this month regarding the problem. check your pms.
hmm..

lnr
Experienced poster
Posts: 142
Joined: Sat Jun 30, 2007 2:52 pm
Location: Dhaka,Bangladesh

Re: 111 Why WA??

Post by lnr » Sat Jan 31, 2009 9:28 am

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).

User avatar
theharshest
New poster
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

Re: 111 Why WA??

Post by theharshest » Wed Feb 04, 2009 9:18 pm

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"

newkid
Learning poster
Posts: 73
Joined: Fri Dec 12, 2008 3:06 am

Re: 111 Why WA??

Post by newkid » Wed Feb 04, 2009 10:43 pm

I think the culprit line is

Code: Select all

str1.resize(tmp.length()/2);
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

Code: Select all

str1.resize(n);
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.
hmm..

User avatar
theharshest
New poster
Posts: 20
Joined: Thu Jan 17, 2008 10:47 pm
Location: India

Re: 111 Why WA??

Post by theharshest » Wed Feb 04, 2009 10:49 pm

Thanks newkid..

I got AC :)
"if u r goin thru hell, keep goin"

asqwzxdfercv
New poster
Posts: 3
Joined: Sat May 16, 2009 3:40 am

Re: 111 Why WA??

Post by asqwzxdfercv » Sat May 16, 2009 3:55 am

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 :(

valkov
New poster
Posts: 20
Joined: Tue Jul 20, 2010 3:11 pm

Re: 111 Why WA??

Post by valkov » Sat Jan 22, 2011 11:24 pm

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!

Burgi12345
New poster
Posts: 1
Joined: Tue Apr 05, 2011 2:51 pm

111 Wrong answer

Post by Burgi12345 » Tue Apr 05, 2011 3:02 pm

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

jfvs
New poster
Posts: 12
Joined: Wed Feb 02, 2011 10:40 am

Re: 111 Wrong answer

Post by jfvs » Tue Apr 12, 2011 7:55 am

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...

Post Reply

Return to “Volume 1 (100-199)”