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🙂.