10338 - Mischievous Children

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

Moderator: Board moderators

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10338 - Mischievous Children

Post by abid_iut » Sun Jan 04, 2009 5:45 pm

getting CE!!
I thought unsigned long long can handle 20!
is it? or any other problem
where should I change
here is the code:

Code: Select all

Removed
pls help :(
Last edited by abid_iut on Sun Jan 04, 2009 6:17 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 10338 - Mischievous Children

Post by helloneo » Sun Jan 04, 2009 5:57 pm

abid_iut wrote:getting CE!!
I thought unsigned long long can handle 20!
is it? or any other problem
where should I change
2432902008176640000 is a representation of 32 bit integer
You should code it like 2432902008176640000LL or 2432902008176640000ULL

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10338 - Mischievous Children

Post by abid_iut » Sun Jan 04, 2009 6:18 pm

I have changed the code accordingly
But now it is WA
pls anyone help
here is the code:

Code: Select all

Removed
Last edited by abid_iut on Mon Jan 05, 2009 6:18 pm, edited 1 time in total.
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

helloneo
Guru
Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Re: 10338 - Mischievous Children

Post by helloneo » Mon Jan 05, 2009 4:41 pm

abid_iut wrote:I have changed the code accordingly
But now it is WA
pls anyone help
here is the code:
I don't fully understand your code.. but, what if k == 0 ??

abid_iut
Learning poster
Posts: 82
Joined: Wed Jul 16, 2008 7:34 am

Re: 10338 - Mischievous Children

Post by abid_iut » Mon Jan 05, 2009 6:20 pm

i have considered k=0;
but still it is WA
here is the code:

Code: Select all

#include<stdio.h>
        #include<string.h>
        #include<math.h>

        char line[100];
        long same[100];
        long long ans,fact;
        int i,j;

        long long factorial[22]={1,2,6,24,120,720,5040,4320,362880,3628800LL,39916800LL,479001600LL,6227020800LL,87178291200LL,1307674368000LL,20922789888000LL,355687428096000LL,6402373705728000LL,121645100408832000LL,2432902008176640000LL};

        int main()
        {
           long n,k,count,t,l,it,div;
           scanf("%ld",&n);
           for(it=1;it<=n;it++){
              gets(line);
              k=0;count=0;
              l=strlen(line);
              for(i=0;i<=l-1;i++){
                 for(j=0;j<=l-1;j++){
                    if(line[i]==line[j] && (line[i]!='*' || line[j]!='*') && line[i]!=' '){
                       count++;
                       if(count>1)line[j]='*';
                    }
                 }
                 if(count>1){same[k]=count;k++;}
                 count=0;
              }
			  if(k>0){
              i=0;
              div=same[0]-1;
              fact=factorial[l-1];
              ans=fact/factorial[div];
              for(i=1;i<k;i++){
               div=same[i]-1;
                 ans=ans/factorial[div];
              }
              printf("Data set %ld: %lld\n",it,ans);
			  }
			  if(k==0){
				  printf("Data set %ld: %lld\n",it,factorial[l-1]);
			  }
           }
           return 0;
        }
pls help :(
i love to wait... wait for better... and better will come...
http://akanoi.webs.com/

User avatar
plamplam
Experienced poster
Posts: 150
Joined: Fri May 06, 2011 11:37 am

Re: 10338 - Mischievous Children

Post by plamplam » Thu Jun 23, 2011 6:34 am

Well well, look what we have here. The problem description is actually wrong, although the problem itself is not. It says that
"The number of arrangements will always be able to fit into an unsigned long int. Note that 12! is the largest factorial that can fit into an unsigned long int." Notice that it should be 20 instead of 12 and that 20! easily fits into an unsigned long long int. :D
Anyway this is indeed a trivial problem, and you should by no means get Wrong Answer. Just use unsigned long long int, but in case somehow you find yourself in a "Wrong Answer" queue, then here are some test cases. Note that the output in my program for a blank line is 1 but Im not sure if this is going to be included in the judge data.

Code: Select all

13
L
LOL
MICROSOFTSUCKS
WHATCANWEDOTOHELP
BAOBABTREE
ACCCACCCCCCCACC
AAAAAAAAAAAC
AAAAAAAAAAAAAAAA
AAAAAACAAAAACAACA
IGOTACYAY
ICANTREALLYHELPU
WHOCARESTHOUGH
ABCDEFGHIJKLMNOPQRST

Code: Select all

Data set 1: 1
Data set 2: 3
Data set 3: 3632428800
Data set 4: 5557616064000
Data set 5: 151200
Data set 6: 455
Data set 7: 12
Data set 8: 1
Data set 9: 680
Data set 10: 90720
Data set 11: 871782912000
Data set 12: 7264857600
Data set 13: 2432902008176640000
If you still get a Wrong Answer then no one can help you. Sorry :wink: :wink:
You tried your best and you failed miserably. The lesson is 'never try'. -Homer Simpson

safait
New poster
Posts: 4
Joined: Sat Jun 08, 2013 10:49 am

why i am getting wrong answer for 10338 no problem

Post by safait » Sat Jun 08, 2013 12:17 pm

here is my code:

Code: Select all

#include<stdio.h>
unsigned long long int binnas(int i)
{
    unsigned long long int n=1;
    for(;i>1;) n*=i--;
    return n;
}

int main()
{
    unsigned long long int n,r;
    int i,j,x,count,in,in1;
    char arr[21];
    in1=1;
    scanf("%d",&in);
    getchar();
    while(in1++<=in){
    for(i=0;arr[i-1]!='\n';i++)
        arr[i]=getchar();
   r=binnas(--i);
   count=1;
   for(j=0;j<i;j++){
        for(x=0;x<i;x++)
            if(arr[j]==arr[x] && x!=j){
                count++;
                arr[x]='Z'+x+j+1;
            }
        if(count>1){
       r/=binnas(count);
       count=1;}
   }
    printf("Data set %d: %llu\n",in1-1,r);
    }
    return 0;
}
for which input ,it get wrong answer.

User avatar
sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Re: why i am getting wrong answer for 10338 no problem

Post by sohel » Sun Jun 09, 2013 4:52 am

http://acm.uva.es/board/viewtopic.php?f=20&t=1353

Search the board first using the search option located at top-right. Don't create a new thread for a problem that already exists. Make your post in an existing thread.

safait
New poster
Posts: 4
Joined: Sat Jun 08, 2013 10:49 am

Re: why i am getting wrong answer for 10338 no problem

Post by safait » Mon Jun 10, 2013 1:34 pm

sohel wrote:http://acm.uva.es/board/viewtopic.php?f=20&t=1353

Search the board first using the search option located at top-right. Don't create a new thread for a problem that already exists. Make your post in an existing thread.
i am not getting perfect answer .
if u see my code carefully then u find my code not able to calculate 20!.
i am want that what is the way to calculate 20!

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: why i am getting wrong answer for 10338 no problem

Post by brianfry713 » Tue Jun 11, 2013 12:49 am

Your code is producing a RE on the sample input. 20! will fit in long long. Also see:
http://www.algorithmist.com/index.php/BigNum
Check input and AC output for thousands of problems on uDebug!

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: 10338 - Mischievous Children

Post by uDebug » Tue Apr 08, 2014 9:10 am

plamplam,
Thanks for the great test cases.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

User avatar
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: why i am getting wrong answer for 10338 no problem

Post by uDebug » Tue Apr 08, 2014 9:12 am

Replying to follow the thread.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.

Post Reply

Return to “Volume 103 (10300-10399)”