You are not logged in. Please login at www.codechef.com to post your questions!

×

# Problem with ICPC16B Beautiful Arrays

 0 1 The problem goes as follows : "An array a is called beautiful if for every pair of numbers ai, aj, (i ≠ j), there exists an ak such that ak = ai * aj. Note that k can be equal to i or j too." So for n==1, there do not exist any pairs and hence the array is not supposed to be "Beautiful". But the way test cases turned out, the array was supposed to be "Not Beautiful" Kindly check into it the same. asked 22 Oct '16, 22:17 87●2●6 accept rate: 0% man, you gave me a shock for a minute. "But the way test cases turned out, the array was supposed to be "Not Beautiful" Kindly check into it the same." It is wrong. Test cases doesn't say that n = 1 is not beautiful. n = 1 is beautiful by definition. (22 Oct '16, 22:21) An array a is called beautiful if for every pair of numbers ai, aj, (i ≠ j). There does not exist any pair in the first place, and for a n==1, we cannot have i!=j. So wouldn't the default answer for n==1 be "Not Beautiful". Didn't mean to shock you but kindly look into this. (22 Oct '16, 22:25) 4 An application of some definition should work in this way, take the definition, apply on your object (in this case array), if it violates the conditions, then the array is bad, otherwise it is good. Now, our example for n = 1, there are no two i, j such that i != j, so the array is good implicitly. This type of statements are called vacuously true. (22 Oct '16, 22:30) Okay, thank you. Perfectly fine :) (22 Oct '16, 23:14)

 7 The problem clearly says that "for every pair of numbers...". For n = 1, no pair exists, hence there is no need to check for the second condition. Hence the answer is "yes" answered 23 Oct '16, 07:52 41 accept rate: 0%
 5 I just cannot believe this. I made -5 submissions in this questions having total faith that for n=1 the answer must be no. I guess the basic definition is being rejected "i!=j" (1st index!=1st index) answered 23 Oct '16, 11:10 766●5 accept rate: 28% You can refer to my answer above (23 Oct '16, 11:12) Yeah!Thanks. (23 Oct '16, 18:07)
 5 As mentioned above, it's a vacuous truth statement.It uses the fact that whenever an implication p=>q is given, and if p itself is false, it doesn't matter whether q is true or not and the statement is considered true. In our case, p = "if there exists a pair", which is false for n=1, making the assertion true by default. You can also use the equivalent relation ~p+q for p=>q, meaning either of ~p or q being true for the statement to be true; This statement, when viewed in it's equivalent terms, would be read as: "If there doesn't exist any pair (i,j) OR there exists an ak..." Since the first condition holds for n=1, the statement is implicitly true. P.S I didn't know about vacuous truth statements either and I submitted the answer with a "no" as well. Learnt something new, and I hope you did too now. :) answered 23 Oct '16, 15:32 105●1●6 accept rate: 25%
 4 The question clearly states that "if there exists pairs and those are not beautiful then output no"..But for n=1,there are no pairs to violate the above condition... Hence the answer will be "Yes".. :) answered 23 Oct '16, 10:55 619●6 accept rate: 12%
 2 Why was time not extended????I submitted at 14 minutes left and got result when 20 seconds were left and That too a compilation error.... Should not they have extended the time by 15 minutes??????They often do it in cook off !! I missed a chance to go to Amritapuri... answered 23 Oct '16, 11:29 11 accept rate: 0%
 0 wow.... Great.... the intricacies of knowledge.. !! "Vacuously" ... shaandaar answered 22 Oct '16, 22:37 2★chari407 448●2●7 accept rate: 0%
 0 answer for n=1 should be "no" because it is clearly stated in question that for pair (i,j) i!=j answered 23 Oct '16, 01:02 1 accept rate: 0%
 0 yes . the answer should be "no" for n=1 , because we cannot have a pair (i,j) such that i!=j. Kindly look into this please. answered 23 Oct '16, 07:11 61●1 accept rate: 50%
 0 The answer for n=1, should be "no".. Vacuous True cases are when we don't have any condition that rejects the case, but here it is clearly stated that i! =j, so it is a "no" here.. Please look into this.. answered 23 Oct '16, 10:27 3★ksut28 31●3 accept rate: 0%
 0 can anyone tell the way to solve this problem.. answered 23 Oct '16, 11:17 1 accept rate: 0% 1 https://www.codechef.com/viewsolution/13226331 the code is readable and logic is surely easy to understand. (09 Apr '17, 13:26)
 0 Please review my code i am new in coding.I am getting time limit exceeded error https://www.codechef.com/viewsolution/13239918 answered 09 Apr '17, 00:32 1 accept rate: 0%
 0 Can SomeOne plz tell me that what is the problem with my solution. https://www.codechef.com/viewsolution/13382532 answered 24 Apr '17, 10:06 1 accept rate: 0%
 0 @akhii1998 The reason you got WA is because you are storing the product of a[i] & a[j] in the integer variable whereas integer limit is 2 * 10^9 and product can go about 10^18. However, that is not you should be worried about. Since you are beginner I think you are not yet aware of the term Time Complexity .( check this links or search on web to know about Time Complexity: https://www.quora.com/What-are-some-easy-ways-to-understand-and-calculate-the-time-complexity-of-algorithms https://www.quora.com/I-am-getting-%E2%80%9CTime-Limit-Exceeded%E2%80%9D-response-for-several-problems-on-Codechef-How-should-I-optimize-my-code/answer/Vaibhav-Tulsyan ) You are running two loops to choose a[i] and a[j] and size of the array can be upto 10^5 . Then 2 select every 2 combination you are using 10^5 Choose 2 iteration which is in the order of 10^10. And again you are linear searching , suppose the product is not present in array, then you have to again traverse 10^5 elements. So your complexity can go up-to 10^15 iterations which can take years to execute because normally PC executes 10^8 to 10^9 iterations per second of C/C++ code. Hence, to reduce the time complexity you need to think about other logic, better logic than needs few number of iterations. So try your best to come up with better approach by making some observations(Use pen and notebook :P). And, if stuck can have a look at working solution here : https://www.codechef.com/viewsolution/ . Cheers , happy coding and learning . answered 24 Apr '17, 10:52 1.2k●10 accept rate: 15%

anbody can help me why my code is wrong?

# include<stdio.h>

int main() { int a,b,c,d,k,h=0,y,i=1,j; scanf("%d\n",&a); start:scanf("%d\n",&b); d=b-1; y=b; while(b!=0) {

scanf("%d",&c);
j[i]=c;

i++;
b--;
}
for(i=1;d>=1;d--,i++)
{
k=j[i];
k=k*j[i+1];
}
for(i=1;i<=y;i++)
{

if(k==j[i])
{
h++;

}
}
if(h!=0)
{
printf("yes\n");
a--;
}
else if(h>0)
{
printf("no\n");
a--;
}
if(a!=0)
{
goto start;
}
return 0;


}

answered 28 Apr '17, 01:31 1
accept rate: 0%

 0 I have a problem with this task ! I have another solution more complicated i have tested for several examples and it works , but every time i submitt , it gives "wrong answer" , i don't know why ?!! package beginner; import java.io.; import java.util.; import java.lang.*; public class BeautifulArraysICPC16B { // static int max ; // static int min; // static int occMax ; // static int occMin ; static class InputReader { public BufferedReader buff; public StringTokenizer token; public InputReader(InputStream stream) { buff = new BufferedReader(new InputStreamReader(stream), 32768); token = null; } public String next() { while (token == null || !token.hasMoreTokens()) { try { token = new StringTokenizer(buff.readLine()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return token.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } public static int max(int[] tab){ int max = tab; for(int i=0 ; i< tab.length ;i++){ if(tab[i] > max) {max = tab[i] ;} } return max; } public static int min(int[] tab){ int min = tab; for(int i=0 ; i< tab.length ;i++){ if(tab[i] < min) {min = tab[i] ;} } return min; } public static int firstocc(int[] tab , int a){ int j = -1 ; do{ j++; }while(tab[j]!=a && j 1){ int l = 0 ; while(l < tab.length && t){ if(l!=occMax){t=(tab[l]==1 || tab[l]==0);} if(!t){out.println("no");break;} l++; } if (l==tab.length) out.println("yes"); }else if(min<-1){ int l = 0 ; while(l < tab.length && t){ if(l!=occMin){t=(tab[l]==1 || tab[l]==0);} if(!t){out.println("no");break;} l++; } if (l==tab.length) out.println("yes"); }else if(min==-1 && max==-1){ out.println("no"); }else{ out.println("yes"); } } out.close(); }  } answered 05 May '17, 20:27 1 accept rate: 0%
 0 well i have a doubt in this problem,shouldn't the array for example {1,-1,2} be not beautiful as -1*2 = -2 as there is no such element therefore {1,-1,2} should not be beautiful but in few of the successful submissions this array comes out to be a beautiful array and i submitted both mine(which shows the above example to be not beautiful) and the other codechef seemed to accept the other one.I think there is a problem in the solution from there end MAYBE.So pls somebody help and pls tell where i am going wrong? answered 10 May '17, 13:06 1 accept rate: 0%

# include <iostream>

using namespace std;

int main() { int k; cin>>k; for(int j=1;j<=k;j++) { int n; cin>>n; int a[n],sum=1,i,count=0;

for(i=0;i<n;i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
sum*=a[i];
}
for(i=0;i<n;i++){
if(sum==a[i])
{
count++;
}
}
if(count>=1)
{
cout<<"yes"<<endl;
}
else
{
cout<<"no";

}
}
return 0;


} pls...Anyone look at this code...pls tell me what is wrong with this.. I an getting the correct answer in all other compilers.But code chef states it as wrong answer.. PLS HELP ANYONE..PLS..PLS..PLS..

answered 21 May '17, 18:13 0★sreeshu
01
accept rate: 0%

 0 import java.util.*; import java.lang.*; import java.io.*; class BeautifulArray { public static void main(String args[])throws java.lang.Exception{ Scanner in=new Scanner(System.in); int testc=in.nextInt(); for(int c=0;c a[j]){ temp = a[j-1]; a[j-1] = a[j]; a[j] = temp; } } } fflag=0; for(i=1;i=2 elements with abs(arr[i])>1` These 3 will give you a direction to think. (26 Jul '17, 00:27)
 toggle preview community wiki:
Preview

### Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×1,427
×1,112

question asked: 22 Oct '16, 22:17

question was seen: 7,839 times

last updated: 26 Jul '17, 00:28