# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338206 | 2020-12-22T17:31:32 Z | KWang31 | "The Lyuboyn" code (IZhO19_lyuboyn) | Java 11 | 0 ms | 0 KB |
import java.util.*; import java.io.*; public class lynboyn { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } } public static void main(String[] args) { FastReader br=new FastReader(); int N=br.nextInt(); int K=br.nextInt(); int T=br.nextInt(); if((K&1)==0){ System.out.println("-1");return; } int[] cur=new int[1<<(K+1)];//Start with (K,K+1) for (int i = 1; i < 1<<(K+1); i++) { int j=0; while((i&(1<<j))==0){j++;} cur[i]=((1<<(K+1))-1-cur[i-1])^(1<<j); } //System.out.println(Arrays.toString(cur)); for(int B=K+2; B<=N; B++){ int[] nxt=new int[1<<B]; nxt[1]=(1<<(B-1))+(1<<(K-1))-1; for(int j=2; j<=(1<<(B-1)); j++){ nxt[j]=nxt[1]^cur[j-1]; } for(int j=(1<<(B-1))+1; j<(1<<B); j++){ nxt[j]=cur[(1<<B)-j]; } cur=new int[1<<B]; for(int i=0;i<(1<<B); i++) {cur[i]=nxt[i];} } //System.out.println(Arrays.toString(cur)); int st=Integer.parseInt(br.next(),2); if(T==1){ for (int i = 0; i < (1<<N); i++) { System.out.println(Integer.toString((1<<N)+(st^cur[i]),2).substring(1)); } }else{ if(K==1 && N==2){ System.out.println(-1);return; } int sta=0; for (int i = 0; i < (1<<N); i++) { if(cur[i]==(1<<K)-4 || cur[i]==(1<<K)-1){ cur[i]+=cur[(i+2)%(1<<N)]; cur[(i+2)%(1<<N)]=cur[i]-cur[(i+2)%(1<<N)]; cur[i]-=cur[(i+2)%(1<<N)]; sta=(i+3)%(1<<N); break; } } for (int i = 0; i < (1<<N); i++) { System.out.println(Integer.toString((1<<N)+(st^cur[(sta+i)%(1<<N)]^cur[sta]),2).substring(1)); } } } }