Your Search Results

155 results found for ""

Codes (144)

  • Binary String on Steroids Codechef Solution in Java| AskTheCode

    Codechef June Cook-Off 2021 Solution | Binary String on Steroids (BNSONSTR) | AskTheCode Problem: A circular binary string is called good if it contains at least one character '1' and there is an integer d such that for each character '1', the distance to the nearest character '1' clockwise is d. You are given a circular binary string S with length N. You may choose some characters in this string and flip them (i.e. change '1' to '0' or vice versa). Convert the given string into a good string by flipping the smallest possible number of characters. Input: The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N. The second line contains a single string S with length N. Output: Print a single line containing one integer ― the minimum number of flips required to transform the initial string into a good string. Sample Input: 2 6 110011 4 0001 Sample Output: 2 0 Code: /* 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 scan = new Scanner(System.in); int test = scan.nextInt(); while(test-- > 0) { int n = scan.nextInt(),ones = 0,d,i,start_1 ; int zeros_one,acc_ones,ones_zeros,curr,ind; String s = scan.next(); for(i =0;i

  • Too Much Xor Codechef Solution in C++| AskTheCode

    Codechef June Cook-Off 2021 Solution | Too Much Xor (TOOXOR) solution in C++ | AskTheCode Problem: Chef calls a sequence of integers A1,A2,…,ANgood if it satisfies the following conditions: In particular, any sequence with length 1 is good and any sequence of length 2 which satisfies the first condition is good. Here, ⊕ denotes the bitwise XOR operation. Chef gives you a sequence A1,A2,…,AN. You may perform the following operation on the sequence any number of times (possibly 0): choose 3 pairwise distinct valid indices a, b and c and change Ac to Aa⊕Ab. Note that this means the operation can only be performed if N≥3. Chef is asking you to make the sequence good using at most 3⋅N operations or report that it is impossible. Note that you do not have to minimise the number of performed operations. Input: The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N. The second line contains N space-separated integers A1,A2,…,AN. Output: For each test case: If it is impossible to change the given sequence into a good sequence using at most 3⋅N operations, print a single line containing the integer −1. Otherwise, first, print a line containing a single integer M (0≤M≤3⋅N) ― the number of operations you want to perform. Then, print M lines describing these operations in the order in which you want to perform them. For each i (1≤i≤M), the i-th of these lines should contain three space-separated integers ai, bi and ci (pairwise distinct; 1≤ai,bi,ci≤N) ― the indices on which the i-th operation is performed. If there are multiple solutions, you may find any one of them. Sample Input: 4 1 69 3 1 2 3 3 1 3 1 2 10 10 Sample Output: 0 -1 4 1 3 2 2 1 3 3 2 1 1 3 2 -1 EXPLANATION: Example case 1: The sequence is already good, so performing 0 operations is a valid solution. Example case 2: The sequence cannot be made good using at most 3⋅N operations. Example case 3: We can make the sequence good by performing the 4 operations shown on the output, in this order. Note that the initial sequence is also good, so performing 0 operations is also a valid solution. Example case 4: The sequence does not satisfy the first condition and since N=2, we cannot perform any operations on it. Code: #include #define mod 1000000007 #define fain(arr) for(ll i=0;i>arr[i]; #define all(x) x.begin(),x.end() #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #define bugv(n1) if(DEBUG)cout<<#n1<<" is "< (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define endl '\n' #define ll long long #define pii pair #define pll pair #define pi acos(-1) #define sz(x) ((ll)x.size()) #define clr(x) memset(x, 0, sizeof(x)) #define init(x, a) memset(x, a, sizeof(x)) #define DEBUG true using namespace std; int main(){ // FILE; SPEED; ll t; cin>>t; // t=1; while(t--) { ll n; cin>>n; ll arr[n]; fain(arr); if(n==1){ cout<<0<> op; for(int i=0;i<3;i++){ int brr[3]; for(int j=0;j<3;j++)brr[j]=arr[j]; ll allxor = arr[0]^arr[1]^arr[2]; brr[i]=allxor^brr[i]; bool poss = true; for(ll pp=1;pp<3;pp++) if((brr[pp]^brr[pp-1])==0) poss=false; if((brr[0]^brr[1]^brr[2])!=brr[1]){ poss=false; } vector xxx = {0,2,1}; for(int pp=0;pp<3;pp++){ if(xxx[pp]==i){ swap(xxx[pp],xxx[2]); break; } } if(poss){ op.push_back(xxx); break; } } if(op.size()>0){ cout<

  • XOR Folding Codechef Solution in Python | AskTheCode

    Codechef June Cook-Off 2021 Solution | XOR Folding (XORFOLD) solution in Python | AskTheCode Problem: You are given a grid with size N×M. Each cell of this grid contains either 0 or 1. We should perform the following operation until the size of the grid becomes 1×1: Suppose the present size of the grid is x×y. Choose one of the x−1 horizontal lines or y−1 vertical lines crossing the grid. Fold the grid along this line. For each pair of cells which overlap after this folding, replace them by a single cell such that the value in this cell is the XOR of the values in the two overlapping cells. Thus, we obtain a new grid. Example: If the initial grid is 000 111 010 1) After folding along 1-st horizontal line, the grid is 111 010 2) After folding along the 2-nd vertical line, the grid is 10 01 3) After folding along the 1-st horizontal line, the grid is 11 4) After folding along the 1-st vertical line, the grid is 0 Determine whether there is a sequence of folds such that in the final 1×1 grid, the only cell contains 1. Input: The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains two space-separated integers N and M. N lines follow. For each valid i, the i-th of these lines contains a single binary string Si with length M describing the i-th row of the grid. Output: Print a single line containing the string "YES" if it is possible to obtain 1 in the final 1×1 grid or "NO" if it is impossible (without quotes). You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical). Sample Input: 2 1 2 01 3 3 000 111 010 Sample Output: YES NO EXPLANATION: Example case 1: There is only 1 possible move, which is to fold along the only vertical line. The resulting grid contains only 1. Example case 2: There is no sequence of moves which would result in a 1×1 grid containing only 1. Code: import sys test = int(sys.stdin.readline().strip()) for i in range(test): n, m = list(map(int, sys.stdin.readline().split())) ans = 0 for i in range(n): a = list(sys.stdin.readline().strip()) len_a = len(a) for i in range(len_a): ans ^= int(a[i]) if ans == 0: print("NO") else: print("YES")

View All

ATC Journa (11)

  • Codechef Long Challenge Solution - AskTheCode

    Codechef June Long Challenge 2021: Question Number 1 to 4 Solution Hey Coders, Have you solved Codechef June Long Challenge 2021 questions number 1 to 4? Were you finding the solution/approach for these questions on AskTheCode? Then, here you are, a parallel and private page of AskTheCode. Due to some reasons, we cannot publish the solution directly on the website. So, giving those here. The solutions are provided in both the Java and C++ languages. We took some time, due to technical reasons, but, here we are publishing the answers🙂. AskTheCode is open to all platforms for those who need help with codes (of any kind/platform). We're always there to provide you the required support. * Click on the relevant question to see its solution. * Note: This page is hidden from Google Search, so utilize the given code as soon as possible. Stay updated for other solutions as well. Until then, Happy Coding🙂.

  • Today's Gift | AskTheCode

    ATC Journal Home Raise A Query Coding Solutions ATC Journal ATC Community About ATC More... Programming Amazing Programs eLearning Coupon Subscribe us Ask Us Are you thinking of learning new skills? Or want to enhance your knowledge? Don’t want to spend unnecessarily on the high-cost courses? Then, you are in the right place. AskTheCode has made your learning very efficient for your budget. Get coupons to grab the fantastic and costlier courses free. Get Udemy free coupons to access great courses and make your learning free. Are you thinking of becoming and exploring the world of developers, whether as an app developer or a web developer? If yes, then Team ATC ( ATC Journal) has brought you some exciting free coupons to make online learning courses for free . Learn these skills at Udemy , an American open eLearning platform for everyone across the globe. Generally, it charges fees to the students, but one can avail of the desired courses free of cost by redeeming the coupons. Get free udemy coupons for some worthy courses. Here are the coupons for the subjects that you can get at no cost, together with their actual price. Java Programming: Complete Beginner to Advanced: Actual price = ₹ 86,40 | Price after applying coupon = ₹ 0 Free Coupon for Java Programming Python for beginners - Learn all the basics of python: Actual price = ₹ 86,40 | Price after applying coupon= ₹ 0 Free Coupon for Python ​ Web Development Masterclass - Complete Certificate Course: Actual price = ₹ 86,40 | Price after applying coupon= ₹ 0 Free Coupon for Web Development Note: These coupons are time-limited, so grab as soon as possible before they expire. Once you grab the course, you can access it for a long time. Stay updated for other free udemy coupons. Until then, Happy Coding.🙂 Free Udemy Coupons to grab great courses at no cost Follow us here for more:

  • AskTheCode | Indian Developer Community

    Log in / Sign up This is indicating to Ask The Code community. Clear doubts about programming questions by getting its solution at AskTheCode. You can get answer to your programming question at AskTheCode quickly. AskTheCode - a community for coders Community for Coders So hey dear upcoming coders. In this digital world, everything is now online. Whatever doubts arrive, the answer is easy to get. But when you ask your programming questions , have you got all your solutions? If your answer is no, then within a few minutes, your answer will be yes. Because here you will get answers to your programming questions free . Here we welcome all the curious coders, who want to be a great coder. Here we will give you answers to your questions related to coding. Whether your question, related to Java, Python, C, C++, or anything else related to coding. After coming here, now no more please answer my coding questions to others. Because you will be able to answer other questions related to coding. The main motive for creating this website, to find new talent and clear their doubts. If you don't know anything about coding or you are a coder. This platform for both. Our main agenda is to clear the doubt of every coder. So, come and join the Indian Developer Community by being connected here at ATC. Now, no more, who will answer my question? Now, it's time to compete with the world and say, yes, I know about coding. Description about AskTheCode platform Benefits of joining the ATC community AskTheCode community members benefits and advantages. AskTheCode is a safe & secure online community for coders to ask your programming questions. Our community members can enjoy many benefits that will contribute a lot to their career as a programmer. Members can get their solutions relatively quicker than normal visitors and enjoy many interesting segments, which will be updated timely. Becoming a member, you can ask us to get answers your programming questions . Also, they have full navigation access to the website. Additionally, a Coding Solutions segment is only accessible by the members, where they can also share their views on any particular question. Here, you'll get every setup and even answer competitive programming that will help you to become an emerging coder. Moreover, there is another member-only area called ATC Community ; here, all our members can create groups and share their questions, solutions, or views over any programming language. Also, they can share helpful posts with their friends very easily. Further, our members can follow their best answer provider to get in direct contact with them, and similarly, they can also be followed by any other member. The most trending member will be chosen for some extra benefits. So please hurry up and join our ATC community and enhance your coding effortlessly. ABOUT ATC Contact US E-mail id Welcome coders! Come and ask your doubts at Ask The Code - an Indian Developer Community. ATC is a programmer community that is available to all. Here you don't need to pay anything. The only thing you need to pay is attention. It's free and for all. So let's be together and develop our India Developer Community as the most influential in coding. Join Team ATC and feel your developer path as hurdle free path. Just ask your programming questions here and get its solution in the quickest time. By being a member of our community, you will not only experience development in your coding skill but will be helping others too, due to which there will be no obstacle in the growth of our Indian Programmers. So come and shake hands with us, join team ATC. You just take a step, and we will help you cross all the obstacles in your coder part. So come forward, ask your doubts, get your answer, and emphasize your journey as a coder. Team ATC will be helping you to become efficient as well as a coder dispelled of any doubts. So come and be a part of our dream to accomplish your desire to be a doubtless coder. Subscribe Alert From Us Subscribe ATC You've been subscribed.

View All