#include <iostream>
using namespace std;
int main()
{
int t,i,k,l;
int z[100000];
cin>>t;
for (i=0;i<=t-1;i++)
{cin>>z[i];
}
int temp;
for (l=0;l<=t-2;l++)
{ for (k=0;k<=t-2;k++)
if (z[k+1]<z[k])
{temp=z[k];
z[k]=z[k+1];
z[k+1]= temp;
}
else
continue;
}
for (l=0;l<=t-1;l++)
{cout<<z[l]<<endl;
}
}
why is this code giving runtime error
Unable to Submit Solution due to non-availability of Language
@admin Not able to submit Any solution on Codechef Ide In Any Language
when trying to Submit Solution On CodeChef,CodeChef is asking for Select Language and When trying to Select Programming Language, Not Able to choose Language because programing language drop down list is not showing any programing language option on drop down list...
@admin remove this bug, my submission work stopped in middle, can't do anything other than wait
string.h defined but showing compilation error then strrev is called.
string.h defined but showing compilation error then strrev is called.
in this simple program, it shows compilation error.but why?
#include<stdio.h>
#include<string.h>
int main(void) {
char a[10]="hello";
strrev(a);
printf("%s",a);
return 0;
}
MARBLEGF help!
The problem can be solved using brute force and BIT as well.
I tried to solve it using segment tree with point updates, but getting WA.
Can anyone help or maybe give a test case where it fails?
Here's my code (CODE)
Here's the Problem Link
Thanks!
Wrong Rank in Snackdown 2017 Certificate
I got rank of Snackdown Pre-Elimination Round A on my certificate of codechef snackdown 2017.
Whereas I got better rank in Snackdown Pre-Elimination Round B.
So, why did I get rank of pre-elimination round A, not of pre-elimination round B on my certificate, as both rounds are of same level?
LOCJUN17:HHMGN, NZEC Can someone tell why? Code below
/ package codechef; // don't place package name! /
import java.util.; import java.lang.; import java.io.*;
/ Name of the class has to be "Main" only if the class is public. / class Codechef { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner s = new Scanner(System.in); int T = s.nextInt(); while(T-->0) { int N = s.nextInt(); long S = s.nextInt(); int A[]= new int[N]; for(int i=0;i<N;i++) { A[i] = s.nextInt(); } Arrays.sort(A); long sum = 0; int i=0; for(i=0;i<N;i++) { if(sum+(N-i)*A[i]==S) { System.out.println(A[i]); break; }
else
sum+=A[i];
}
if(i==N)
System.out.println(-1);
}
}
}
CHEFSUBA help!
Hello. I am new to codechef, and I am not able to solve the question CHEFSUBA. I followed the editorial, learned about segment trees, and implemented the solution. I am getting wrong answer. Can anyone please tell me where I went wrong? I have commented the code so it is easier to understand.
upload EDITORIALS !!
@admin pls upload the editorials of JUNE LONG challenge as well as COOK-OFF !!
How to find NZEC error ??
Hi! please tell me what is NZEC error, how to find it inside the code and how to prevent it ? How do codechef encounter NZEC errors, do they use any software ??
Does LoC challenge affect user's rating on codechef?
Plz tell me whether Loc June challenge will help me improve my rating and rank on codechef or will it not affect at all?
Remove this feature Admin !!
@admin , Its been 17 hours since I asked a question here in Codechef and all I could get was 27 views THANKS TO YOUR NEW FEATURE OF SHOWING ONLY POPULAR QUESTIONS ..!!! This is absolute nonsense. Due to this feature, the verve with which the doubts were clarified before has reduced. Some questions are going unanswered. If this is the case how will we learn?? Your feature is similar to this scenario !! - RICH BECOME RICHER , POOR BECOME POORER. only popular questions get views. If that is the case when will our doubts get clarified?? My sincere request to people at codechef - WE LIKE CODECHEF TO BE EDUCATIONAL RATHER THAN COMMERCIAL. DO NOT TRY NEWER THINGS TO MAKE US HAPPY, JUST KEEP POSTING THE EDITORIALS ON TIME, THIS IS MORE THAN ENOUGH. Hope you people understand and I hope i have not angered anyone.
Has anyone here attempted USACO training pages?
Hi all, I just started competitive programming and I have made a little progress in it.. I heard some people talk about USACO training pages on codeforces and therefore I went to check the pages out.. There are in total only 100 questions in the training pages,and I have completed the first chapter,I am currently on chapter 2.. I wanted to ask everyone here if they have completed or made it to the later chapters (i.e. ch.4 or ch.5),are the USACO pages any good?! I have a lot of sources and I want to know how USACO training pages helped you...did you learn a lot of new stuff or nothing new,basically,is it worth the time... Thankyou.
I think this user has two accounts
Three Way Communication
#Shows correct output in termial but shows wrong answer on codechef...
from math import sqrt
t = int(raw_input())
num = []
for i in range(0,t):
r = int(raw_input())
x1,y1 = map(int,raw_input().split())
x2,y2 = map(int,raw_input().split())
x3,y3 = map(int,raw_input().split())
if sqrt((x2-x1)**2 + (y2-x2)**2) <= r and sqrt((x3-x1)**2 + (y3-y1)**2) <= r:
num.append('yes')
elif sqrt((x3-x1)**2 + (y3-y1)**2) <= r and sqrt((x2-x3)**2 + (y2-y3)**2) <= r:
num.append('yes')
elif sqrt((x2-x3)**2 + (y2-y3)**2) <= r and sqrt((x2-x1)**2 + (y2-x2)**2) <= r:
num.append('yes')
else:
num.append('no')
for i in num:
print i
wrong answer on problem count subarrays practice beginner
for _ in range(int(input())): n=int(input()) a=list(map(int,input().split())) c=0 for i in range(len(a)): for j in range(i,len(a)): if j>(i+1): break elif((i<=j) and (a[i]<=a[j])): c+=1 else: continue print(c)
MAXSEGM - Editorial
PROBLEM LINK:
Author:Ramazan Rakhmatullin
Testers:Lewin Gan, Marek Sommer
Editorialist:Pawel Kacprzak
DIFFICULTY:
Easy
PREREQUISITES:
Two pointers
PROBLEM:
You are given 2 arrays $W = [W_1, W_2, \ldots, W_N]$ and $C = [C_1, C_2, \ldots, C_N]$ with $N$ elements each. We say that a range $[L, R]$ is unique if all the elements $C_L, C_{L+1}, \ldots, C_R$ are unique. The goal is to find the maximum possible sum $W_L + W_{L+1} + \ldots + W_R$ for a unique range $[L, R]$.
EXPLANATION:
First of all, notice that in both subtasks, values of $W$ are up to $10^9$, which means that the final sum can exceed $32$-bit integer range, so you should use $64$-bit integers to represent the sums.
Subtask 1
In the first subtask, there are up to $100$ test cases to solve, but we know that the sum of $N$ over all these test cases doesn't exceed $10^4$, so we can apply the following quadratic time approach. For all $L = 1, 2, \ldots, N$, let's iterate over all $R \geq L$ such that a range $[L, R]$ is unique and update the result during this iteration. The key observation here is that if for some $A$, the range $[L, A]$ is not unique, i.e. there exists two indices $L \leq i < j \leq A$, such that $C_i = C_j$, then any range $[L, B]$ for $B > A$ is also not unique. In order to track uniqueness of elements in a range during iterations, we can use a hash-table, or even better, after noticing that values in $C$ are non-negative integers less than $N$, we can use a simple boolean array for this purpose.
The following pseudocode illustrates the above appraoch:
result = 0
for L = 1 to N:
for i = 0 to N-1:
seen[i] = False # initially all are unseen
currentSum = 0
for R = L to N:
if seen[C[R]]:
break
currentSum += W[R]
result = max(result, currentSum)
seen[C[R]] = True
print result
The total time complexity of this method is clearly $O(N^2)$ for a single test case, which is sufficient in this subtask.
Subtask 2
In the second subtask, there are also up to $100$ test cases to solve, but now the sum over $N$ over these test cases doesn't exceed $10^6$. Thus we need a faster approach, ideally a linear one.
The key observation is to notice that values in the array $W$ are non-negative, which means that if a range $[L, R]$ is unique, and we can extend it in any direction, then we can always do that. It follows, that if we have a unique range $[L, R$], we want to extend in both directions as much as it stays unique. This leads to the following approach:
Let's start with $L = 1$. We are going to use a boolean array for tracking already seen elements in the current range - similarly as in the solution for the first subtask. Now, let's find maximum $R$ such that the range $[L, R$] is unique. It means that either $R = N$ or value $C[R+1]$ appears in range $[L, R]$ in array $C$. We do this by simply iterating from $R = L$ until we find this maximum $R$. Now we know that $[L, R]$ is a unique range and we can update the result with its sum, which can be computed while iterating. Now comes the second key observation. If $R = N$ we are done, because there are no remaining elements to the right. Otherwise, in order to extend the current range to the right, we have to find the minimum $i \geq L$, such that $C[i] = C[R+1]$, update $L$ to $i+1$ and start extending the right endpoint of the range from $R$ while it remains unique. We repeat this process until $R$ becomes $N$. The following pseudocode illustrates this approach:
result = 0
currentSum = 0
L = 1
R = 1
for i = 0 to N-1:
seen[i] = False # initially all are unseen
while True:
while R <= N and not seen[C[R]]:
currentSum += W[R]
seen[C[R]] = True
R += 1
result = max(result, currentSum)
if R == N+1:
break
while seen[C[R]]:
seen[C[L]] = False
currentSum -= W[L]
L += 1
print result
The time complexity of this approach is $O(N)$ for a single test case because both $L$ and $R$ can be updated at most $N$ times in the loops and the total complexity is dominated by the loops where these values are updated in every iteration. This method is often called "Two pointers" approach and it's useful in approaching many problems, even very advanced ones.
AUTHOR'S AND TESTER'S SOLUTIONS:
Setter's solution can be found here.
First tester's solution can be found here.
Second tester's solution can be found here.
Editorialist's solution can be found here.
NEW to python NZEC error
import math
t=input()
for i in range(1,t+1):
a=input()
b=input()
n=input()
m=(n+1)/2
z=math.pow(2,m)
a=a*z
z=math.pow(2,n-m)
b=b*z
if a>b:
print(int(a/b))
else:
print(int(b/a))
A variant of subset sum problem
I was trying to solve this problem on some other site, but couldnt find an optimal algo which meets its constraints. Here it goes -
There exists an array A consisting of N numbers. Output the number of subsets of the array A whose sum is greater than or equal to K.
1 <= N <= 40
1 <= A[i], K <= 10^16
Had K been smaller, I could have used a dp approach with complexity O(nk) to count all such subsets. But I wonder how does one solve this problem with such big constraint on K?
Request for Indian Programming Camp 2017 Materials
Dear Organisers,
Kindly provide us with the materials given to the attendants of the programming camp taking place at IIT Gandhinagar. Many of us are unable to go to the camp, but would still like to be able to learn from its lessons. I realize that the materials do get uploaded eventually, but it would be amazing if they can be available during the month of July, even along with the camp. For many students, the academic semester starts at August, and July is the last month of summer holidays. It would be convenient to put time into the topics now.
Thank You
EDIT 1: typo
EDIT 2: Guys please request Codechef to post material, personally on facebook, mail, or any other avenues possible. Do the whole demand -> supply thing.
Need help in GAMCOUNT
1st i sorted the piles according to their V(i) values. Then I tried to solve the problem using dp(i.e. enumerating counts all possible xor values if we take only 1st "i" piles using O(n^3)). Then i thought Matrix exponentiation(some kind of modified) will b helpful, as i saw the Matrix can be created recursively. But failed to get a good algorithm to solve within the time limit.
Also i saw all the solvers of this problem used something called "Fast Walsh-Hadamard transform". I am unable to link my solution with their :(..
Please Help me to move forward. Any other method is also appreciated..