10919 - Prerequisites?

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

Moderator: Board moderators

Post Reply
Cho
A great helper
Posts: 274
Joined: Wed Oct 20, 2004 11:51 pm
Location: Hong Kong

10919 - Prerequisites?

Post by Cho »

I used set<string> to solve this one during the contest, but couldn't get AC. I couldn't find any bug in my code so I submit it to online-judge without any modification. I get AC now with 2 secs running time. So I think I failed in contest because of TLE. Any one know what's the time limit of this problem in the contest?

By the way, in the recent two contests, I find no way to check the result of my submission. I can only know it's AC or not from the all team rank list. If it's not AC, how can I check if it WA, TLE, RTE, ...?
Monsoon
Learning poster
Posts: 66
Joined: Fri Jul 23, 2004 4:42 pm
Location: Poland

Post by Monsoon »

you can see your submit status in "Judge status & Event Page" (second button below "All team ranklist"); i think there was 1 sec time limit
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

What is the output for the following input set...

Input:

Code: Select all

3 2
0123 9876 2222
2 1 8888 2222
3 1 3172 2222 7654 
3 2
0123 9876 2222
2 1 8888 2222
3 2 0123 9876 2222
0
Thanks.
Last edited by Jan on Mon Oct 03, 2005 2:59 pm, edited 1 time in total.
Ami ekhono shopno dekhi...
HomePage
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Got Accpeted. Thanks :D
Ami ekhono shopno dekhi...
HomePage
IRA
Learning poster
Posts: 82
Joined: Sat Jan 07, 2006 6:52 am

Post by IRA »

Who can describe the meaning of the probelm.
I have think this so long but i can't figure it how to do.
Thanks in advanced!
mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun »

To meet the degree requirements, he must take courses from each of several categories.
...
the minimum number of courses from the category that must be taken...
You can look at this too.
smilitude
Experienced poster
Posts: 137
Joined: Fri Jul 01, 2005 12:21 am

Post by smilitude »

you got to input some course name that freddie is going to take.
he got to take some minimum courses out of some catagories.
you got to check whether he is taking minimum numbers of courses from each catagory or not...

monsoon, why did you tried to use string? i used a simple boolean array and got AC in 0.248 seconds! :lol:
fahim
#include <smile.h>
abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10919 - Prerequisites? why RTE

Post by abid_iut »

please help.. I am getting RTE
here is the code

Code: Select all

#include<stdio.h>

int main(){
	long n,m,array[150],n1,m1,ccount,i,k,test[150],itr,it,flag1=0;
	bool flag[150];
	while(1){
		k=0;
		scanf("%ld",&n);
		if(n==0)break;
		scanf("%ld",&m);
		for(i=0;i<n;i++)scanf("%ld",&array[i]);
		for(int tr=0;tr<m;tr++){
			ccount=0;
			scanf("%ld",&n1);
			scanf("%ld",&m1);
			for(itr=0;itr<n1;itr++)scanf("%ld",&test[itr]);
			for(itr=0;itr<n1;itr++){
				for(it=0;it<n;it++){
					if(test[itr]==array[it])ccount++;
				}
				if(ccount>=m1){flag[k]=true;k++;}
			}
			if(ccount<m1){flag[k]=false;k++;}
		}
		for(it=0;it<k;it++){
			if(flag[it]==false){
				printf("no\n");
				flag1=0;
				break;
			}
			else flag1=1;
		}
		if(flag1==1)printf("yes\n");
		for(it=0;it<k;it++)flag[it]=false;
		flag1=0;
	}
	return 0;
}
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/
DD
Experienced poster
Posts: 145
Joined: Thu Aug 14, 2003 8:42 am
Location: Mountain View, California
Contact:

Re: 10919 - Prerequisites? why RTE

Post by DD »

abid_iut wrote:please help.. I am getting RTE
here is the code

Code: Select all

#include<stdio.h>

int main(){
	long n,m,array[150],n1,m1,ccount,i,k,test[150],itr,it,flag1=0;
	bool flag[150];
	while(1){
		k=0;
		scanf("%ld",&n);
		if(n==0)break;
		scanf("%ld",&m);
		for(i=0;i<n;i++)scanf("%ld",&array[i]);
		for(int tr=0;tr<m;tr++){
			ccount=0;
			scanf("%ld",&n1);
			scanf("%ld",&m1);
			for(itr=0;itr<n1;itr++)scanf("%ld",&test[itr]);
			for(itr=0;itr<n1;itr++){
				for(it=0;it<n;it++){
					if(test[itr]==array[it])ccount++;
				}
				if(ccount>=m1){flag[k]=true;k++;}
			}
			if(ccount<m1){flag[k]=false;k++;}
		}
		for(it=0;it<k;it++){
			if(flag[it]==false){
				printf("no\n");
				flag1=0;
				break;
			}
			else flag1=1;
		}
		if(flag1==1)printf("yes\n");
		for(it=0;it<k;it++)flag[it]=false;
		flag1=0;
	}
	return 0;
}
I think there may be some problems on your use of flag[], which may out of boundary. You should re-design it such that its size is equal to the number of categories.
Have you ever...
  • Wanted to work at best companies?
  • Struggled with interview problems that could be solved in 15 minutes?
  • Wished you could study real-world problems?
If so, you need to read Elements of Programming Interviews.
tidusleonart
New poster
Posts: 10
Joined: Fri Nov 21, 2014 9:18 am

Re: 10919 - Prerequisites?

Post by tidusleonart »

Code: Select all

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

typedef vector<int> vi;
bool indexB(vi& a, int f)
{
	int low = 0, high = a.size()-1, mid;
	while(low <= high)
	{
		mid = (low+high)/2;
		if(a[mid] == f)
			return true;
		if(a[mid] > f)
			high = mid-1;
		if(a[mid] < f)
			low = mid+1;
	}
	return false;
}
int main()
{
	freopen("input.txt", "r", stdin);
	vi taken, same;
	int k, m, c, r, num;
	while(scanf("%d", &k), k)
	{
		scanf("%d", &m);
		int ctaken;
		bool flag = true;
		for(int i = 0; i < k; i++)
		{
			scanf("%d", &ctaken);
			taken.push_back(ctaken);
		}
		sort(taken.begin(), taken.end());
		/*for(int i = 0; i < taken.size(); i++)
		{
			printf("%d ", taken[i]);
		}*/
		for(int i = 0; i < m; i++)
		{
			scanf("%d %d", &c, &r);
			//printf("%d %d\n", c, r);
			int check = 0;
			for(int j = 0; j < c; j++)
			{
				scanf("%d", &num);
				if(indexB(taken, num)){
					check++;}
			}
			if(check < r){
				flag = false;}
		}
		//cout << indexB(taken, 2222) << endl;
		printf((flag) ? "yes\n": "no\n");
	}
	return 0;
}
I keep getting WA. even though checked many test cases with input. I wonder what test cases that i did wrong. Please help. I'm bit frustrating. Thanks
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 10919 - Prerequisites?

Post by brianfry713 »

Don't read from a file.
Check input and AC output for thousands of problems on uDebug!
Post Reply

Return to “Volume 109 (10900-10999)”