exec_outcome
stringclasses
1 value
code_uid
stringlengths
32
32
file_name
stringclasses
111 values
prob_desc_created_at
stringlengths
10
10
prob_desc_description
stringlengths
63
3.8k
prob_desc_memory_limit
stringclasses
18 values
source_code
stringlengths
117
65.5k
lang_cluster
stringclasses
1 value
prob_desc_sample_inputs
stringlengths
2
802
prob_desc_time_limit
stringclasses
27 values
prob_desc_sample_outputs
stringlengths
2
796
prob_desc_notes
stringlengths
4
3k
lang
stringclasses
5 values
prob_desc_input_from
stringclasses
3 values
tags
listlengths
0
11
src_uid
stringlengths
32
32
prob_desc_input_spec
stringlengths
28
2.37k
difficulty
int64
-1
3.5k
prob_desc_output_spec
stringlengths
17
1.47k
prob_desc_output_to
stringclasses
3 values
hidden_unit_tests
stringclasses
1 value
PASSED
eebec33ce3ad41ec8207cecd87981f2b
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; import java.util.stream.*; public class App { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws Exception { if (System.getProperty("ONLINE_JUDGE") == null) { File inputFile = new File("/Users/vipinjain/self/cp/input.txt"); File outputFile = new File("/Users/vipinjain/self/cp/output.txt"); br = new BufferedReader(new FileReader(inputFile)); bw = new BufferedWriter(new FileWriter(outputFile)); } int tests; tests = Integer.parseInt(br.readLine()); //tests = 1; while (tests-- > 0) { solve(); } bw.flush(); bw.close(); br.close(); } static void solve() throws Exception { // String[] tmp = br.readLine().split(" "); // long n = Long.parseLong(tmp[0]); // long k = Long.parseLong(tmp[1]); // int b = Integer.parseInt(tmp[2]); // int c = Integer.parseInt(tmp[3]); // int d = Integer.parseInt(tmp[4]); int n = Integer.parseInt(br.readLine()); for (int i = 1; i <= n; ++i) { bw.write(i + " "); for (int j = n; j > 0; --j) { if (j != i) { bw.write(j + " "); } } bw.write("\n"); } } static String queueOutput(Queue<Integer> queue) { StringBuilder sb = new StringBuilder(); for (Integer num : queue) { sb.append(num + " "); } return sb.toString().trim(); } static int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } static long minDivisor(long n) { for (long i = 2; i * i <= n; ++i) { if (n % i == 0) { return i; } } return n; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
3d2a8dab2ed7fb49c1d7f5adf3440b04
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; import java.util.stream.*; public class App { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public static void main(String[] args) throws Exception { if (System.getProperty("ONLINE_JUDGE") == null) { File inputFile = new File("/Users/vipinjain/self/cp/input.txt"); File outputFile = new File("/Users/vipinjain/self/cp/output.txt"); br = new BufferedReader(new FileReader(inputFile)); bw = new BufferedWriter(new FileWriter(outputFile)); } int tests; tests = Integer.parseInt(br.readLine()); //tests = 1; while (tests-- > 0) { solve(); } bw.flush(); bw.close(); br.close(); } static void solve() throws Exception { // String[] tmp = br.readLine().split(" "); // long n = Long.parseLong(tmp[0]); // long k = Long.parseLong(tmp[1]); // int b = Integer.parseInt(tmp[2]); // int c = Integer.parseInt(tmp[3]); // int d = Integer.parseInt(tmp[4]); int n = Integer.parseInt(br.readLine()); if (n == 3) { bw.write("3 2 1\n1 3 2\n3 1 2\n"); return; } Queue<Integer> queue = new LinkedList<>(); for (int i = n; i > 0; --i) { queue.add(i); } for (int i = 0; i < n; ++i) { bw.write(queueOutput(queue)); queue.add(queue.poll()); bw.write("\n"); } } static String queueOutput(Queue<Integer> queue) { StringBuilder sb = new StringBuilder(); for (Integer num : queue) { sb.append(num + " "); } return sb.toString().trim(); } static int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } static boolean isPrime(long n) { for (long i = 2; i * i <= n; i++) { if (n % i == 0) { return false; } } return true; } static long minDivisor(long n) { for (long i = 2; i * i <= n; ++i) { if (n % i == 0) { return i; } } return n; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
b7871f1cf5aed5977b1d0a12520c5a6c
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
/* I am dead inside Do you like NCT, sKz, BTS? 5 4 3 2 1 Moonwalk Imma knock it down like domino Is this what you want? Is this what you want? Let's ttalkbocky about that :() */ import static java.lang.Math.*; import java.util.*; import java.io.*; public class x1644B { public static void main(String omkar[]) throws Exception { BufferedReader infile = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(infile.readLine()); int T = Integer.parseInt(st.nextToken()); StringBuilder sb = new StringBuilder(); while(T-->0) { st = new StringTokenizer(infile.readLine()); int N = Integer.parseInt(st.nextToken()); if(N == 4) { sb.append("4 1 3 2\n"); sb.append("1 2 4 3\n"); sb.append("3 4 1 2\n"); sb.append("2 4 1 3\n"); continue; } if(N == 3) { sb.append("3 2 1\n"); sb.append("1 3 2\n"); sb.append("3 1 2\n"); continue; } ArrayList<Integer> odd = new ArrayList<Integer>(); ArrayList<Integer> even = new ArrayList<Integer>(); for(int i=1; i <= N; i+=2) odd.add(i); for(int i=2; i <= N; i+=2) even.add(i); HashSet<String> set = new HashSet<String>(); while(set.size() < N) { StringBuilder lol = new StringBuilder(); boolean works = true; for(int i=2; i < even.size(); i++) if(even.get(i-2)+even.get(i-1) == (int)even.get(i)) { works = false; break; } if(works && odd.get(odd.size()-1)+odd.get(odd.size()-2) != even.get(0)) { for(int x: odd) lol.append(x+" "); for(int x: even) lol.append(x+" "); set.add(lol.toString()); } odd = shuffle(odd); even = shuffle(even); } for(String s: set) sb.append(s).append("\n"); } System.out.print(sb); } public static ArrayList<Integer> shuffle(ArrayList<Integer> ls) { int[] order = new int[ls.size()]; for(int i=0; i < ls.size(); i++) order[i] = i; int turns = 30; while(turns-->0) { int a = (int)(Math.random()*ls.size()); int b = (int)(Math.random()*ls.size()); int temp = order[a]; order[a] = order[b]; order[b] = temp; } int[] arr = new int[ls.size()]; for(int i=0; i < arr.length; i++) arr[i] = ls.get(order[i]); ArrayList<Integer> next = new ArrayList<Integer>(); for(int x: arr) next.add(x); return next; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
68a06722d13cf0127dd0cdb5c82d14b7
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; import java.util.Arrays; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); for(int i = 0; i < T; i++) { int N = scan.nextInt(); for(int j = 1; j <= N; j++) { System.out.print(j); for(int k = N; k>0; k--) { if(j != k) { System.out.print(" " + k); } } System.out.println(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
1f9841df0a654008d6477614e5b0249f
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
/* 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. */ public class Codechef { public static void main (String[] args) throws java.lang.Exception { try { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-- > 0) { int n=sc.nextInt(); int arr[]=new int[n]; for(int i=1; i<=n; i++) { System.out.print(i + " "); for(int j=n; j>0; j--) { if(j != i) System.out.print(j+" "); } System.out.println(); } } } catch(Exception e) { } // your code goes here } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
7e0cb41e188a3a3ce71cf0d6d68440bf
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Submit { public static void main(String[] args) throws IOException { try (BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out)); InputReader reader = new InputReader()) { int t = reader.nextInt(); int n, p[]; while (t-- > 0) { n = reader.nextInt(); p = new int[n]; for (int i = 1; i <= n; i++) { writer.append(i + " "); for (int j = n; j > 0; j--) { if (i == j) { continue; } writer.append(j + " "); } writer.append(System.lineSeparator()); writer.flush(); } } } } } class InputReader implements AutoCloseable { private BufferedReader bufferedReader; private StringTokenizer tokenizer; public InputReader() { bufferedReader = new BufferedReader(new InputStreamReader(System.in)); } public String next() { while (tokenizer == null || !tokenizer.hasMoreElements()) { try { tokenizer = new StringTokenizer(bufferedReader.readLine()); } catch (IOException ex) { ex.printStackTrace(); } } return tokenizer.nextToken(); } public char nextChar() { char character = ' '; try { character = (char) bufferedReader.read(); } catch (IOException e) { e.printStackTrace(); } return character; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public String nextLine() { String line = ""; try { line = bufferedReader.readLine(); } catch (IOException ex) { ex.printStackTrace(); } return line; } @Override public void close() { try { this.bufferedReader.close(); } catch (IOException ex) { ex.printStackTrace(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
33e63988a78a0ee8c9aae045052ff2ca
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; import static java.lang.System.currentTimeMillis; /* * @author: Hivilsm * @createTime: 2022-04-27, 23:29:16 * @description: Platform */ public class Accepted { static FastReader in = new FastReader(); static PrintWriter out = new PrintWriter(System.out); static Random rand = new Random(); static int[][] DIRS = new int[][]{{0, 1}, {0, -1}, {1, 0}, {-1, 0}}; public static void main(String[] args) { // long start = currentTimeMillis(); // int t = 3; int t = i(); out.println(); out.println(); out.println(); while (t-- > 0){ sol(); // int[] ans = sol(); // for (int i : ans){ // out.print(i + " "); // } // out.println(); // boolean ans = sol(); // if (ans){ // out.println("YES"); // }else{ // out.println("NO"); // } } // long end = currentTimeMillis(); // out.println(end - start); out.flush(); out.close(); } static void sol() { int n = i(); int[] ans = new int[n]; for (int i = 0; i < n; i++){ ans[i] = n - i; } for (int i = 1; i < n; i++){ swap(ans, i, i - 1); for (int j : ans){ out.print(j + " "); } out.println(); swap(ans, i, i - 1); } ans[0] = 1; ans[1] = 3; ans[2] = 2; for (int i = 3; i < n; i++){ ans[i] = i + 1; } for (int j : ans){ out.print(j + " "); } out.println(); } static boolean check(int x, int y, int n, int m){ return x >= 0 && y >= 0 && x < n && y < m; } static void swap(int[] nums, int l, int r){ int tmp = nums[l]; nums[l] = nums[r]; nums[r] = tmp; } static void ranArr() { int n = 3, len = 10, val = 10; System.out.println(n); for (int i = 0; i < n; i++) { int cnt = rand.nextInt(len) + 1; System.out.println(cnt); for (int j = 0; j < cnt; j++) { System.out.print(rand.nextInt(val) + " "); } System.out.println(); } } static double fastPower(double x, int n) { if (x == 0) return 0; long b = n; double res = 1.0; if (b < 0) { x = 1 / x; b = -b; } while (b > 0) { if ((b & 1) == 1) res *= x; x *= x; b >>= 1; } return res; } static int i() { return in.nextInt(); } static long l() { return in.nextLong(); } static double d() { return in.nextDouble(); } static String s() { return in.nextLine(); } static int[] inputI(int n) { int nums[] = new int[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextInt(); } return nums; } static long[] inputLong(int n) { long nums[] = new long[n]; for (int i = 0; i < n; i++) { nums[i] = in.nextLong(); } return nums; } } class ListNode { int val; ListNode next; public ListNode() { } public ListNode(int val) { this.val = val; } } class TreeNode { int val; TreeNode left; TreeNode right; public TreeNode() { } public TreeNode(int val) { this.val = val; } } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
f68b03e1c89842176ad2eb01b1b6a986
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.lang.Math.*; public class Inheritance{ static int highestPowerOf2(int n) { return (n & (~(n - 1))); } public static void main(String[] args){ Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); if(n==3) { System.out.println("3 "+"2 "+"1"); System.out.println("3 "+"1 "+"2"); System.out.println("2 "+"3 "+"1"); continue; } ArrayList<Integer>arr=new ArrayList<>(); for(int i=n;i>0;i--) { arr.add(i); } int count=0; while(count!=n) { for(int i=0;i<arr.size();i++) { System.out.print(arr.get(i)+" "); } System.out.println(); count++; int temp=arr.get(arr.size()-1); arr.remove(arr.size()-1); arr.add(0, temp); } } // for(int i=0;i<n;i++) // { // int ans1=32768-arr[i]; // int ans2=0; // if(arr[i]%2==0) // { // int count=0; // int i1=arr[i]; // while(i1%2==0) // { // count++; // i1=i1/2; // } // ans2=15-count; // } // else // { // int count=0; // int i1=arr[i]+1; // while(i1%2==0) // { // count++; // i1=i1/2; // } // //System.out.println(count); // ans2=15-count+1; // } // System.out.print(Math.min(ans2, ans1)+" "); // } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
80f2a0e14e4dfc4cf67c0a1a367be0ab
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; public class AntiFibonacciPermutation { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); List<Integer>list=new ArrayList<>(); List<Integer>list2=new ArrayList<>(); for(int i=1;i<=n;i++) { list.add(i); } Collections.reverse(list); list2.addAll(list); for(int i=n-1;i>0;i--) { Collections.swap(list, i, i-1); list2.addAll(list); } for(int i=0;i<list2.size();i++) { System.out.print(list2.get(i)+" "); if(i%n==n-1) { System.out.println(); } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
3741d2b79c5c5bd834033ff6549b023f
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; public class AntiFibonacciPermutation { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); List<Integer>list=new ArrayList<>(); List<Integer>list2=new ArrayList<>(); for(int i=1;i<=n;i++) { list.add(i); } Collections.reverse(list); list2.addAll(list); for(int i=n-1;i>0;i--) { Collections.swap(list, i, i-1); list2.addAll(list); } List<Integer> list3 = new ArrayList<Integer>(list2); AtomicInteger counter = new AtomicInteger(); final Collection<List<Integer>> partitionedList = list3.stream().collect(Collectors.groupingBy(i -> counter.getAndIncrement() / n)) .values(); for(List<Integer> x : partitionedList) { for(Integer y: x) { System.out.print(y+" "); } System.out.println(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
3d42dd11b970a631c8b02e5f37ac39e4
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class code { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t-->0) { int n=sc.nextInt(); int[] a=new int[n]; for (int i=0;i<n;i++){ a[i]=n-i; } for (int i = 0; i < a.length; i++) { System.out.print(a[i]+" "); } System.out.println(); for (int i = 1; i <n; i++) { swapprint(i,a); System.out.println(); } } } private static void swapprint(int i, int[] a) { int temp=a[i-1]; a[i-1]=a[i]; a[i]=temp; for (int j = 0; j < a.length; j++) { System.out.print(a[j]+" "); } temp=a[i-1]; a[i-1]=a[i]; a[i]=temp; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
5d6f4d13eb8f954fb24a67a3f01b503e
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class Main { private static int[] a; private static int cnt; public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); while(T-- > 0) { cnt = 0; int n = in.nextInt(); a = new int[n + 1]; int[] mark = new int[n + 1]; Arrays.fill(mark, 0); dfs(1, n, mark); } } public static int dfs(int now, int n, int[] mark) { if(now == n + 1) { if(cnt == n) return 1; for(int i = 3; i <= n; i++) { if(a[i-2] + a[i-1] == a[i]) { return 0; } } ++cnt; for(int i = 1; i <= n; i++) { System.out.printf("%d ", a[i]); } System.out.println(); return 0; } for(int i = n; i >= 1; i--) { if(mark[i] == 0) { a[now] = i; mark[i] = 1; int tmp = dfs(now + 1, n, mark); if(tmp == 1) return 1; mark[i] = 0; } } return 0; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
0cbd107124c6e1ca2c3e5b23d13aa326
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; public class solution { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { try { br = new BufferedReader( new FileReader("input.txt")); PrintStream out = new PrintStream(new FileOutputStream("output.txt")); System.setOut(out); } catch (Exception e) { 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static FastReader sc = new FastReader(); public static void main(String[] args) { long t=sc.nextLong(); while(t--!=0) { int n=sc.nextInt(); int b[]=new int[n];int y=n; if(n==3) { System.out.println(3+" "+2+" "+1); System.out.println(3+" "+1+" "+2); System.out.println(1+" "+3+" "+2); } else { for(int i=0;i<n;i++) { b[i]=y; y--; } for(int i=1;i<=n;i++) { int x=1; for(int j=0;j<x;j++){ int last; last=b[b.length-1]; for(int k1=b.length-1;k1>0;k1--) { b[k1]=b[k1-1]; } b[0]=last; } for(int m=0;m<n;m++) { System.out.print(b[m]+" "); } System.out.println(); } } } }//END OF MAIN METHOD }//END OF MAIN CLASS
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
b1c9e340a9d9dc72580d00083ad65d0a
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; public class cpSolutions { 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static FastReader sc=new FastReader(); static Scanner in=new Scanner(System.in); public static void main(String[] args) { long t=sc.nextLong(); while(t--!=0) { int n=sc.nextInt(); int b[]=new int[n];int y=n; if(n==3) { System.out.println(3+" "+2+" "+1); System.out.println(3+" "+1+" "+2); System.out.println(1+" "+3+" "+2); } else { for(int i=0;i<n;i++) { b[i]=y; y--; } for(int i=1;i<=n;i++) { int x=1; for(int j=0;j<x;j++){ int last; last=b[b.length-1]; for(int k1=b.length-1;k1>0;k1--) { b[k1]=b[k1-1]; } b[0]=last; } for(int m=0;m<n;m++) { System.out.print(b[m]+" "); } System.out.println(); } } } } //END OF MAIN MEHTOD } //END OF MAIN CLASS
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
a2ec1cdb36e43fb38df7c22d93839108
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { static int row; static int col; public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); int j=n; int i=0; int p=0; for(i=n;i>=1;i--){ System.out.print(j--+" "); } j=n-1; System.out.println(); for(i=n-1;i>=1;i--){ System.out.print(i+" "+n+" "); j=n-1; for(int q=1;q<n;q++){ if(q==n||q==i){ continue; } if(j==i) j--; System.out.print(j+" "); j--; } System.out.println(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
f7f041719aeeb78d513fc67e65991a73
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.Arrays; import java.util.Scanner; public class exc2 { public static void main(String[] args) { Scanner scanner=new Scanner(System.in); int n= scanner.nextInt(); while(n!=0) { int num=scanner.nextInt(); for(int i=1;i<=num;i++) { System.out.print(i+" "); for(int j=num;j>0;j--) { if(i!=j) System.out.print(j+" "); } System.out.println(); } n--; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
682e918bc223ec2595a79b8096d3cac1
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class AntiFib { public static void main(String[] args) throws IOException { FastScanner in = new FastScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); for (int i = 1; i <= t; i++) { int n = in.nextInt(); if (n == 3) { out.println("3 2 1"); out.println("1 3 2"); out.println("3 1 2"); } else { int[] x = new int[n]; x[0] = 1; x[1] = 2; for (int j = 2; j < n - 1; j++) { x[j] = j + 2; } x[n - 1] = 3; for (int j = 0; j < n; j++) { for (int k = j; k < j + n; k++) { out.print(x[k % n]); out.print(" "); } out.print("\n"); } } } out.close(); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { // noop } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
7152f25dcbfb4b0f864b656194fe76fb
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class B { public static void main(String[] args){ Scanner sc= new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); for(int i=1;i<=n;i++){ System.out.print(i+" "); for(int j=n;j>=i+1;j--) System.out.print(j+" "); for(int k=i-1;k>=1;k--) System.out.print(k+" "); System.out.println(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
307896512a2f4f46631e64eebb216085
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.System.out; import java.util.*; import java.io.*; import java.math.*; public class Main { public static void main (String[] args) throws java.lang.Exception { try { FastReader sc= new FastReader(); int T=sc.nextInt(); while(T>0) { int n=sc.nextInt(); int[]arr=new int[n]; for (int i = 0; i < n; i++) { arr[i] = i + 1; System.out.print((n-i)+" "); } System.out.println(); int k = 0; for (int i = 1; i < n; i++) { swap(k,k+1,arr); for (int j = n - 1; j >= 0; j--) { System.out.print(arr[j]+" "); } System.out.println(); swap(k,k+1,arr); k++; } T--; } } catch(Exception e) { return ; } } public static void swap(int a, int b, int[]arr) { int x=arr[a]; arr[a]=arr[b]; arr[b]=x; } } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
8b8f0129bb3472492ae7fc5b2f47bddd
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Q222022022 { public static void main(String[] args) throws Exception { BufferedReader sc = new BufferedReader(new InputStreamReader(System.in)); int test=Integer.parseInt(sc.readLine()); while(test>0) { int N=Integer.parseInt(sc.readLine()); int dec=0; if(N==3) { System.out.println("3 1 2"); System.out.println("3 2 1"); System.out.println("1 3 2"); } else { int [] Arr=new int[N]; for(int i=0;i<N;i++) { Arr[i]=N-i; } for(int i=0;i<N;i++) { for(int j=0;j<N;j++) { int index=(j+dec)%N; System.out.print((Arr[index])+" "); } System.out.println(); dec++; } } test--; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
db50462eba466e90c4e8fe20d37b6754
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
//import java.io.IOException; import java.io.*; import java.util.*; import java.util.function.LongToIntFunction; public class Template { static InputReader inputReader=new InputReader(System.in); static BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); static List<LinkedHashSet<Integer>>answer=new ArrayList<>(); static void solve() throws IOException { answer=new ArrayList<>(); int n=inputReader.nextInt(); for (int i=1;i<=n;i++) { for (int j=1;j<=n;j++) { if (i!=j) { LinkedHashSet<Integer>hashSet=new LinkedHashSet<>(); hashSet.add(i); hashSet.add(j); helper(i,j,2,hashSet,n); if (answer.size()==n) { break; } } } if (answer.size()==n) { break; } } for (LinkedHashSet<Integer>linkedHashSet:answer) { for (int ele:linkedHashSet) { out.print(ele+" "); } out.println(); } } static void helper(int prev1,int prev2,int ind,LinkedHashSet<Integer>hashSet,int n) { if (ind==n) { answer.add(new LinkedHashSet<>(hashSet)); return; } if (answer.size()==n) { return; } for (int i=1;i<=n;i++) { if ((prev2+prev1)!=i&&!hashSet.contains(i)) { hashSet.add(i); helper(prev2,i,ind+1,hashSet,n); hashSet.remove(i); } } } static PrintWriter out=new PrintWriter((System.out)); static void SortDec(long arr[]) { List<Long>list=new ArrayList<>(); for(long ele:arr) { list.add(ele); } Collections.sort(list,Collections.reverseOrder()); for (int i=0;i<list.size();i++) { arr[i]=list.get(i); } } static void Sort(long arr[]) { List<Long>list=new ArrayList<>(); for(long ele:arr) { list.add(ele); } Collections.sort(list); for (int i=0;i<list.size();i++) { arr[i]=list.get(i); } } public static void main(String args[])throws IOException { int t=inputReader.nextInt(); while (t-->0) { solve();} long s = System.currentTimeMillis(); // out.println(System.currentTimeMillis()-s+"ms"); out.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[8192]; private int curChar, snumChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int snext() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
e527bdbc78b58066459f448e9802d59b
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
//package CodeForces; import java.util.*; public class Main { public static void main(String[] arg) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); Integer[] arr = new Integer[n]; for(int i = 0;i < n;i++) arr[i] = i + 1; Arrays.sort(arr,Collections.reverseOrder()); for(int i = 0;i < n;i++) { for(int j = 0;j < n;j++) { System.out.print(arr[j]+" "); } System.out.println(); if(i < n - 1) { int tmp = arr[0]; arr[0] = arr[i + 1]; arr[i + 1] = tmp; } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
4bebdbcb853198bbefa9251d5d9d2071
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; public class AntiFibonacci { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(br.readLine()); while (t-->0){ int i=Integer.parseInt(br.readLine()); if(i>2){ ArrayList<Integer> list=new ArrayList<>(); for(int j=i;j>=2;j--) list.add(j); int p=1; for(int j=1;j<=i;j++) { String str=""; int res=i; for(int x=1;x<=i;x++){ if(x==p){ str+="1 "; } else str+=res--+" "; } p++; System.out.println(str); } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
f24e67ee38864bb7aa70786e602dd8be
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner (System.in); int test; test=in.nextInt(); while(test-- > 0) { int n; n=in.nextInt(); int ar[]=new int[n]; for(int i=0;i<n;i++) { ar[i]=i+1; } int art=0,j=0; for(int i=0;i<n;i++) { System.out.print(ar[art]+" "); for(int anmol=n-1;anmol>=0;anmol--) { if(anmol==art) continue; System.out.print(ar[anmol]+" "); } System.out.println(); art++; j++; } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
bbf8de68b5d9bedf3ad40243d98b9393
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; import java.text.DecimalFormat; public class quetion1template { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static void main(String[] args) { try { FastReader in = new FastReader(); FastWriter out = new FastWriter(); int testCases = in.nextInt(); while (testCases-- > 0) { int n = in.nextInt(); int a[][] = new int[n][n]; int temp = 1; int start = 1; for (int i = 0; i < n - 1; i++) { int sum = 0; for (int j = 0; j < n; j++) { a[i][j] = start; start++; if (j >= 2) { sum = a[i][j - 1] + a[i][j - 2]; if (sum == a[i][j]) { int swap=a[i][j-1]; a[i][j-1]=a[i][j]; a[i][j]=swap; } } if (start > n) { start = 1; } } // start=a[i][n-1]+1; // if (start > n) { // start = 1; // } // if(start==a[i][0] && start!=n) { // start++; // } start=i+2; } for(int i=n-1;i<n;i++) { start=n; for(int j=0;j<n;j++) { a[i][j]=start; start--; if(start<1) { start=n; } } } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { System.out.print(a[i][j]+" "); } System.out.println(); } System.out.println(); } out.close(); } catch (Exception e) { return; } } private static void swap(int i, int j) { // TODO Auto-generated method stub int swap = i; i = j; j = swap; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
dcdc8045e3ed9d20c0ec3e1a12ba6dc0
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class test1 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n = scan.nextInt(); scan.nextLine(); for (int i = 0; i < n; i++) { int size = scan.nextInt(); int[] arr = new int[size]; for (int j = 0; j < arr.length; j++) { arr[j] = arr.length - j; } for (int j = 0; j < size; j++) { for (int j2 = 0; j2 < size; j2++) { System.out.print(arr[j2] + " "); } System.out.println(); if (j != size - 1) { int temp = arr[0]; arr[0] = arr[j + 1]; arr[j + 1] = temp; } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c5797e2af85d240d698cfe24f4de6d7b
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class Solution { static Scanner sc = new Scanner(System.in); public static void reverse(int[] arr, int l, int r) { int d = (r - l + 1) / 2; for (int i = 0; i < d; i++) { int t = arr[l + i]; arr[l + i] = arr[r - i]; arr[r - i] = t; } } public static void main(String[] args) { if (System.getProperty("ONLINE_JUDGE") == null) { try { System.setOut(new PrintStream( new FileOutputStream("output.txt"))); sc = new Scanner(new File("input.txt")); } catch (Exception e) { } } int n = sc.nextInt(); for (int i = 0; i < n; i++) { int num = sc.nextInt(); solve(num); } // HashMap<String, Integer> map = new HashMap<String, Integer>(); // int n = sc.nextInt(); // for (int i = 0; i < n; i++) { // int no_l = sc.nextInt(); // for (int j = 0; j < no_l; j++) { // String str = sc.next(); // map.put(str, map.getOrDefault(str, 0) + 1); // } // int no_d = sc.nextInt(); // for (int k = 0; k < no_d; k++) { // String str_d = sc.next(); // map.put(str_d, map.getOrDefault(str_d, 0) - 1); // } // } // int count = 0; // StringBuilder sb = new StringBuilder(); // for (Map.Entry<String, Integer> entry : map.entrySet()) { // String key = entry.getKey(); // int value = entry.getValue(); // if (value > 0) { // sb.append(key).append(" "); // count++; // } // } // System.out.println(count + " " + sb); // System.out.println(map); // for (int ks = 1; ks <= caseNum; ks++) { // // System.out.println(String.format("Case #%d: %s", ks, solve())); // solve(); // } } static void solve(int num) { int arr[] = new int[num]; for (int i = num, j = 0; i >= 1; j++, i--) { arr[j] = i; } printArray(arr); for (int i = num - 1; i >= 1 ; i--) { int temp = arr[i]; arr[i] = arr[i - 1]; arr[i - 1] = temp; printArray(arr); } } static void printArray(int arr[]) { for (int num : arr) System.out.print(num + " "); System.out.println(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
01790966964222476948b49ce55d17c2
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; public class Main { public static class Pair implements Comparable < Pair > { long d; int i; Pair(long d, int i) { this.d = d; this.i = i; } public int compareTo(Pair o) { if (this.d > o.d) return 1; else return -1; } } public static class SegmentTree { long[] st; long[] lazy; int n; SegmentTree(long[] arr, int n) { this.n = n; st = new long[4 * n]; lazy = new long[4 * n]; construct(arr, 0, n - 1, 0); } public long construct(long[] arr, int si, int ei, int node) { if (si == ei) { st[node] = arr[si]; return arr[si]; } int mid = (si + ei) / 2; long left = construct(arr, si, mid, 2 * node + 1); long right = construct(arr, mid + 1, ei, 2 * node + 2); st[node] = left + right; return st[node]; } public long get(int l, int r) { return get(0, n - 1, l, r, 0); } public long get(int si, int ei, int l, int r, int node) { if (r < si || l > ei) return 0; if (lazy[node] != 0) { st[node] += lazy[node] * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += lazy[node]; lazy[2 * node + 2] += lazy[node]; } lazy[node] = 0; } if (l <= si && r >= ei) return st[node]; int mid = (si + ei) / 2; return get(si, mid, l, r, 2 * node + 1) + get(mid + 1, ei, l, r, 2 * node + 2); } public void update(int index, int value) { update(0, n - 1, index, 0, value); } public void update(int si, int ei, int index, int node, int val) { if (si == ei) { st[node] = val; return; } int mid = (si + ei) / 2; if (index <= mid) { update(si, mid, index, 2 * node + 1, val); } else { update(mid + 1, ei, index, 2 * node + 2, val); } st[node] = st[2 * node + 1] + st[2 * node + 2]; } public void rangeUpdate(int l, int r, int val) { rangeUpdate(0, n - 1, l, r, 0, val); } public void rangeUpdate(int si, int ei, int l, int r, int node, int val) { if (r < si || l > ei) return; if (lazy[node] != 0) { st[node] += lazy[node] * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += lazy[node]; lazy[2 * node + 2] += lazy[node]; } lazy[node] = 0; } if (l <= si && r >= ei) { st[node] += val * (ei - si + 1); if (si != ei) { lazy[2 * node + 1] += val; lazy[2 * node + 2] += val; } return; } int mid = (si + ei) / 2; rangeUpdate(si, mid, l, r, 2 * node + 1, val); rangeUpdate(mid + 1, ei, l, r, 2 * node + 2, val); st[node] = st[2 * node + 1] + st[2 * node + 2]; } } static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } public static void main(String[] args) throws IOException { if (System.getProperty("ONLINE_JUDGE") == null) { try { System.setIn(new FileInputStream(new File("input.txt"))); System.setOut(new PrintStream(new File("output.txt"))); } catch (Exception e) { } } Reader sc = new Reader(); int tc = sc.nextInt(); StringBuilder sb = new StringBuilder(); while (tc-- > 0) { int n = sc.nextInt(); int[] arr = new int[n + 1]; for (int i = 1; i <= n; i++) arr[i] = n - i + 1; for (int i = 1; i <= n; i++) sb.append(arr[i] + " "); sb.append("\n"); for (int i = n; i > 1; i--) { int temp = arr[i]; arr[i] = arr[i - 1]; arr[i - 1] = temp; for (int j = 1; j <= n; j++) sb.append(arr[j] + " "); sb.append("\n"); } } System.out.println(sb); } public static int get(int[] dsu, int x) { if (dsu[x] == x) return x; int k = get(dsu, dsu[x]); dsu[x] = k; return k; } static int gcd(int a, int b) { // Everything divides 0 if (a == 0) return b; if (b == 0) return a; // base case if (a == b) return a; // a is greater if (a > b) return gcd(a - b, b); return gcd(a, b - a); } public static int Xor(int n) { if (n % 4 == 0) return n; // If n%4 gives remainder 1 if (n % 4 == 1) return 1; // If n%4 gives remainder 2 if (n % 4 == 2) return n + 1; // If n%4 gives remainder 3 return 0; } public static long pow(long a, long b, long mod) { long res = 1; while (b > 0) { if ((b & 1) > 0) res = (res * a) % mod; b = b >> 1; a = ((a % mod) * (a % mod)) % mod; } return (res % mod + mod) % mod; } public static double digit(long num) { return Math.floor(Math.log10(num) + 1); } public static boolean isPos(int idx, long[] arr, long[] diff) { if (idx == 0) { for (int i = 0; i <= Math.min(arr[0], arr[1]); i++) { diff[idx] = i; arr[0] -= i; arr[1] -= i; if (isPos(idx + 1, arr, diff)) { return true; } arr[0] += i; arr[1] += i; } } else if (idx == 1) { if (arr[2] - arr[1] >= 0) { long k = arr[1]; diff[idx] = k; arr[1] = 0; arr[2] -= k; if (isPos(idx + 1, arr, diff)) { return true; } arr[1] = k; arr[2] += k; } else return false; } else { if (arr[2] == arr[0] && arr[1] == 0) { diff[2] = arr[2]; return true; } else { return false; } } return false; } public static boolean isPal(String s) { for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != s.charAt(s.length() - 1 - i)) return false; } return true; } static int upperBound(ArrayList<Long> arr, long key) { int mid, N = arr.size(); // Initialise starting index and // ending index int low = 0; int high = N; // Till low is less than high while (low < high && low != N) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is greater than or equal // to arr[mid], then find in // right subarray if (key >= arr.get(mid)) { low = mid + 1; } // If key is less than arr[mid] // then find in left subarray else { high = mid; } } // If key is greater than last element which is // array[n-1] then upper bound // does not exists in the array return low; } static int lowerBound(ArrayList<Long> array, long key) { // Initialize starting index and // ending index int low = 0, high = array.size(); int mid; // Till high does not crosses low while (low < high) { // Find the index of the middle element mid = low + (high - low) / 2; // If key is less than or equal // to array[mid], then find in // left subarray if (key <= array.get(mid)) { high = mid; } // If key is greater than array[mid], // then find in right subarray else { low = mid + 1; } } // If key is greater than last element which is // array[n-1] then lower bound // does not exists in the array if (low < array.size() && array.get(low) < key) { low++; } // Returning the lower_bound index return low; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
29000a753f2c88325960e41b94b7fc9b
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; public class solve { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { int n = Integer.parseInt(br.readLine()); int[] result = new int[n]; for (int j = n; j >= 1; j--) { result[n - j] = j; } printResult(result, pw); for (int j = n - 1; j >= 1; j--) { pw.println(); int temp = result[j]; result[j] = result[j - 1]; result[j - 1] = temp; printResult(result, pw); } pw.println(); } pw.flush(); pw.close(); br.close(); } public static void printResult(int[] result, PrintWriter pw) { for (int i = 0; i < result.length; i++) { if (i > 0) pw.print(" "); pw.print(result[i]); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
08260ad43b99f9a216c9ca1a7b73b6fa
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class Main{ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int z=0;z<t;z++){ int n=sc.nextInt(); for(int i=n;i>1;i--){ for(int j=n;j>=1;j--){ if(i==j){ System.out.print((j-1)+" "+(j)+" "); j--; }else{ System.out.print(j+" "); } } System.out.println(); } for(int i=n;i>=1;i--){ System.out.print(i+ " "); } System.out.println(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
95f43e846b4b706552cd334262a4cae4
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class b { FastScanner scn; PrintWriter w; PrintStream fs; int MOD = 1000000007; int MAX = 200005; long mul(long x, long y) { long res = x * y; return (res >= MOD ? res % MOD : res); } long power(long x, long y) { if (y < 0) return 1; long res = 1; x %= MOD; while (y != 0) { if ((y & 1) == 1) res = mul(res, x); y >>= 1; x = mul(x, x); } return res; } void ruffleSort(int[] a) { int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n), temp = a[i]; a[i] = a[oi]; a[oi] = temp; } Arrays.sort(a); } void reverseSort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i = 0; i < arr.length; i++) { list.add(arr[i]); } Collections.sort(list, Collections.reverseOrder()); for (int i = 0; i < arr.length; i++) { arr[i] = list.get(i); } } boolean LOCAL; void debug(Object... o) { if (LOCAL) System.err.println(Arrays.deepToString(o)); } // SPEED IS NOT THE CRITERIA, CODE SHOULD BE A NO BRAINER, CMP KILLS, MOCIM void solve() { int t=scn.nextInt(); while(t-->0) { int n=scn.nextInt(); if(n==3){ w.println("3 2 1"); w.println("1 3 2"); w.println("3 1 2"); }else if(n<=6){ int[] ar= new int[3]; int val = n; for(int i=0;i<3;i++){ ar[i] = val; val--; } ArrayList<Integer> ans = new ArrayList<>(); while(val>0){ ans.add(val); val--; } AllPermutation perm = new AllPermutation(ar); debug(ar); int count = 0; perm.GetFirst(); for(int ele:ans){ w.print(ele+" "); } w.println(); count++; while(count!=n&&perm.HasNext()){ count++; perm.GetNext(); for(int ele:ans){ w.print(ele+" "); } w.println(); } }else if(n==7){ int[] ar= new int[4]; int val = n; for(int i=0;i<4;i++){ ar[i] = val; val--; } ArrayList<Integer> ans = new ArrayList<>(); while(val>0){ ans.add(val); val--; } AllPermutation perm = new AllPermutation(ar); debug(ar); int count = 0; perm.GetFirst(); for(int ele:ans){ w.print(ele+" "); } w.println(); count++; while(count!=n&&perm.HasNext()){ count++; perm.GetNext(); for(int ele:ans){ w.print(ele+" "); } w.println(); } }else{ int[] ar= new int[5]; int val = n; for(int i=0;i<5;i++){ ar[i] = val; val--; } ArrayList<Integer> ans = new ArrayList<>(); while(val>0){ ans.add(val); val--; } AllPermutation perm = new AllPermutation(ar); debug(ar); int count = 0; perm.GetFirst(); for(int ele:ans){ w.print(ele+" "); } w.println(); count++; while(count!=n&&perm.HasNext()){ count++; perm.GetNext(); for(int ele:ans){ w.print(ele+" "); } w.println(); } } } } class AllPermutation { // The input array for permutation private final int Arr[]; // Index array to store indexes of input array private int Indexes[]; // The index of the first "increase" // in the Index array which is the smallest // i such that Indexes[i] < Indexes[i + 1] private int Increase; // Constructor public AllPermutation(int arr[]) { this.Arr = arr; this.Increase = -1; this.Indexes = new int[this.Arr.length]; } // Initialize and output // the first permutation public void GetFirst() { // Allocate memory for Indexes array this.Indexes = new int[this.Arr.length]; // Initialize the values in Index array // from 0 to n - 1 for (int i = 0; i < Indexes.length; ++i) { this.Indexes[i] = i; } // Set the Increase to 0 // since Indexes[0] = 0 < Indexes[1] = 1 this.Increase = 0; // Output the first permutation this.Output(); } // Function that returns true if it is // possible to generate the next permutation public boolean HasNext() { // When Increase is in the end of the array, // it is not possible to have next one return this.Increase != (this.Indexes.length - 1); } // Output the next permutation public void GetNext() { // Increase is at the very beginning if (this.Increase == 0) { // Swap Index[0] and Index[1] this.Swap(this.Increase, this.Increase + 1); // Update Increase this.Increase += 1; while (this.Increase < this.Indexes.length - 1 && this.Indexes[this.Increase] > this.Indexes[this.Increase + 1]) { ++this.Increase; } } else { // Value at Indexes[Increase + 1] is greater than Indexes[0] // no need for binary search, // just swap Indexes[Increase + 1] and Indexes[0] if (this.Indexes[this.Increase + 1] > this.Indexes[0]) { this.Swap(this.Increase + 1, 0); } else { // Binary search to find the greatest value // which is less than Indexes[Increase + 1] int start = 0; int end = this.Increase; int mid = (start + end) / 2; int tVal = this.Indexes[this.Increase + 1]; while (!(this.Indexes[mid]<tVal&& this.Indexes[mid - 1]> tVal)) { if (this.Indexes[mid] < tVal) { end = mid - 1; } else { start = mid + 1; } mid = (start + end) / 2; } // Swap this.Swap(this.Increase + 1, mid); } // Invert 0 to Increase for (int i = 0; i <= this.Increase / 2; ++i) { this.Swap(i, this.Increase - i); } // Reset Increase this.Increase = 0; } this.Output(); } // Function to output the input array private void Output() { for (int i = 0; i < this.Indexes.length; ++i) { // Indexes of the input array // are at the Indexes array w.print(this.Arr[this.Indexes[i]]+" "); } } // Swap two values in the Indexes array private void Swap(int p, int q) { int tmp = this.Indexes[p]; this.Indexes[p] = this.Indexes[q]; this.Indexes[q] = tmp; } } void run() { try { long ct = System.currentTimeMillis(); scn = new FastScanner(new File("input.txt")); w = new PrintWriter(new File("output.txt")); fs = new PrintStream("error.txt"); System.setErr(fs); LOCAL = true; solve(); w.close(); System.err.println(System.currentTimeMillis() - ct); } catch (FileNotFoundException e) { e.printStackTrace(); } } void runIO() { scn = new FastScanner(System.in); w = new PrintWriter(System.out); LOCAL = false; solve(); w.close(); } class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner(File f) { try { br = new BufferedReader(new FileReader(f)); } catch (FileNotFoundException e) { e.printStackTrace(); } } public FastScanner(InputStream f) { br = new BufferedReader(new InputStreamReader(f)); } String next() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return null; st = new StringTokenizer(s); } return st.nextToken(); } boolean hasMoreTokens() { while (st == null || !st.hasMoreTokens()) { String s = null; try { s = br.readLine(); } catch (IOException e) { e.printStackTrace(); } if (s == null) return false; st = new StringTokenizer(s); } return true; } int nextInt() { return Integer.parseInt(next()); } int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } long[] nextLongArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) { a[i] = nextLong(); } return a; } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } int lowerBound(int[] arr, int x) { int n = arr.length, si = 0, ei = n - 1; while (si <= ei) { int mid = si + (ei - si) / 2; if (arr[mid] == x) { if (mid - 1 >= 0 && arr[mid - 1] == arr[mid]) { ei = mid - 1; } else { return mid; } } else if (arr[mid] > x) { ei = mid - 1; } else { si = mid + 1; } } return si; } int upperBound(int[] arr, int x) { int n = arr.length, si = 0, ei = n - 1; while (si <= ei) { int mid = si + (ei - si) / 2; if (arr[mid] == x) { if (mid + 1 < n && arr[mid + 1] == arr[mid]) { si = mid + 1; } else { return mid + 1; } } else if (arr[mid] > x) { ei = mid - 1; } else { si = mid + 1; } } return si; } int upperBound(ArrayList<Integer> list, int x) { int n = list.size(), si = 0, ei = n - 1; while (si <= ei) { int mid = si + (ei - si) / 2; if (list.get(mid) == x) { if (mid + 1 < n && list.get(mid + 1) == list.get(mid)) { si = mid + 1; } else { return mid + 1; } } else if (list.get(mid) > x) { ei = mid - 1; } else { si = mid + 1; } } return si; } void swap(int[] arr, int i, int j) { int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } long nextPowerOf2(long v) { if (v == 0) return 1; v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v |= v >> 32; v++; return v; } int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } // TC- O(logmax(a,b)) boolean nextPermutation(int[] arr,ArrayList<Integer> ans) { debug("hi"); if (arr == null || arr.length <= 1) { return false; } int last = arr.length - 2; while (last >= 0) { if (arr[last] < arr[last + 1]) { break; } last--; } if (last < 0) { return false; } if (last >= 0) { int nextGreater = arr.length - 1; for (int i = arr.length - 1; i > last; i--) { if (arr[i] > arr[last]) { nextGreater = i; break; } } swap(arr, last, nextGreater); } int i = last + 1, j = arr.length - 1; while (i < j) { swap(arr, i++, j--); } int n= arr.length; for(int k=0;k<n;k++){ w.print(arr[k]+" "); } for(int ele:ans){ w.print(ele+" "); } w.println(); return true; } public static void main(String[] args) { new b().runIO(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
f2692184e328a81803efb391366fa59d
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; import java. util. Arrays; public class Main { public static void print(int[] arr) { for(int i=0;i<arr.length;i++) { System.out.print(arr[i]+" "); } System.out.println(); } public static void main(String args[]) throws IOException { Scanner scn = new Scanner(System.in); int n =scn.nextInt(); for (int i = 0; i <n ; i++) { int x=scn.nextInt(); int [] arr=new int [x]; for(int j=0;j<x;j++) { arr[j]=j+1; } int y=0,l=x-1; while(y<=l) { int temp1=arr[y]; arr[y]=arr[l]; arr[l]=temp1; y++; l--; } print(arr); for(int k=0;k<x-1;k++) { int temp=arr[k]; arr[k]=arr[k+1]; arr[k+1]=temp; print(arr); int temp2=arr[k]; arr[k]=arr[k+1]; arr[k+1]=temp2; } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
bffc7847f6611861160454ee29b3b0af
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author ankur.y */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); BAntiFibonacciPermutation solver = new BAntiFibonacciPermutation(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class BAntiFibonacciPermutation { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); if (n == 3) { out.println(1 + " " + 3 + " " + 2); out.println(2 + " " + 3 + " " + 1); out.println(3 + " " + 2 + " " + 1); return; } int ar[] = new int[n]; ar[0] = 1; ar[1] = 3; ar[2] = 2; for (int i = 3; i < n; i++) { ar[i] = i + 1; } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { out.print(ar[(j + i) % n] + " "); } out.println(); } } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar; private int snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { //*-*------clare-----anjlika--- //remeber while comparing 2 non primitive data type not to use == //remember Arrays.sort for primitive data has worst time case complexity of 0(n^2) bcoz it uses quick sort //again silly mistakes ,yr kb tk krta rhega ye mistakes //try to write simple codes ,break it into simple things //knowledge>rating /* public class Main implements Runnable{ public static void main(String[] args) { new Thread(null,new Main(),"Main",1<<26).start(); } public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; libraries.InputReader in = new libraries.InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC();//chenge the name of task solver.solve(1, in, out); out.close(); } */ if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String next() { return readString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c8ce9eed63e362fa6312c2eb944a03ba
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.Scanner; public class cfContest1644 { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); StringBuilder sb = new StringBuilder(); k: while (t-- > 0) { int n = scan.nextInt(); int curr = n; for (int i = 0; i < n; i++) { if (curr == 5) { --curr; continue; } if (i == n - 3) { for (int j = n; j >= 1; j--) { if (j == 3) { sb.append("2 "); } else if (j == 1) { sb.append("1 "); } else if (j == 2) { sb.append("3 "); } else { sb.append(j + " "); } } } else { for (int j = n; j >= 2; j--) { if (curr == j) { sb.append(1 + " "); } else { sb.append(j + " "); } } sb.append(curr + " "); } sb.append("\n"); --curr; } if (n >= 5) { sb.append((n - 1) + " " + n + " "); for (int j = n - 2; j >= 1; j--) { sb.append(j + " "); } sb.append("\n"); } } System.out.println(sb); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
953df744c97fc8ecde4f499a9684a807
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class edu_123_a { public static void main(String args[]){ FScanner in = new FScanner(); PrintWriter out = new PrintWriter(System.out); int t = in.nextInt(); while(t-->0) { int n=in.nextInt(); int k=0; if(n==3) { out.println("3 2 1"); out.println("1 3 2"); out.println("3 1 2"); } else { for(int i=1;i<=n;i++) { for(int j=n-k;j>=1;j--) { out.print(j+" "); } for(int j=n;j>n-k;j--) { out.print(j+" "); } out.println(); k++; } } //out.println(); } out.close(); } static class FScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer sb = new StringTokenizer(""); String next(){ while(!sb.hasMoreTokens()){ try{ sb = new StringTokenizer(br.readLine()); } catch(IOException e){ } } return sb.nextToken(); } String nextLine(){ try{ return br.readLine(); } catch(IOException e) { } return ""; } int nextInt(){ return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } int[] readArray(int n) { int a[] = new int[n]; for(int i=0;i<n;i++) a[i] = nextInt(); return a; } float nextFloat(){ return Float.parseFloat(next()); } double nextDouble(){ return Double.parseDouble(next()); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
d097891528c40ee333cf0229f8bc59e7
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by Fernflower decompiler) // import java.io.BufferedWriter; import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.util.*; public class CFB { static CFB.Reader sc = new CFB.Reader(); static BufferedWriter bw; static int team1; static int team2; static int minkicks; public CFB() { } static long h1=0; public static void main(String[] args) throws IOException { int t =inputInt(); process: for (int p = 1;p<=t; p++) { int n=inputInt(); if(n==3){ print("3 2 1\n" + "1 3 2\n" + "3 1 2"); println(""); continue process; } int st=n; int orig=st; for (int i=1;i<=n;i++){ //int chance=0; // List<Integer> list=new ArrayList<>(); for(int j=1;j<=n;j++){ print(st+" "); // list.add(st); /* if(list.size()>=3&&list.get(list.size()-1)==(list.get(list.size()-2)+list.get(list.size()-3))){ print("found"+" "+n); }*/ st--; if(st==0) st=n; } /* if(list.size()>3&&list.get(list.size()-1)==(list.get(list.size()-2)+list.get(list.size()-3))){ print("found"+" "+n); }*/ st=--orig; println(""); } } bw.flush(); bw.close(); } static void swap(int[] ar,int i,int j){ int temp=ar[i]; ar[i]=ar[j]; ar[j]=temp; } public static int getAns(int i, int j, int[] ar, int c, int[][] dp) { if (c != 0 && i <= j) { if (dp[i][c] != -1) return dp[i][c]; int min = Integer.MAX_VALUE; for (int p = i; p <= j; p++) { min = Math.min(min, ar[p] - ar[i] + getAns(p + 1, j, ar, c - 1, dp)); } dp[i][c] = min; return min; } else if (i <= j) { return ar[j] - ar[i]; } else { return 10000000; } } public static class Coffee { int st, en; public Coffee(int st, int en) { this.st = st; this.en = en; } } public static int checker(int a) { if (a % 2 == 0) { return 1; } else { byte b; do { b = 2; } while (a + b != (a ^ b)); return b; } } public static boolean checkPrime(int n) { if (n != 0 && n != 1) { for (int j = 2; j * j <= n; ++j) { if (n % j == 0) { return false; } } return true; } else { return false; } } public static void dfs1(List<List<Integer>> g, boolean[] visited, Stack<Integer> stack, int num) { visited[num] = true; Iterator var4 = ((List) g.get(num)).iterator(); while (var4.hasNext()) { Integer integer = (Integer) var4.next(); if (!visited[integer]) { dfs1(g, visited, stack, integer); } } stack.push(num); } public static void dfs2(List<List<Integer>> g, boolean[] visited, List<Integer> list, int num, int c, int[] raj) { visited[num] = true; Iterator var6 = ((List) g.get(num)).iterator(); while (var6.hasNext()) { Integer integer = (Integer) var6.next(); if (!visited[integer]) { dfs2(g, visited, list, integer, c, raj); } } raj[num] = c; list.add(num); } public static int inputInt() throws IOException { return sc.nextInt(); } public static long inputLong() throws IOException { return sc.nextLong(); } public static double inputDouble() throws IOException { return sc.nextDouble(); } public static String inputString() throws IOException { return sc.readLine(); } public static void print(String a) throws IOException { bw.write(a); } public static void printSp(String a) throws IOException { bw.write(a + " "); } public static void println(String a) throws IOException { bw.write(a + "\n"); } public static long getAns(int[] ar, int c, long[][] dp, int i, int sign) { if (i < 0) { return 1L; } else if (c <= 0) { return 1L; } else { dp[i][c] = Math.max(dp[i][c], Math.max((long) ar[i] * getAns(ar, c - 1, dp, i - 1, sign), getAns(ar, c, dp, i - 1, 1))); return dp[i][c]; } } public static long power(long a, long b, long c) { long ans; for (ans = 1L; b != 0L; b /= 2L) { if (b % 2L == 1L) { ans *= a; ans %= c; } a *= a; a %= c; } return ans; } public static long power1(long a, long b, long c) { long ans; for (ans = 1L; b != 0L; b /= 2L) { if (b % 2L == 1L) { ans = multiply(ans, a, c); } a = multiply(a, a, c); } return ans; } public static long multiply(long a, long b, long c) { long res = 0L; for (a %= c; b > 0L; b /= 2L) { if (b % 2L == 1L) { res = (res + a) % c; } a = (a + a) % c; } return res % c; } public static long totient(long n) { long result = n; for (long i = 2L; i * i <= n; ++i) { if (n % i == 0L) { while (n % i == 0L) { n /= i; } result -= result / i; } } if (n > 1L) { result -= result / n; } return result; } public static long gcd(long a, long b) { return b == 0L ? a : gcd(b, a % b); } public static boolean[] primes(int n) { boolean[] p = new boolean[n + 1]; p[0] = false; p[1] = false; int i; for (i = 2; i <= n; ++i) { p[i] = true; } for (i = 2; i * i <= n; ++i) { if (p[i]) { for (int j = i * i; j <= n; j += i) { p[j] = false; } } } return p; } public String LargestEven(String S) { int[] count = new int[10]; int num; for (num = 0; num < S.length(); ++num) { ++count[S.charAt(num) - 48]; } num = -1; for (int i = 0; i <= 8; i += 2) { if (count[i] > 0) { num = i; break; } } StringBuilder ans = new StringBuilder(); for (int i = 9; i >= 0; --i) { int j; if (i != num) { for (j = 1; j <= count[i]; ++j) { ans.append(i); } } else { for (j = 1; j <= count[num] - 1; ++j) { ans.append(num); } } } if (num != -1 && count[num] > 0) { ans.append(num); } return ans.toString(); } static { bw = new BufferedWriter(new OutputStreamWriter(System.out)); team1 = 0; team2 = 0; minkicks = 10; } public static class Score { int l; String s; public Score(int l, String s) { this.l = l; this.s = s; } } public static class Ath { int r1; int r2; int r3; int r4; int r5; int index; public Ath(int r1, int r2, int r3, int r4, int r5, int index) { this.r1 = r1; this.r2 = r2; this.r3 = r3; this.r4 = r4; this.r5 = r5; this.index = index; } } static class Reader { private final int BUFFER_SIZE = 65536; private DataInputStream din; private byte[] buffer; private int bufferPointer; private int bytesRead; public Reader() { this.din = new DataInputStream(System.in); this.buffer = new byte[65536]; this.bufferPointer = this.bytesRead = 0; } public Reader(String file_name) throws IOException { this.din = new DataInputStream(new FileInputStream(file_name)); this.buffer = new byte[65536]; this.bufferPointer = this.bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; int cnt; byte c; for (cnt = 0; (c = this.read()) != -1 && c != 10; buf[cnt++] = (byte) c) { } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c; for (c = this.read(); c <= 32; c = this.read()) { } boolean neg = c == 45; if (neg) { c = this.read(); } do { ret = ret * 10 + c - 48; } while ((c = this.read()) >= 48 && c <= 57); return neg ? -ret : ret; } public long nextLong() throws IOException { long ret = 0L; byte c; for (c = this.read(); c <= 32; c = this.read()) { } boolean neg = c == 45; if (neg) { c = this.read(); } do { ret = ret * 10L + (long) c - 48L; } while ((c = this.read()) >= 48 && c <= 57); return neg ? -ret : ret; } public double nextDouble() throws IOException { double ret = 0.0D; double div = 1.0D; byte c; for (c = this.read(); c <= 32; c = this.read()) { } boolean neg = c == 45; if (neg) { c = this.read(); } do { ret = ret * 10.0D + (double) c - 48.0D; } while ((c = this.read()) >= 48 && c <= 57); if (c == 46) { while ((c = this.read()) >= 48 && c <= 57) { ret += (double) (c - 48) / (div *= 10.0D); } } return neg ? -ret : ret; } private void fillBuffer() throws IOException { this.bytesRead = this.din.read(this.buffer, this.bufferPointer = 0, 65536); if (this.bytesRead == -1) { this.buffer[0] = -1; } } private byte read() throws IOException { if (this.bufferPointer == this.bytesRead) { this.fillBuffer(); } return this.buffer[this.bufferPointer++]; } public void close() throws IOException { if (this.din != null) { this.din.close(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
7ff0cb9b75739f88164e53179bab1cc9
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
/* /$$$$$ /$$$$$$ /$$ /$$ /$$$$$$ |__ $$ /$$__ $$ |$$ |$$ /$$__ $$ | $$| $$ \ $$| $$|$$| $$ \ $$ | $$| $$$$$$$$| $$ / $$/| $$$$$$$$ / $$ | $$| $$__ $$ \ $$ $$/ | $$__ $$ | $$ | $$| $$ | $$ \ $$$/ | $$ | $$ | $$$$$$/| $$ | $$ \ $/ | $$ | $$ \______/ |__/ |__/ \_/ |__/ |__/ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ /$$ /$$ /$$ /$$ /$$$$$$$$ /$$$$$$$ | $$__ $$| $$__ $$ /$$__ $$ /$$__ $$| $$__ $$ /$$__ $$| $$$ /$$$| $$$ /$$$| $$_____/| $$__ $$ | $$ \ $$| $$ \ $$| $$ \ $$| $$ \__/| $$ \ $$| $$ \ $$| $$$$ /$$$$| $$$$ /$$$$| $$ | $$ \ $$ | $$$$$$$/| $$$$$$$/| $$ | $$| $$ /$$$$| $$$$$$$/| $$$$$$$$| $$ $$/$$ $$| $$ $$/$$ $$| $$$$$ | $$$$$$$/ | $$____/ | $$__ $$| $$ | $$| $$|_ $$| $$__ $$| $$__ $$| $$ $$$| $$| $$ $$$| $$| $$__/ | $$__ $$ | $$ | $$ \ $$| $$ | $$| $$ \ $$| $$ \ $$| $$ | $$| $$\ $ | $$| $$\ $ | $$| $$ | $$ \ $$ | $$ | $$ | $$| $$$$$$/| $$$$$$/| $$ | $$| $$ | $$| $$ \/ | $$| $$ \/ | $$| $$$$$$$$| $$ | $$ |__/ |__/ |__/ \______/ \______/ |__/ |__/|__/ |__/|__/ |__/|__/ |__/|________/|__/ |__/ */ import java.io.BufferedReader; import java.text.DecimalFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.io.IOException; import java.io.InputStreamReader; import java.math.BigInteger; import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import java.io.*; public class abc { static PrintWriter pw; static long x = 1, y = 1; /* * static long inv[]=new long[1000001]; static long dp[]=new long[1000001]; */ /// MAIN FUNCTION/// public static void main(String[] args) throws Exception { FastReader sc = new FastReader(); pw = new PrintWriter(System.out); // use arraylist as it uses the concept of dynamic table(amortized analysis) // Arrays.stream(array).forEach(a -> Arrays.fill(a, 0)); /* List<Integer> l1 = new ArrayList<Integer>(); */ // Random rand = new Random(); int tst = sc.nextInt(); while (tst-- > 0) { int n=sc.nextInt(); int arr[]=new int[n]; int c=0; for(int i=n;i>0;i--) { arr[c++]=i; } int k=n;int x=1; int j=0; while(j<k) { for(int i=n;i>=2;i--) { if(i==x) { // i++; pw.print(1+" "+i+" "); } else pw.print(i+" "); } x=x+1; if(j==0) pw.print(1+" "); j++; pw.println(); } } pw.flush(); } public static int perfectSum(int arr[],int n, int sum) { int dp[][]=new int[n+1][sum+1]; for(int i=0;i<n+1;i++) { for(int j=0;j<sum+1;j++) { if(i==0) dp[i][j]=0; if(j==0) dp[i][j]=1; } } for(int i=1;i<n+1;i++) { for(int j=1;j<sum+1;j++) { if(arr[i-1] <= j) dp[i][j]=dp[i-1][j]+dp[i-1][j-arr[i-1]]; else dp[i][j]=dp[i-1][j]; dp[i][j]=dp[i][j]; } } return dp[n][sum]; } public static long eculidean_gcd(long a, long b) { if (a == 0) { x = 0; y = 1; return b; } long ans = eculidean_gcd(b % a, a); long x1 = x; x = y - (b / a) * x; y = x1; return ans; } public static boolean isLsbOne(int n) { if ((n & 1) != 0) return true; return false; } public static pair helper(int arr[], int start, int end, int k, pair dp[][]) { if (start >= end) { if (start == end) return (new pair(arr[start], 0)); else return (new pair(0, 0)); } if (dp[start][end].x != -1 && dp[start][end].y != -1) { return dp[start][end]; } pair ans = new pair(0, Integer.MAX_VALUE); for (int i = start; i < end; i++) { pair x1 = helper(arr, start, i, k, dp); pair x2 = helper(arr, i + 1, end, k, dp); long tip = k * (x1.x + x2.x) + x1.y + x2.y; if (tip < ans.y) ans = new pair(x1.x + x2.x, tip); } return dp[start][end] = ans; } public static void debugger() { Random rand = new Random(); int tst = (int) (Math.abs(rand.nextInt()) % 2 + 1); pw.println(tst); while (tst-- > 0) { int n = (int) (Math.abs(rand.nextInt()) % 5 + 1); pw.println(n); for (int i = 0; i < n; i++) { pw.print((int) (Math.abs(rand.nextInt()) % 6 + 1) + " "); } pw.println(); } } static int UpperBound(long a[], long x) {// x is the key or target value int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] <= x) l = m; else r = m; } return l + 1; } static int LowerBound(long a[], long x) { // x is the target value or key int l = -1, r = a.length; while (l + 1 < r) { int m = (l + r) >>> 1; if (a[m] >= x) r = m; else l = m; } return r; } static void recursion(int n) { if (n == 1) { pw.print(n + " "); return; } // pw.print(n+" "); gives us n to 1 recursion(n - 1); // pw.print(n+" "); gives us 1 to n } // ch.charAt(i)+"" converts into a char sequence 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } /* CREATED BY ME */ int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } } public static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public static boolean isPrime(long n) { if (n == 2) return true; long i = 2; while (i * i <= n) { if (n % i == 0) return false; i++; } return true; } static int ceil(int x, int y) { return (x % y == 0 ? x / y : (x / y + 1)); } static long ceil(long x, long y) { return (x % y == 0 ? x / y : (x / y + 1)); } static double max(double x, double y) { return Math.max(x, y); } static int min(int x, int y) { return Math.min(x, y); } static int abs(int x) { return Math.abs(x); } static long abs(long x) { return Math.abs(x); } static int log2(int N) { int result = (int) (Math.log(N) / Math.log(2)); return result; } static long max(long x, long y) { return Math.max(x, y); } static long min(long x, long y) { return Math.min(x, y); } public static class pair { long x; long y; public pair(long a, long b) { x = a; y = b; } } public static class Comp implements Comparator<pair> { public int compare(pair a, pair b) { long ans = a.y - b.y; if (ans > 0) return 1; if (ans < 0) return -1; return 0; // if(a.x!=b.x) // return Integer.compare((int)a.x, (int)b.x); // else // return Integer.compare((int)a.y, (int)b.y); } } // modular exponentiation public static long fastExpo(long a, int n, int mod) { if (n == 0) return 1; else { if ((n & 1) == 1) { long x = fastExpo(a, n / 2, mod); return (((a * x) % mod) * x) % mod; } else { long x = fastExpo(a, n / 2, mod); return (((x % mod) * (x % mod)) % mod) % mod; } } } public static long modInverse(long n, int p) { return fastExpo(n, p - 2, p); } /* * public static void extract(ArrayList<Integer> ar, int k, int d) { int c = 0; * for (int i = 1; i < k; i++) { int x = 0; boolean dm = false; while (x > 0) { * long dig = x % 10; x = x / 10; if (dig == d) { dm = true; break; } } if (dm) * ar.add(i); } } */ public static int[] prefixfuntion(String s) { int n = s.length(); int z[] = new int[n]; for (int i = 1; i < n; i++) { int j = z[i - 1]; while (j > 0 && s.charAt(i) != s.charAt(j)) j = z[j - 1]; if (s.charAt(i) == s.charAt(j)) j++; z[i] = j; } return z; } // counts the set(1) bit of a number public static long countSetBitsUtil(long x) { if (x <= 0) return 0; return (x % 2 == 0 ? 0 : 1) + countSetBitsUtil(x / 2); } //tells whether a particular index has which bit of a number public static int getIthBitsUtil(int x, int y) { return (x & (1 << y)) != 0 ? 1 : 0; } public static void swaper(long x, long y) { x = x ^ y; y = y ^ x; x = x ^ y; } public static double decimalPlaces(double sum) { DecimalFormat df = new DecimalFormat("#.00"); String angleFormated = df.format(sum); double fin = Double.parseDouble(angleFormated); return fin; } //use collections.swap for swapping static boolean isSubSequence(String str1, String str2, int m, int n) { int j = 0; for (int i = 0; i < n && j < m; i++) if (str1.charAt(j) == str2.charAt(i)) j++; return (j == m); } static long sum(long n) { long s2 = 0, max = -1, min = 10; while (n > 0) { s2 = (n % 10); min = min(s2, min); max = max(s2, max); n = n / 10; } return max * min; } static long pow(long base, long power) { if (power == 0) { return 1; } long result = pow(base, power / 2); if (power % 2 == 1) { return result * result * base; } return result * result; } // return the hash value of a string static long compute_hash(String s) { long val = 0; long p = 31; long mod = (long) (1000000007); long pow = 1; for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); val = (val + (int) (ch - 'a' + 1) * pow) % mod; pow = (pow * p) % mod; } return val; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
bdfaafda23d7ff579fe3e09c260ecf17
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class A { public static void main (String[] args) throws java.lang.Exception { Scanner scn = new Scanner(System.in); int t=scn.nextInt(); while(t-->0) { int N=scn.nextInt(); int[] A=new int[N]; for(int i=0;i<N;i++) { A[i]=N-i; } int k=N; if(N==3) { System.out.println(3+" "+2+" "+1); System.out.println(2+" "+3+" "+1); System.out.println(1+" "+3+" "+2); } else { while(k-->0) { int first=A[0]; int last=A[N-1]; for(int i=N-1;i>0;i--) { A[i]=A[i-1]; } A[0]=last; A[1]=first; for(int j=0;j<N;j++) { System.out.print(A[j]+" "); } System.out.println(); } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
6319e800c559a3943da731e7e3812d60
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import javax.management.Query; import java.io.*; import java.math.BigInteger; public class Contest1 { public static void main(String[] args) throws Exception { Scanner sc=new Scanner(System.in); int t1=sc.nextInt(); while(t1-->0) { int n=sc.nextInt(); String s1="3 1 2 "; String s2="3 2 1 "; String s3="2 3 1 "; String s=""; String t=""; if(n==3) { pw.println(s1); pw.println(s2); pw.println(s3); continue; } int i1=0; for (int i = 0; i <n; i++) { for (int j = n-i1; j>3; j--) { s=s+j+" "; } t=s+s1; for (int j = n; j >n-i1; j--) { t=t+j+" "; } pw.println(t); i++; if(i<n) { t=s+s2; for (int j = n; j >n-i1; j--) { t=t+j+" "; } pw.println(t); } i++; if(i<n) { t=s+s3; for (int j = n; j >n-i1; j--) { t=t+j+" "; } pw.println(t); } s=""; t="";i1++; } } pw.close(); } //static int n; //static int w; //static int[] weight; //static int[] val; //static long[][] memo; // public static long dp(int idx,int rem) { // if(idx==n) // return 0; // if(memo[idx][rem]!=-1) // return memo[idx][rem]; // long res=dp(idx+1,rem); // if(weight[idx]<=rem) // res=Math.max(res, val[idx]+dp(idx+1,rem-weight[idx])); // return memo[idx][rem]= res; // } public static double ceil(Long n, Long m) { if(n%m==0) return n/m; else return n/m +1; } public static int gcd(int a, int b) { if(b==0) return a; else return gcd(b,a%b); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader r) { br = new BufferedReader(r); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if (x.charAt(0) == '-') { neg = true; start++; } for (int i = start; i < x.length(); i++) if (x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if (dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg ? -1 : 1); } public long[] nextlongArray(int n) throws IOException { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public Long[] nextLongArray(int n) throws IOException { Long[] a = new Long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } public int[] nextIntArray(int n) throws IOException { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public Integer[] nextIntegerArray(int n) throws IOException { Integer[] a = new Integer[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public boolean ready() throws IOException { return br.ready(); } } static class pair implements Comparable<pair> { long x; long y; public pair(long x, long y) { this.x = x; this.y = y; } public String toString() { return x + " " + y; } public boolean equals(Object o) { if (o instanceof pair) { pair p = (pair) o; return p.x == x && p.y == y; } return false; } public int hashCode() { return new Long(x).hashCode() * 31 + new Long(y).hashCode(); } public int compareTo(pair other) { if (this.x == other.x) { return Long.compare(this.y, other.y); } return Long.compare(this.x, other.x); } } static class tuble implements Comparable<tuble> { int x; int y; int z; public tuble(int x, int y, int z) { this.x = x; this.y = y; this.z = z; } public String toString() { return x + " " + y + " " + z; } public int compareTo(tuble other) { if (this.x == other.x) { if (this.y == other.y) { return this.z - other.z; } return this.y - other.y; } else { return this.x - other.x; } } } static long mod = 1000000007; static Random rn = new Random(); static Scanner sc = new Scanner(System.in); static PrintWriter pw = new PrintWriter(System.out); }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
555911d2949244539f18f5a402962fd9
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Ashutosh Patel (ashutoshpatelnoida@gmail.com) Linkedin : ( https://www.linkedin.com/in/ashutosh-patel-7954651ab/ ) */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); BAntiFibonacciPermutation solver = new BAntiFibonacciPermutation(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class BAntiFibonacciPermutation { public void solve(int testNumber, InputReader sc, OutputWriter out) { int n = sc.readInt(); if (n == 3) { out.printLine("3 2 1\n" + "1 3 2\n" + "3 1 2"); return; } int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = i + 1; } arr[1] = 3; arr[2] = 2; int left = 0; int temp = n; while (temp-- > 0) { for (int i = left; i < n; i++) { out.print(arr[i] + " "); } for (int i = 0; i < left; i++) { out.print(arr[i] + " "); } left++; out.printLine(); } } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void printLine() { writer.println(); } public void printLine(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int read() { if (numChars == -1) { throw new InputMismatchException(); } if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) { return -1; } } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) { res.appendCodePoint(c); } c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) { return filter.isSpaceChar(c); } return isWhitespace(c); } public String next() { return readString(); } public interface SpaceCharFilter { boolean isSpaceChar(int ch); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
d46e20d6aa0ba6b445c108973277af9e
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Main { static class pair { long r; long d; public pair(long r , long d) { this.r= r; this.d= d; } } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main (String[] args) throws java.lang.Exception { OutputStream outputStream =System.out; PrintWriter out =new PrintWriter(outputStream); FastReader sc =new FastReader(); int t = sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int k =1; int i = 0; if(n==3){ out.println("3 2 1\n1 3 2\n3 1 2"); continue; } while(k++<=n){ int x = i; // if(x>=3) //{ // out.print("1 3 2 "); // x-=3; //} while(x>0) out.print(x--+" "); for(int j =n;j>i;j--) out.print(j+" "); i++; out.println(); } // out.println(); } out.close(); // your code goes here } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
a2faa38db6916b32c85961e4df76395f
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
// package CF.EDU123; import java.io.*; import java.util.*; import java.math.*; /** * @Author: merickbao * @Created_Time: 2022-02-22 21:28 * @Description: Educational Codeforces Round 123 (Rated for Div. 2) */ public class Main { public static void main(String[] args) throws IOException { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); // code here Task solver = new B(); solver.solve(1, in, out); out.close(); } } class B implements Task { int cnt = 0; boolean[] seen = new boolean[100]; HashSet<String> all = new HashSet<>(); @Override public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.readInt(); while (t-- > 0) { int n = in.readInt(); if (n == 3) { System.out.println("3 2 1"); System.out.println("1 3 2"); System.out.println("3 1 2"); } else { cnt = 0; all.clear(); Arrays.fill(seen, false); for (int i = 1; i <= n; i++) { seen[i] = true; for (int j = i; j <= n; j++) { if (i == j) continue; seen[j] = true; List<Integer> now = new ArrayList<Integer>(); now.add(i); now.add(j); dfs(n, now); seen[j] = false; } seen[i] = false; } } } } public void dfs(int n, List<Integer> now) { if (now.size() == n) { StringBuilder sb = new StringBuilder(); for (int i : now) { sb.append(i).append("+"); } if (!all.contains(sb.toString())) { all.add(sb.toString()); cnt++; for (int i : now) System.out.print(i + " "); System.out.println(); } return; } for (int i = 1; i <= n; i++) { if (seen[i]) continue; if (now.get(now.size() - 1) + now.get(now.size() - 2) != i && cnt < n) { seen[i] = true; now.add(i); dfs(n, now); now.remove(now.size() - 1); seen[i] = false; } } } } class A implements Task { @Override public void solve(int testNumber, InputReader in, OutputWriter out) { int t = in.readInt(); while (t-- > 0) { String s = in.readString(); int flag = 0; boolean ok = true; for (int i = 0; i < s.length(); i++) { if ("RGB".indexOf(s.charAt(i) + "") >= 0) { if (((flag >> (s.charAt(i) - 'A')) & 1) == 0) { ok = false; break; } } else { flag |= (1 << (s.charAt(i) - 'a')); } } System.out.println(ok ? "YES" : "NO"); } } } interface Task { public void solve(int testNumber, InputReader in, OutputWriter out); } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int peek() { if (numChars == -1) return -1; if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { return -1; } if (numChars <= 0) return -1; } return buf[curChar]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long readLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { if (Character.isValidCodePoint(c)) res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private String readLine0() { StringBuilder buf = new StringBuilder(); int c = read(); while (c != '\n' && c != -1) { if (c != '\r') buf.appendCodePoint(c); c = read(); } return buf.toString(); } public String readLine() { String s = readLine0(); while (s.trim().length() == 0) s = readLine0(); return s; } public String readLine(boolean ignoreEmptyLines) { if (ignoreEmptyLines) return readLine(); else return readLine0(); } public BigInteger readBigInteger() { try { return new BigInteger(readString()); } catch (NumberFormatException e) { throw new InputMismatchException(); } } public char readCharacter() { int c = read(); while (isSpaceChar(c)) c = read(); return (char) c; } public double readDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, readInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public boolean isExhausted() { int value; while (isSpaceChar(value = peek()) && value != -1) read(); return value == -1; } public String next() { return readString(); } public InputReader.SpaceCharFilter getFilter() { return filter; } public void setFilter(InputReader.SpaceCharFilter filter) { this.filter = filter; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(char[] array) { writer.print(array); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) writer.print(' '); writer.print(objects[i]); } } public void print(int[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) writer.print(' '); writer.print(array[i]); } } public void print(long[] array) { for (int i = 0; i < array.length; i++) { if (i != 0) writer.print(' '); writer.print(array[i]); } } public void printLine(int[] array) { print(array); writer.println(); } public void printLine(long[] array) { print(array); writer.println(); } public void printLine() { writer.println(); } public void printLine(Object... objects) { print(objects); writer.println(); } public void print(char i) { writer.print(i); } public void printLine(char i) { writer.println(i); } public void printLine(char[] array) { writer.println(array); } public void printFormat(String format, Object... objects) { writer.printf(format, objects); } public void close() { writer.close(); } public void flush() { writer.flush(); } public void print(long i) { writer.print(i); } public void printLine(long i) { writer.println(i); } public void print(int i) { writer.print(i); } public void printLine(int i) { writer.println(i); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
174d51d5bb68bdcd07303a08d4a9b1c7
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
//package com.company; import java.util.*; import java.lang.*; import java.io.*; public class Rough_Work { public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t = sc.nextInt(); while (t-->0) { int n = sc.nextInt(); if (n == 3) { out.println("3 2 1\n3 1 2\n1 3 2"); continue; } ArrayList<Integer> x = new ArrayList<>(); for (int i = n; i > 0; i--) x.add(i); for (int i = n; i > 0; i--) { for (int z: x)out.print(z+" "); out.println(); x.remove(0); x.add(i); } } sc.close(); out.close(); } static class FastReader { final private int BUFFER_SIZE = 1 << 17; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public FastReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastReader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[128]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } public int[] nextIntArray(int size) throws IOException { int[] arr = new int[size]; for (int i = 0; i < size; i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int size) throws IOException { long[] arr = new long[size]; for (int i = 0; i < size; i++) { arr[i] = nextLong(); } return arr; } public Double[] nextDoubleArray(int size) throws IOException { Double[] arr = new Double[size]; for (int i = 0; i < size; i++) { arr[i] = nextDouble(); } return arr; } public int[][] nextIntMatrix(int n, int m) throws IOException { int[][] arr = new int[n][m]; for (int i = 0; i < n; i++) { arr[i] = nextIntArray(m); } return arr; } public long[][] nextLongMatrix(int n, int m) throws IOException { long[][] arr = new long[n][m]; for (int i = 0; i < n; i++) { arr[i] = nextLongArray(m); } return arr; } public ArrayList<Integer> nextIntList(int size) throws IOException { ArrayList<Integer> arrayList = new ArrayList<>(size); for (int i = 0; i < size; i++) { arrayList.add(nextInt()); } return arrayList; } public ArrayList<Long> nextLongList(int size) throws IOException { ArrayList<Long> arrayList = new ArrayList<>(size); for (int i = 0; i < size; i++) { arrayList.add(nextLong()); } return arrayList; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
27ebd1ab1802d1e88926a215e5ef9c7c
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.math.*; import java.io.*; public class Main { static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } public static void main(String[] args) { try { FastReader in=new FastReader(); FastWriter out = new FastWriter(); int testCases=in.nextInt(); int l = 100000; ArrayList<Integer> primes = prime(l); while(testCases-- > 0){ int n = in.nextInt(); int j = n-1; ArrayList<Integer> ans = new ArrayList<>(); while ( n > 0) { ans.add(n); n--; } print(ans); while ( j >= 1) { swap(ans , j , j-1); print(ans); j--; } } out.close(); } catch (Exception e) { return; } } public static void print(ArrayList<Integer> arr ) { for ( int i=0;i<arr.size();i++) System.out.print(arr.get(i) + " "); System.out.println(); } public static String sortString(String inputString){ char tempArray[] = inputString.toCharArray(); Arrays.sort(tempArray); return new String(tempArray); } private static void reverse( ArrayList<Integer> arr , int i, int j ) { while ( i <= j ) { swap(arr,i,j); i++;j--; } } private static void swap( ArrayList<Integer> arr , int i, int j ) { int temp = arr.get(i); arr.set(i,arr.get(j)); arr.set(j,temp); } private static void rangePrime( int l , int r ) { int n = (int) Math.sqrt(r); ArrayList<Integer> prime = prime(n); int dummy[] = new int[r-l+1]; for (int i=0;i<r-l+1;i++) dummy[i] = 1; for ( int p : prime ) { int firstMultiple = (l/p)*p; if ( firstMultiple < l ) firstMultiple+=p; for ( int j=Math.max(firstMultiple, p*p);j<=r;j+=p) { dummy[j-l] = 0; } for ( int i=l;i<=r;i++) { if ( dummy[i-l] == 1 ) { System.out.println(i); } } } } private static boolean isPalindrome(String s ) { int i=0,j=s.length()-1; while ( i <= j ) { if ( s.charAt(i) != s.charAt(j) ) { return false; } i++;j--; } return true; } private static boolean isPrime(long n ) { if ( n == 1 ) return true; for ( int i=2;i<=Math.sqrt(n);i++) { if ( n % i == 0 ) { return false ; } } return true; } private static boolean[] seive(){ int n = 1000000; boolean prime[] = new boolean[n+1]; Arrays.fill(prime, true); for ( int i=2;i*i<=n;i++) { for ( int j=i*i;j<=n;j+=i) { prime[j] = false; } } return prime; } private static ArrayList<Integer> prime(int n ) { ArrayList<Integer> prime = new ArrayList<>(); boolean seive[] = seive(); for ( int i=2;i<=n;i++) { if ( seive[i] == true ) { prime.add(i); } } return prime; } private static int GCD( int a,int b) { if ( b == 0 ) return a; return GCD(b,a%b); } private static long power( long a , long b ) { long ans = 1; while ( b > 0 ) { if ( (b&1) != 0 ) { ans = binMultiply(ans,a); } a = binMultiply(a,a ); b >>=1; } return ans; } private static long binMultiply(long a , long b ) { long ans = 0; while ( b > 0 ) { if ( (b&1) != 0 ) { ans = (ans + a ); // if m is given in ques than use ans = ans+a % m ; } a = (a+a); // if m is given in ques than use a = (a+a)%m; b >>=1; } return ans; } private static int[] primeFactors() { int n = 1000000; int prime[] = new int[n+1]; for(int i=1;i<=n;i++) { prime[i] = i; } for (int i=2;i*i<=n;i++) { if ( prime[i] == i ) { for (int j=i*i;j<=n;j+=i) { if ( prime[j] == j ) { prime[j] = i; } } } } return prime; } private static int binarySearch(int l , int r , int[] arr , int find ) { int mid = l + (r-l)/2; if ( arr[mid] == find ) { return mid; }else if ( arr[mid] > find ) { return binarySearch(l,mid-1,arr,find); } return binarySearch(mid+1,r,arr,find); } private static int upper_bound(ArrayList<Integer> arr , int element ) { int l = 0 ; int h = arr.size(); int mid = 0; while ( h-l > 0 ) { mid = l + (h-l)/2; if ( arr.get(mid) <= element ) { l = mid+1; }else { h = mid ; } } if ( arr.get(l) > element ) return l; if ( arr.get(h) > element ) return h; return -1; } private static int lower_bound(ArrayList<Integer> arr , int element ) { int l = 0 ; int h = arr.size(); int mid = 0; while ( h-l > 0 ) { mid = l + (h-l)/2; if ( arr.get(mid) < element ) { l = mid+1; }else { h = mid ; } } if ( arr.get(l) >= element ) return l; if ( arr.get(h) >= element ) return h; return -1; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
bb034053d7ee532b67d82e7246c1b9ab
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; import java.lang.*; public class Main{ public static void swap(int i, int j, int [] arr) { int temp = arr[i]; arr[i] = arr[j]; arr[j] =temp; } public static void print(int [] arr) { for (int i = 0; i < arr.length; i++) System.out.print(arr[i]+" "); System.out.println(); } public static void main(String [] args) throws IOException { Scanner sc = new Scanner(System.in); int test = sc.nextInt(); while(test-->0) { int n = sc.nextInt(); int [] arr = new int[n]; for(int i = n; i >0; i--) { arr[n-i] = i; System.out.print(i+" "); } System.out.println(); int k = n-1, l = n-2; for(int i = 0; i < n-1; i++) { swap(k--, l--, arr); print(arr); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
51d354b1b1dbd66b4bf027a7a85d6d45
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; import java.util.concurrent.CountDownLatch; public class B { public static void main(String[] args) throws IOException { // int N = 100010; // long[] a = new long[N]; in.nextToken(); int t = (int) in.nval; while (t-- > 0) { in.nextToken(); int n = (int) in.nval; int[] a = new int[n + 1]; int idx = 1; for (int i = n; i >= 1; i--) a[idx++] = i; int cot = 0; con1: for (int i = 1; i <= n; i++) { swap(a, i, n); for (int i1 = 3; i1 <= n; i1++) { if (a[i1] == a[i1 - 1] + a[i1 - 2]) { swap(a, i, n); continue con1; } } for (int j = 1; j <= n; j++) { out.print(a[j] + " "); } out.println(); cot++; swap(a, i, n); if (cot >= n) break; } if (cot < n) { con2: for (int i = 1; i < n - 1; i++) { swap(a, i, n - 1); for (int i1 = 3; i1 <= n; i1++) { if (a[i1] == a[i1 - 1] + a[i1 - 2]) { swap(a, i, n); continue con2; } } for (int j = 1; j <= n; j++) { out.print(a[j] + " "); } out.println(); cot++; swap(a, i, n - 1); if (cot >= n) break; } } } out.flush(); out.close(); } private static void swap(int[] a, int i, int n) { int temp = a[i]; a[i] = a[n]; a[n] = temp; } // static Scanner in = new Scanner(System.in); // static BufferedReader in = new BufferedReader(new // InputStreamReader(System.in)); static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
346f390a0f0d5096cd4f185740605b40
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; //import java.util.HashMap; import java.util.*; public class C { static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static Scanner scn = new Scanner(System.in); public static void main(String[] args) throws Exception { int t = Integer.parseInt(br.readLine()); while (t-- > 0) { ArrayList<Integer> list = new ArrayList<>(); int n = Integer.parseInt(br.readLine()); for (int i = 0; i < n; i++) { list.add(i + 1); } Collections.reverse(list); if (n % 2 == 0) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { // System.out.println(list.get(0) + " " + list.get(1) + " " + list.get(2) + " " // + list.get(3)); System.out.print(list.get(j) + " "); } System.out.println(); int val = list.remove(0); list.add(val); } }else { for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { System.out.print(list.get(j) + " "); } System.out.println(); if(i == n - 1) { continue; }else { swap(n-i - 1,n-i-2, list); } } } } } public static void swap(int i, int j, ArrayList<Integer> list) { int temp = list.get(i); list.set(i, list.get(j)); list.set(j, temp); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
fb21a1507dd8763c04232f9fc79588c5
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
//package Competitve1; //package compete; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.lang.reflect.Array; import java.nio.MappedByteBuffer; //import java.security.acl.LastOwnerException; import java.util.*; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Deque; import java.util.HashMap; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Main { public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String[] nextSArray() { String sr[] = null; try { sr = br.readLine().trim().split(" "); } catch (IOException e) { e.printStackTrace(); } return sr; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } static int root[],size[],tree[],arr[]; static int mod=998244353; static int maxDepth=0; public static void main(String[] args) throws Exception{ FastReader sc=new FastReader(); int t=sc.nextInt(); //int t=1; while(t-->0) { solve(sc); } out.close(); } static long l,r; static long count=0l; static int N; static long dp[]; static int gmex[]; static void solve(FastReader sc) { int n=sc.nextInt(); if(n==3) { out.println("3 2 1"); out.println("2 3 1"); out.println("1 3 2"); return; } for(int i=0;i<n;i++) { for(int j=n-i,k=0;k<n;k++,j--) { int p=j<=0?(j+n):j; out.print(p+" "); } out.println(); } } static boolean isSorted(long arr[]) { for(int i=1;i<arr.length;i++) if(arr[i]<arr[i-1]) return false; return true; } static int find(int a,int b) { int mask=0; for(int i=0;i<32;i++) { int p=1<<i; if((a&p)!=0) mask|=p; if(mask>=b) { return mask; } } return a; } static String reverse(String a){ return new StringBuilder(a).reverse().toString(); } static int bs(ArrayList<Integer> arr,int k) { int lo=0,hi=arr.size()-1,res=hi+1; while(lo<=hi) { int m=lo+(hi-lo)/2; if(arr.get(m)>=k) { res=m; hi=m-1; }else lo=m+1; } return res; } static boolean check(long m, long arr[],long sum) { int l=arr.length; int start=(l-1)/2; long op=m*l-sum; if(arr[start]<=m) op-=(m-arr[start]); else return false; for(int i=start+1;i<l;i++) { if(m>=arr[i]) op-=(m-arr[i]); } return op>=0?true:false; } static long bit(long num,long i,long len) { if(i==len/2+1) return num%2; if(i<=len/2) return bit(num/2,i,len/2); else return bit(num/2,i-len/2-1,len/2); } static long f(long n) { if(n==1 || n==0) return 1; return 2*f(n/2)+1; } static void ftree(int n) { tree=new int[n+1]; } static int query(int r) { int ans=0; r+=1; while(r>0) { ans= (ans%mod + tree[r]%mod)%mod; r-=(r & -r); } return ans; } static void update(int i,int n) { i+=1; while(i<tree.length) { tree[i]= (tree[i]%mod + n%mod)%mod; i+= (i & -i); } } static void dsu(int n) { root=new int[n+1]; size=new int[n+1]; Arrays.fill(size, 1); for(int i=0;i<=n;i++) root[i]=i; } static int find_root(int i) { while(root[i]!=i) { root[i]=root[root[i]]; i=root[i]; } return i; } static void union(int a,int b) { int ra=find_root(a); int rb=find_root(b); if(ra==rb) return; if(size[ra]>size[rb]) { size[ra]+=size[rb]; root[rb]=ra; }else { size[rb]+=size[ra]; root[ra]=rb; } } static int bs(int arr[],int i, int j,int a,int b) { int lo=i,hi=j,index=lo; while(lo<=hi) { int m=lo+(hi-lo)/2; if(check(arr,m,a,b)) { index=m; lo=m+1; } else { hi=m-1; } } return arr[index]; } static boolean check(int arr[],int m,int a,int b) { if(m==0) return true; long x=(long)(arr[m]-a)*(long)(b-arr[m]),y=(long)(arr[m-1]-a)*(long)(b-arr[m-1]); return x>y; } static long pow(long a,long n) { if(n==0l) return 1l; long curr=pow(a,n/2)%mod; if(n%2l==0l) return (curr*curr)%mod; else return (((curr*a)%mod)*curr)%mod; } static void stree(int n,int[] arr) { tree=new int[4*n]; maketree(arr,0,arr.length-1,1); } static int maketree(int[] arr,int st, int en,int root) { if(st==en) { tree[root]=arr[st]; return arr[st]; } int m=st+(en-st)/2; int left=maketree(arr,st,m,root*2); int right=maketree(arr,m+1,en,root*2+1); tree[root]=left+right; return tree[root]; } static int update(int lq,int rq,int l,int r,int root,int val) { if(l==r) { tree[root]=val; arr[l]=val; return tree[root]; } else if(lq>r || rq<l) return 0; int m=l+(r-l)/2; tree[root]= update(lq,rq,l,m,root*2,val)+update(lq,rq,m+1,r,root*2+1,val); return tree[root]; } static void update(int i,int l,int r,int root,int val) { if(l==r) { tree[root]=val; arr[i]=val; return; } int m=l+(r-l)/2; if(i<=m) update(i,l,m,root*2,val); else update(i,m+1,r,root*2+1,val); tree[root]=tree[root*2]+tree[root*2+1]; } static int query(int lq,int rq,int l,int r,int root) { if(lq>r || rq<l) return 0; if(lq<=l && rq>=r) return tree[root]; int m=l+(r-l)/2; return query(lq,rq,l,m,root*2)+query(lq,rq,m+1,r,root*2+1); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
d49ac5d8d26787b19f898d7ad3212a5f
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class B { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int N = sc.nextInt(); for (int i = 0; i < N; i++) { if (N == 3 && i == 2) { System.out.print("3 1 2"); } else { for (int j = i; j > 0; j--) { System.out.print(j + " "); } for (int j = N; j > i; j--) { System.out.print(j + " "); } } System.out.println(); } } sc.close(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
ff6551903b6ebc57e1b4e23785291bbf
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.util.stream.Collectors; import java.io.*; import java.math.*; public class A_Temp4 { public static FastScanner sc; public static PrintWriter pw; public static StringBuilder sb; public static int MOD= 1000000007; public static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } public static void printList(List<Long> al) { System.out.println(al.stream().map(it -> it.toString()).collect(Collectors.joining(" "))); } public static void printList(Deque<Long> al) { System.out.println(al.stream().map(it -> it.toString()).collect(Collectors.joining(" "))); } public static void printArr(long[] arr) { System.out.println(Arrays.toString(arr).trim().replace("[", "").replace("]","").replace(","," ")); } public static void printArr(int[] arr) { System.out.println(Arrays.toString(arr).trim().replace("[", "").replace("]","").replace(","," ")); } public static long gcd(long a, long b) { if(b==0) return a; return gcd(b,a%b); } public static long lcm(long a, long b) { return((a*b)/gcd(a,b)); } public static void decreasingOrder(ArrayList<Long> al) { Comparator<Long> c = Collections.reverseOrder(); Collections.sort(al,c); } public static boolean[] sieve(int n) { boolean isPrime[] = new boolean[n+1]; Arrays.fill(isPrime, true); isPrime[0]=false; isPrime[1]=false; for(int i=2;i*i<n;i++) { for(int j=2*i;j<n;j+=i) { isPrime[j]=false; } } return isPrime; } public static long nCr(long N, long R) { double result=1; for(int i=1;i<=R;i++) result=((result*(N-R+i))/i); return (long) result; } public static long fastPow(long a, long b, int n) { long result=1; while(b>0) { if((b&1)==1) result=(result*a %n)%n; a=(a%n * a%n)%n; b>>=1; } return result; } public static int BinarySearch(long[] arr, long key) { int low=0; int high=arr.length-1; while(low<=high) { int mid=(low+high)/2; if(arr[mid]==key) return mid; else if(arr[mid]>key) high=mid-1; else low=mid+1; } return low; //High=low-1 } public static int upperBound(int[] arr, int target, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid]<=target) l=mid+1; else r=mid-1; } return l; } public static int lowerBound(int[] arr, int target, int l, int r) { while(l<=r) { int mid=(l+r)/2; if(arr[mid]<target) l=mid+1; else r=mid-1; } return l; } public static void solve(int t) { int n=sc.nextInt(); if(n==3) { sb.append(3+" "+2+" "+1); sb.append('\n'); sb.append(1+" "+3+" "+2); sb.append('\n'); sb.append(3+" "+1+" "+2); sb.append('\n'); return; } for(int i=n;i>=1;i--) { sb.append(i+" "); } sb.append('\n'); int[] arr = new int[n]; arr[n-1]=1; for(int i=0;i<n-1;i++) arr[i]=i+2; // printArr(arr); // System.out.println("temp"); for(int i=1;i<=n-1;i++) { for(int j=0;j<n;j++) { sb.append(arr[j]+" "); } sb.append('\n'); int temp=arr[n-2]; int temp2=arr[0]; for(int k=1;k<=n-2;k++) { int temp3=arr[k]; arr[k]=temp2; temp2=temp3; } arr[0]=temp; } } public static void main(String[] args) { sc = new FastScanner(); pw = new PrintWriter(new OutputStreamWriter(System.out)); sb= new StringBuilder(""); int t=sc.nextInt(); for(int i=1;i<=t;i++) solve(i); System.out.println(sb); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
75c804f591f08506f18aba8adffc322c
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; //import java.math.BigInteger; public class code{ public static class Pair{ int a; int b; Pair(int i,int j){ a=i; b=j; } } public static int GCD(int a, int b) { if (b == 0) return a; return GCD(b, a % b); } public static void shuffle(int a[], int n) { for (int i = 0; i < n; i++) { // getting the random index int t = (int)Math.random() * a.length; // and swapping values a random index // with the current index int x = a[t]; a[t] = a[i]; a[i] = x; } } public static PrintWriter out = new PrintWriter(System.out); //public static long mod=(long)(1e9+7); //@SuppressWarnings("unchecked") public static void main(String[] arg) throws IOException{ //Reader in=new Reader(); //PrintWriter out = new PrintWriter(System.out); //Scanner in = new Scanner(System.in); FastScanner in=new FastScanner(); int t=in.nextInt(); while(t-- > 0){ int n=in.nextInt(); int[] arr=new int[n]; int k=n; for(int i=0;i<n;i++) { arr[i]=k; k--; } int pos=n-1; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ out.print(arr[j]+" "); } out.println(); if(i==n-1) break; int temp=arr[pos]; arr[pos]=arr[pos-1]; arr[pos-1]=temp; pos--; } } out.flush(); } } class Fenwick{ int[] bit; public Fenwick(int n){ bit=new int[n]; //int sum=0; } public void update(int index,int val){ index++; for(;index<bit.length;index += index&(-index)) bit[index]+=val; } public int presum(int index){ int sum=0; for(;index>0;index-=index&(-index)) sum+=bit[index]; return sum; } public int sum(int l,int r){ return presum(r+1)-presum(l); } } class FastScanner { private int BS = 1 << 16; private char NC = (char) 0; private byte[] buf = new byte[BS]; private int bId = 0, size = 0; private char c = NC; private double cnt = 1; private BufferedInputStream in; public FastScanner() { in = new BufferedInputStream(System.in, BS); } public FastScanner(String s) { try { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } catch (Exception e) { in = new BufferedInputStream(System.in, BS); } } private char getChar() { while (bId == size) { try { size = in.read(buf); } catch (Exception e) { return NC; } if (size == -1) return NC; bId = 0; } return (char) buf[bId++]; } public int nextInt() { return (int) nextLong(); } public int[] nextInts(int N) { int[] res = new int[N]; for (int i = 0; i < N; i++) { res[i] = (int) nextLong(); } return res; } public long[] nextLongs(int N) { long[] res = new long[N]; for (int i = 0; i < N; i++) { res[i] = nextLong(); } return res; } public long nextLong() { cnt = 1; boolean neg = false; if (c == NC) c = getChar(); for (; (c < '0' || c > '9'); c = getChar()) { if (c == '-') neg = true; } long res = 0; for (; c >= '0' && c <= '9'; c = getChar()) { res = (res << 3) + (res << 1) + c - '0'; cnt *= 10; } return neg ? -res : res; } public double nextDouble() { double cur = nextLong(); return c != '.' ? cur : cur + nextLong() / cnt; } public double[] nextDoubles(int N) { double[] res = new double[N]; for (int i = 0; i < N; i++) { res[i] = nextDouble(); } return res; } public String next() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c > 32) { res.append(c); c = getChar(); } return res.toString(); } public String nextLine() { StringBuilder res = new StringBuilder(); while (c <= 32) c = getChar(); while (c != '\n') { res.append(c); c = getChar(); } return res.toString(); } public boolean hasNext() { if (c > 32) return true; while (true) { c = getChar(); if (c == NC) return false; else if (c > 32) return true; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
fbb25cea792a1589cb8dd342feae9cb7
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); static int N = 100010, M = N, INF = Integer.MAX_VALUE; static int MOD = (int)1e9 + 7; static double EPS = 1e-7; static int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; static int h[] = new int[N], to[] = new int[M], ne[] = new int[M], w[] = new int[M], idx; static boolean st[] = new boolean[N]; static InputReader sc = new InputReader(); static int a[] = new int[N]; static int n, m; static void add(int a, int b) { to[idx] = b; ne[idx] = h[a]; h[a] = idx ++ ; } static void solve() { int n = sc.nextInt(); if(n == 3) { System.out.println("3 2 1"); System.out.println("1 3 2"); System.out.println("3 1 2"); return; } int a[] = new int[n]; for(int i = 0, j = n; i < n; i ++ ) a[i] = j -- ; int cnt = 0; for(int i = 0; i < n; i ++ ) { for(int j = i + 1; j < n&& cnt < n; j ++ ) { if(i == j) continue; int t = a[i]; a[i] = a[j]; a[j] = t; boolean is = true; for(int k = 2; k < n; k ++ ) if(a[k] == a[k - 1] + a[k - 2]) { is = false; break; } if(is) { cnt ++ ; for(int k = 0; k < n; k ++ ) System.out.print(a[k] + " "); System.out.println(); } t = a[i]; a[i] = a[j]; a[j] = t; } } } public static void main(String[] args) throws IOException { int T = sc.nextInt(); while(T -- > 0) { solve(); } } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static int lcm(int a, int b) { return (a * b) / gcd(a, b); } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader() { reader = new BufferedReader(new InputStreamReader(System.in), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
717d05e39a8681060141e7f2fbd58861
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int T=sc.nextInt(); while(T-->0) { int n=sc.nextInt(); int[] a=new int[n]; for(int i=n,j=0;i>0;i--,j++) { a[j]=i; System.out.print(a[j]+" "); } System.out.println(); func(a,n); } sc.close(); } private static void func(int[] a,int n) { for(int i=n-1;i>0;i--) { int temp=a[i]; a[i]=a[i-1]; a[i-1]=temp; for(int j=0;j<a.length;j++) System.out.print(a[j]+" "); System.out.println(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
9ed1ce7253a3a8a4439b83b1bbc11668
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; import java.math.BigDecimal; import java.math.*; public class Main{ public static void main(String[] args) { TaskA solver = new TaskA(); // boolean[]prime=seive(3*100001); int t = in.nextInt(); for (int i = 1; i <= t ; i++) { solver.solve(1, in, out); } // solver.solve(1, in, out); out.flush(); out.close(); } static class TaskA { public void solve(int testNumber, InputReader in, PrintWriter out) { int n= in.nextInt(); for(int i=1;i<=n;i++) { StringBuilder sb=new StringBuilder(); for(int j=1;j<=n;j++) { if(i==j) { sb.append(1+" "); } else if(j>i) { sb.append((n+2-j)+" "); } else { sb.append((n+1-j)+" "); } } println(sb.toString()); } } } static long ceil(long a,long b) { return (a/b + Math.min(a%b, 1)); } static char[] rev(char[]ans,int n) { for(int i=ans.length-1;i>=n;i--) { ans[i]=ans[ans.length-i-1]; } return ans; } static int countStep(int[]arr,long sum,int k,int count1) { int count=count1; int index=arr.length-1; while(sum>k&&index>0) { sum-=(arr[index]-arr[0]); count++; if(sum<=k) { break; } index--; // println("c"); } if(sum<=k) { return count; } else { return Integer.MAX_VALUE; } } static long pow(long b, long e) { long ans = 1; while (e > 0) { if (e % 2 == 1) ans = ans * b % mod; e >>= 1; b = b * b % mod; } return ans; } static void sortDiff(Pair arr[]) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if(p1.first==p2.first) { return (p1.second-p1.first)-(p2.second-p1.first); } return (p1.second-p1.first)-(p2.second-p2.first); } }); } static void sortF(Pair arr[]) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { if(p1.first==p2.first) { return p1.second-p2.second; } return p1.first - p2.first; } }); } static int[] shift (int[]inp,int i,int j){ int[]arr=new int[j-i+1]; int n=j-i+1; for(int k=i;k<=j;k++) { arr[(k-i+1)%n]=inp[k]; } for(int k=0;k<n;k++ ) { inp[k+i]=arr[k]; } return inp; } static long[] fac; static long mod = (long) 1000000007; static void initFac(long n) { fac = new long[(int)n + 1]; fac[0] = 1; for (int i = 1; i <= n; i++) { fac[i] = (fac[i - 1] * i) % mod; } } static long nck(int n, int k) { if (n < k) return 0; long den = inv((int) (fac[k] * fac[n - k] % mod)); return fac[n] * den % mod; } static long inv(long x) { return pow(x, mod - 2); } static void sort(int[] a) { ArrayList<Integer> q = new ArrayList<>(); for (int i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } static void sort(long[] a) { ArrayList<Long> q = new ArrayList<>(); for (long i : a) q.add(i); Collections.sort(q); for (int i = 0; i < a.length; i++) a[i] = q.get(i); } public static int bfsSize(int source,LinkedList<Integer>[]a,boolean[]visited) { Queue<Integer>q=new LinkedList<>(); q.add(source); visited[source]=true; int distance=0; while(!q.isEmpty()) { int curr=q.poll(); distance++; for(int neighbour:a[curr]) { if(!visited[neighbour]) { visited[neighbour]=true; q.add(neighbour); } } } return distance; } public static Set<Integer>factors(int n){ Set<Integer>ans=new HashSet<>(); ans.add(1); for(int i=2;i*i<=n;i++) { if(n%i==0) { ans.add(i); ans.add(n/i); } } return ans; } public static int bfsSp(int source,int destination,ArrayList<Integer>[]a) { boolean[]visited=new boolean[a.length]; int[]parent=new int[a.length]; Queue<Integer>q=new LinkedList<>(); int distance=0; q.add(source); visited[source]=true; parent[source]=-1; while(!q.isEmpty()) { int curr=q.poll(); if(curr==destination) { break; } for(int neighbour:a[curr]) { if(neighbour!=-1&&!visited[neighbour]) { visited[neighbour]=true; q.add(neighbour); parent[neighbour]=curr; } } } int cur=destination; while(parent[cur]!=-1) { distance++; cur=parent[cur]; } return distance; } static int bs(int size,int[]arr) { int x = -1; for (int b = size/2; b >= 1; b /= 2) { while (!ok(arr)); } int k = x+1; return k; } static boolean ok(int[]x) { return false; } public static int solve1(ArrayList<Integer> A) { long[]arr =new long[A.size()+1]; int n=A.size(); for(int i=1;i<=A.size();i++) { arr[i]=((i%2)*((n-i+1)%2))%2; arr[i]%=2; } int ans=0; for(int i=0;i<A.size();i++) { if(arr[i+1]==1) { ans^=A.get(i); } } return ans; } public static String printBinary(long a) { String str=""; for(int i=31;i>=0;i--) { if((a&(1<<i))!=0) { str+=1; } if((a&(1<<i))==0 && !str.isEmpty()) { str+=0; } } return str; } public static String reverse(long a) { long rev=0; String str=""; int x=(int)(Math.log(a)/Math.log(2))+1; for(int i=0;i<32;i++) { rev<<=1; if((a&(1<<i))!=0) { rev|=1; str+=1; } else { str+=0; } } return str; } //////////////////////////////////////////////////////// static void sortS(Pair arr[]) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return p1.second - p2.second; } }); } static class Pair implements Comparable<Pair> { int first ;int second ; public Pair(int x, int y) { this.first = x ;this.second = y ; } @Override public boolean equals(Object obj) { if(obj == this)return true ; if(obj == null)return false ; if(this.getClass() != obj.getClass()) return false ; Pair other = (Pair)(obj) ; if(this.first != other.first)return false ; if(this.second != other.second)return false ; return true ; } @Override public int hashCode() { return this.first^this.second ; } @Override public String toString() { String ans = "" ;ans += this.first ; ans += " "; ans += this.second ; return ans ; } @Override public int compareTo(Main.Pair o) { { if(this.first==o.first) { return this.second-o.second; } return this.first - o.first; } } } ////////////////////////////////////////////////////////////////////////// static int nD(long num) { String s=String.valueOf(num); return s.length(); } static int CommonDigits(int x,int y) { String s=String.valueOf(x); String s2=String.valueOf(y); return 0; } static int lcs(String str1, String str2, int m, int n) { int L[][] = new int[m + 1][n + 1]; int i, j; // Following steps build L[m+1][n+1] in // bottom up fashion. Note that L[i][j] // contains length of LCS of str1[0..i-1] // and str2[0..j-1] for (i = 0; i <= m; i++) { for (j = 0; j <= n; j++) { if (i == 0 || j == 0) L[i][j] = 0; else if (str1.charAt(i - 1) == str2.charAt(j - 1)) L[i][j] = L[i - 1][j - 1] + 1; else L[i][j] = Math.max(L[i - 1][j], L[i][j - 1]); } } // L[m][n] contains length of LCS // for X[0..n-1] and Y[0..m-1] return L[m][n]; } ///////////////////////////////// boolean IsPowerOfTwo(int x) { return (x != 0) && ((x & (x - 1)) == 0); } //////////////////////////////// static long power(long a,long b,long m ) { long ans=1; while(b>0) { if(b%2==1) { ans=((ans%m)*(a%m))%m; b--; } else { a=(a*a)%m;b/=2; } } return ans%m; } /////////////////////////////// public static boolean repeatedSubString(String string) { return ((string + string).indexOf(string, 1) != string.length()); } static int search(char[]c,int start,int end,char x) { for(int i=start;i<end;i++) { if(c[i]==x) {return i;} } return -2; } //////////////////////////////// static long gcd(long a, long b) { while (b != 0) { long t = b; b = a % b; a = t; } return a; } static long fac(long a) { if(a== 0L || a==1L)return 1L ; return a*fac(a-1L) ; } static ArrayList al() { ArrayList<Integer>a =new ArrayList<>(); return a; } static HashSet h() { return new HashSet<Integer>(); } static void debug(int[][]a) { int n= a.length; for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { out.print(a[i][j]+" "); } out.print("\n"); } } static void debug(int[]a) { out.println(Arrays.toString(a)); } static void debug(ArrayList<Integer>a) { out.println(a.toString()); } static boolean[]seive(int n){ boolean[]b=new boolean[n+1]; for (int i = 2; i <= n; i++) b[i] = true; for(int i=2;i*i<=n;i++) { if(b[i]) { for(int j=i*i;j<=n;j+=i) { b[j]=false; } } } return b; } static int longestIncreasingSubseq(int[]arr) { int[]sizes=new int[arr.length]; Arrays.fill(sizes, 1); int max=1; for(int i=1;i<arr.length;i++) { for(int j=0;j<i;j++) { if(arr[j]<arr[i]) { sizes[i]=Math.max(sizes[i],sizes[j]+1); max=Math.max(max, sizes[i]); } } } return max; } public static ArrayList primeFactors(long n) { ArrayList<Long>h= new ArrayList<>(); // Print the number of 2s that divide n if(n%2 ==0) {h.add(2L);} // n must be odd at this point. So we can // skip one element (Note i = i +2) for (long i = 3; i <= Math.sqrt(n); i+= 2) { if(n%i==0) {h.add(i);} } if (n > 2) h.add(n); return h; } static boolean Divisors(long n){ if(n%2==1) { return true; } for (long i=2; i<=Math.sqrt(n); i++){ if (n%i==0 && i%2==1){ return true; } } return false; } static InputStream inputStream = System.in; static OutputStream outputStream = System.out; static InputReader in = new InputReader(inputStream); static PrintWriter out = new PrintWriter(outputStream); public static void superSet(int[]a,ArrayList<String>al,int i,String s) { if(i==a.length) { al.add(s); return; } superSet(a,al,i+1,s); superSet(a,al,i+1,s+a[i]+" "); } public static long[] makeArr() { long size=in.nextInt(); long []arr=new long[(int)size]; for(int i=0;i<size;i++) { arr[i]=in.nextInt(); } return arr; } public static long[] arr(int n) { long []arr=new long[n+1]; for(int i=1;i<n+1;i++) { arr[i]=in.nextLong(); } return arr; } public static void sort(long arr[], int l, int r) { if (l < r) { // Find the middle point int m = (l+r)/2; // Sort first and second halves sort(arr, l, m); sort(arr , m+1, r); // Merge the sorted halves merge(arr, l, m, r); } } static void println(long x) { out.println(x); } static void print(long c) { out.print(c); } static void print(int c) { out.print(c); } static void println(int x) { out.println(x); } static void print(String s) { out.print(s); } static void println(String s) { out.println(s); } public static void merge(long arr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long[n1]; long R[] = new long[n2]; //Copy data to temp arrays for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } /* Copy remaining elements of L[] if any */ while (i < n1) { arr[k] = L[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; j++; k++; } } public static void reverse(int[] array) { int n = array.length; for (int i = 0; i < n / 2; i++) { int temp = array[i]; array[i] = array[n - i - 1]; array[n - i - 1] = temp; } } public static long nCr(int n,int k) { long ans=1L; k=k>n-k?n-k:k; for( int j=1;j<=k;j++,n--) { if(n%j==0) { ans*=n/j; }else if(ans%j==0) { ans=ans/j*n; }else { ans=(ans*n)/j; } } return ans; } static int searchMax(int index,long[]inp) { while(index+1<inp.length &&inp[index+1]>inp[index]) { index+=1; } return index; } static int searchMin(int index,long[]inp) { while(index+1<inp.length &&inp[index+1]<inp[index]) { index+=1; } return index; } public class ListNode { int val; ListNode next; ListNode() {} ListNode(int val) { this.val = val; } ListNode(int val, ListNode next) { this.val = val; this.next = next; } } static class Pairr implements Comparable<Pairr>{ private int index; private int cumsum; private ArrayList<Integer>indices; public Pairr(int index,int cumsum) { this.index=index; this.cumsum=cumsum; indices=new ArrayList<Integer>(); } public int compareTo(Pairr other) { return Integer.compare(cumsum, other.cumsum); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c0eedc35be67ab0c75246b4a8f79eff4
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[]args) { Scanner m = new Scanner(System.in); int n; n = m.nextInt(); while(n-->0) { int h; h = m.nextInt(); int arr[] = new int[h+10]; int tmp = h; for(int i=0;i<h;++i) arr[i] =tmp--; for(int i=0;i<h-1;++i) { for(int j=0;j<i;++j) System.out.print(arr[j]+" "); System.out.print(arr[i+1]+" "+arr[i]+" "); for(int j=i+2;j<h;++j) System.out.print(arr[j]+" "); System.out.println(); } for(int i=0;i<h;++i) System.out.print(arr[i]+" "); System.out.println(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
08f7d5621b64bcb0f7b75e164a299d89
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Hashtable; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; public class A { public static void main(String[]args){ MyScanner sc = new MyScanner(); int t = sc.nextInt(); for(int i=0;i<t;i++){ int n = sc.nextInt(); int start = n; int lines = 0; if(n==3){ System.out.println(3+" "+2+" "+1); System.out.println(1+" "+3+" "+2); System.out.println(3+" "+1+" "+2); } else{ while(lines<n){ int curr = start; for(int index=0;index<n;index++){ System.out.print(curr+" "); curr--; if(curr==0){ curr = n; } } System.out.println(); lines++; start --; } } } } } class Pair{ int x; int y; Pair(int a, int b){ x = a; y = b; } } class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c24f94b476d7d9fcfb09b0f9e65d1e93
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; public class B { private static final FastScanner fs = new FastScanner(); private static final int MOD = 1000000007; private static int cnt = 0; public static void main(String[] args) throws IOException { int cases = fs.nextInt(); while (cases-- > 0) solve(); } static void solve() throws IOException { int n = fs.nextInt(); cnt=0; ArrayList<Integer> res = new ArrayList<>(); HashSet<Integer> set = new HashSet<>(); for (int i = 1; i <= n; i++) set.add(i); dfs(set, res, n); } public static void dfs(HashSet<Integer> set, ArrayList<Integer> res, int n) { if (cnt == n) return; if (res.size() == n) { for (int i : res) System.out.print(i + " "); System.out.println(); cnt++; } int not = -1; if (res.size() >= 2) { not = res.get(res.size()-1) + res.get(res.size()-2); } for (int i : set) { if (i == not) continue; res.add(i); HashSet<Integer> nSet = new HashSet<>(set); nSet.remove(i); dfs(nSet, res, n); res.remove(res.size()-1); } } static class FastScanner { //I don't know how this works lmao public BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] nextInts(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
5fa1754e61563319fcb3667a4ec93566
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
/* Rating: 1367 Date: 22-02-2022 Time: 20-10-02 Author: Kartik Papney Linkedin: https://www.linkedin.com/in/kartik-papney-4951161a6/ Leetcode: https://leetcode.com/kartikpapney/ Codechef: https://www.codechef.com/users/kartikpapney */ import java.util.*; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Main { public static boolean debug = false; static void debug(String st) { if(debug) p.writeln(st); } public static void s() { int n = sc.nextInt(); int[] arr = new int[n]; for(int i=0; i<arr.length; i++) arr[n-i-1] = i+1; for(int i=0; i<arr.length; i++) { p.writes(arr[i]); } p.writeln(); for(int i=0; i<arr.length-1; i++) { int temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; for(int j=0; j<arr.length; j++) { p.writes(arr[j]); } p.writeln(); temp = arr[i]; arr[i] = arr[i+1]; arr[i+1] = temp; } } public static void main(String[] args) { int t = 1; t = sc.nextInt(); while (t-- != 0) { s(); } p.print(); } static final Integer MOD = (int) 1e9 + 7; static final FastReader sc = new FastReader(); static final Print p = new Print(); static class Functions { static void sort(int[] a) { ArrayList<Integer> l = new ArrayList<>(); for (int i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static void sort(long[] a) { ArrayList<Long> l = new ArrayList<>(); for (long i : a) l.add(i); Collections.sort(l); for (int i = 0; i < a.length; i++) a[i] = l.get(i); } static int max(int[] a) { int max = Integer.MIN_VALUE; for (int val : a) max = Math.max(val, max); return max; } static int min(int[] a) { int min = Integer.MAX_VALUE; for (int val : a) min = Math.min(val, min); return min; } static long min(long[] a) { long min = Long.MAX_VALUE; for (long val : a) min = Math.min(val, min); return min; } static long max(long[] a) { long max = Long.MIN_VALUE; for (long val : a) max = Math.max(val, max); return max; } static long sum(long[] a) { long sum = 0; for (long val : a) sum += val; return sum; } static int sum(int[] a) { int sum = 0; for (int val : a) sum += val; return sum; } public static long mod_add(long a, long b) { return (a % MOD + b % MOD + MOD) % MOD; } public static long pow(long a, long b) { long res = 1; while (b > 0) { if ((b & 1) != 0) res = mod_mul(res, a); a = mod_mul(a, a); b >>= 1; } return res; } public static long mod_mul(long a, long b) { long res = 0; a %= MOD; while (b > 0) { if ((b & 1) > 0) { res = mod_add(res, a); } a = (2 * a) % MOD; b >>= 1; } return res; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long factorial(long n) { long res = 1; for (int i = 1; i <= n; i++) { res = (i % MOD * res % MOD) % MOD; } return res; } public static int count(int[] arr, int x) { int count = 0; for (int val : arr) if (val == x) count++; return count; } public static ArrayList<Integer> generatePrimes(int n) { boolean[] primes = new boolean[n]; for (int i = 2; i < primes.length; i++) primes[i] = true; for (int i = 2; i < primes.length; i++) { if (primes[i]) { for (int j = i * i; j < primes.length; j += i) { primes[j] = false; } } } ArrayList<Integer> arr = new ArrayList<>(); for (int i = 0; i < primes.length; i++) { if (primes[i]) arr.add(i); } return arr; } } static class Print { StringBuffer strb = new StringBuffer(); public void write(Object str) { strb.append(str); } public void writes(Object str) { char c = ' '; strb.append(str).append(c); } public void writeln(Object str) { char c = '\n'; strb.append(str).append(c); } public void writeln() { char c = '\n'; strb.append(c); } public void yes() { char c = '\n'; writeln("YES"); } public void no() { writeln("NO"); } public void writes(int[] arr) { for (int val : arr) { write(val); write(' '); } } public void writes(long[] arr) { for (long val : arr) { write(val); write(' '); } } public void writeln(int[] arr) { for (int val : arr) { writeln(val); } } public void print() { System.out.print(strb); } public void println() { System.out.println(strb); } } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] readArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nextLong(); return a; } double[] readArrayDouble(int n) { double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } String nextLine() { String str = new String(); try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
0827d0beaf1d2f38bce0c65d5d999510
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; //import java.text.DecimalFormat; import java.util.*; public class Codeforces { static long mod = 1000000007 ; public static void main(String[] args) throws Exception { PrintWriter out=new PrintWriter(System.out); FastScanner fs=new FastScanner(); int t=fs.nextInt(); outer:while(t-->0) { int n=fs.nextInt(); if(n==3) { out.println("3 2 1"); out.println("1 3 2"); out.println("3 1 2"); continue outer; } int arr[]=new int[n]; for(int i=0;i<n;i++) arr[i]=n-i; int st=0; for(int j=0;j<n;j++) { int i=st; int cnt=0; while(cnt<n) { int x= arr[i]; i++; i%=n; cnt++; out.print(x+" "); } out.println(); st++; } } out.close(); } static long pow(long a,long b) { if(b<0) return 1; long res=1; while(b!=0) { if((b&1)!=0) { res*=a; res%=mod; } a*=a; a%=mod; b=b>>1; } return res; } static long gcd(long a,long b) { if(b==0) return a; return gcd(b,a%b); } static long nck(int n,int k) { if(k>n) return 0; long res=1; res*=fact(n); res%=mod; res*=modInv(fact(k)); res%=mod; res*=modInv(fact(n-k)); res%=mod; return res; } static long fact(long n) { // return fact[(int)n]; long res=1; for(int i=2;i<=n;i++) { res*=i; res%=mod; } return res; } static long modInv(long n) { return pow(n,mod-2); } static void sort(int[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n); int temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } static void sort(long[] a) { //suffle int n=a.length; Random r=new Random(); for (int i=0; i<a.length; i++) { int oi=r.nextInt(n); long temp=a[i]; a[i]=a[oi]; a[oi]=temp; } //then sort Arrays.sort(a); } // Use this to input code since it is faster than a Scanner static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long[] readArrayL(int n) { long a[]=new long[n]; for(int i=0;i<n;i++) a[i]=nextLong(); return a; } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
b128bc0ec643dd9f022c902464746154
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.HashSet; import java.util.Set; import java.util.StringTokenizer; public class E123B { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); while (t-- > 0) { st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); solve(n); } } private static void solve(int n) { int[] arr = new int[n]; for (int i = n; i >= 1; i--) { arr[n - i] = i; } for (int i = 0; i < n; i++) { print(arr); if (i != n - 1) swap(arr, n - i - 1, n - i - 2); } } private static void print(int[] arr) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < arr.length; i++) { builder.append(arr[i]); builder.append(" "); } builder.append("\n"); System.out.println(builder.toString()); } private static void swap(int[] arr, int i, int j) { int t = arr[i]; arr[i] = arr[j]; arr[j] = t; } } /* 1 1 0 1 0 1 1 0 0 0 1 */
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
f2bc6d02dc0f4b349744e60b507f8623
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0) { solve(sc); } } static void solve(Scanner sc) { int n = sc.nextInt(); for(int j = 1; j <= n; j++) { System.out.print(j); for(int x = n; x > 0; x--) { if(x != j) { System.out.print(" " + x); } } System.out.println(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c73e01715515d9c5ee02d04848712cb0
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; public class AntiFibonacciPermutation { public static void main(String[] args) throws IOException { Reader in = new Reader(); PrintWriter out = new PrintWriter(System.out); int T = in.nextInt(); for (int t = 0; t < T; t++) { int N = in.nextInt(); if (N == 3) { out.println("3 2 1"); out.println("1 3 2"); out.println("3 1 2"); } else { for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { out.print(((N - 1 - j + i) % N + 1) + (j == N - 1 ? "\n" : " ")); } } } } out.close(); } static class Reader { BufferedReader in; StringTokenizer st; public Reader() { in = new BufferedReader(new InputStreamReader(System.in)); st = new StringTokenizer(""); } public String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } public String next() throws IOException { while (!st.hasMoreTokens()) { st = new StringTokenizer(in.readLine()); } return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } } public static void sort(int[] arr) { List<Integer> list = new ArrayList<>(); for (int i : arr) { list.add(i); } Collections.sort(list); for (int i = 0; i < arr.length; i++) { arr[i] = list.get(i); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
21bd182b53c97a52a4be2ab647a37784
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class B_Anti_Fibonacci_Permutation { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int arr[] = new int[n]; for (int i = 0; i < n; i++) { arr[i] = n - i; } for (int i = 0; i < n; i++) { System.out.print(arr[i] + " "); } System.out.println(); int k = n - 2; for (int i = 0; i < n - 1; i++) { for (int j = 0; j < n; j++) { if (j == k) { System.out.print(arr[j + 1] + " " + arr[j] + " "); j++; } else { System.out.print(arr[j] + " "); } } System.out.println(); k--; } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
42839a1be16c5efe36d427391704829d
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.math.BigInteger; import java.util.*; import java.lang.*; import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.Math.sqrt; import static java.lang.Math.pow; import static java.lang.Math.ceil; import java.math.*; import java.util.function.Consumer; import java.util.stream.Collectors; public class AAtempOneForCodeForces { @SuppressWarnings("FieldCanBeLocal") private static Reader in; private static PrintWriter out; private static String YES = "YES"; private static String NO = "NO"; private static void solve() throws IOException{ //Your Code Goes Here; int n = in.nextInt(); for(int i = 1; i <= n; i++){ System.out.print(i); for(int j = n; j > 0; j--){ if(i != j){ System.out.print(" " + j); } } System.out.println(); } } public static void main(String[] args) throws IOException, InterruptedException { in = new Reader(); out = new PrintWriter(new OutputStreamWriter(System.out)); int T = in.nextInt(); while(T --> 0){ solve(); } out.flush(); in.close(); out.close(); } static final Random random = new Random(); static final int mod = 1_000_000_007; private static boolean check(long[] arr, long n){ long ch = arr[0]; for(int i = 0; i < n; i++){ if(ch != arr[i]){ return false; } } return true; } //This function gives the max occuring of any element in an array;(HashMap version) private static long maxFreqHashMap(long[] arr, long n){ Map<Long, Long> hp = new HashMap<Long, Long>(); for(int i = 0; i < n; i++) { long key = arr[i]; if(hp.containsKey(key)) { long freq = hp.get(key); freq++; hp.put(key, freq); } else { hp.put(key, 1L); } } long max_count = 0, res = 1, count = 0; for(Map.Entry<Long, Long> val : hp.entrySet()) { if (max_count < val.getValue()) { res = Math.toIntExact(val.getKey()); max_count = Math.toIntExact(val.getValue()); count = max_count; } } return count; } //This function gives the max occuring of any element in an array; this also known as the "MOORE's Algorithm" private static long maxFreq(long []arr, long n) { // using moore's voting algorithm long res = 0; long count = -1; for(int i = 1; i < n; i++) { if(arr[i] == arr[(int) res]) { count++; } else { count--; } if(count == 0) { res = i; count = 1; } } return arr[(int) res]; /* you've to add below code in the solve() long freq = maxFreq(arr, n); int count = 0; for(int i = 0; i < n; i++){ if(arr[i] == freq){ count++; } } */ } private static int LCSubStr(char[] X, char[] Y, int m, int n) { int[][] LCStuff = new int[m + 1][n + 1]; int result = 0; for (int i = 0; i <= m; i++){ for (int j = 0; j <= n; j++) { if (i == 0 || j == 0) { LCStuff[i][j] = 0; } else if (X[i - 1] == Y[j - 1]) { LCStuff[i][j] = LCStuff[i - 1][j - 1] + 1; result = Integer.max(result, LCStuff[i][j]); } else { LCStuff[i][j] = 0; } } } return result; } private static long longCusBsearch(long[] arr, long n, long h){ long ans = h; long l = 1; long r = h; while(l <= r){ long mid = (l + r) / 2; long ok = 0; for(long i = 0; i < n; i++){ if(i == n - 1) { ok += mid; } else{ long x = arr[(int) (i + 1)] - arr[(int) i]; if(x >= mid) { ok += mid; } else{ ok += x; } } } if(ok >= h){ ans = mid; r = mid - 1; } else{ l = mid + 1; } } return ans; } public static int intCusBsearch(int[] arr, int n, int h){ int ans = h, l = 1, r = h; while(l <= r){ int mid = (l + r) / 2; int ok = 0; for(int i = 0; i < n; i++){ if(i == n - 1){ ok += mid; } else{ int x = arr[i + 1] - arr[i]; if(x >= mid){ ok += mid; } else{ ok += x; } } } if(ok >= h){ ans = mid; r = mid - 1; } else{ l = mid + 1; } } return ans; } /* Method to check if x is power of 2*/ private static boolean isPowerOfTwo (int x) { /* First x in the below expression is for the case when x is 0 */ return x!=0 && ((x&(x-1)) == 0); } //Taken From "Second Thread" static void ruffleSort(int[] a){ int n = a.length;//shuffles, then sort; for(int i=0; i<n; i++){ int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } sort(a); } private static void longRuffleSort(long[] a){ long n = a.length; for(long i = 0;i<n;i++){ long oi = random.nextInt((int) n), temp = a[(int) oi]; a[(int) oi] = a[(int) i]; a[(int) i] = temp; } longSort(a); } private static int gcd(int a, int b){ if(a == 0 || b == 0){ return 0; } while(b != 0){ int temp; temp = a % b; a = b; b = temp; } return a; } private static long gcd(long a, long b){ if(a == 0 || b == 0){ return 0; } while(b != 0){ long temp; temp = a % b; a = b; b = temp; } return a; } private static int lowestCommonMultiple(int a, int b){ return (a / gcd(a, b) * b); } /* The Below func: the for loop runs in sqrt times. The second if is used to if the divisors are equal to print only one of them otherwise we're printing both; */ private static void pDivisors(int n){ for(int i=1;i<Math.sqrt(n);i++){ if(n % i == 0){ if(n / i == i){ System.out.println(i + " "); } else{ System.out.println(i + " " + (n / i) + " "); } } } } private static void returnNothing(){return;} private static int numOfdigitsinN(int a){return (int) (Math.floor(Math.log10(a)) + 1);} //prime Num till N: it takes any number and prints all the prime till that //num; private static boolean isPrime(int n){ if(n <= 1) return false; if(n <= 3) return true; //This is checked so that we can skip middle five number in below loop: if(n % 2 == 0 || n % 3 == 0) return false; for(int i = 5; i * i <= n; i = i + 6){ if(n % i == 0 || n % (i + 2) == 0){ return false; } } return true; } //below func is to print the isPrime func(); private static void printTheIsPrimeFunc(int n){ for(int i=2;i<=n;i++){ if(isPrime(i)) System.out.println(i + " "); } } public static boolean primeFinder(int n){ int m = 0; int flag = 0; m = n / 2; if(n == 0 ||n == 1){ return false; } else{ for(int i=2;i<=m;i++){ if(n % i == 0){ return false; } } return true; } } private static boolean evenOdd(int num){ //System.out.println((num & 1) == 0 ? "EVEN" : "ODD"); return (num & 1) == 0 ? true : false; } private static boolean[] sieveOfEratosthenes(long n) { boolean prime[] = new boolean[(int)n + 1]; for (int i = 0; i <= n; i++) { prime[i] = true; } for (long p = 2; p * p <= n; p++) { if (prime[(int)p] == true) { for (long i = p * p; i <= n; i += p) prime[(int)i] = false; } } return prime; } private static int log2(int n){ int result = (int) (Math.log(n) / Math.log(2)); return result; } private static long add(long a, long b){ return (a + b) % mod; } private static long lcm(long a, long b){ return (a / gcd((int) a, (int) b) * b); } private static void sort(int[] a){ ArrayList<Integer> l = new ArrayList<>(); for(int i:a) l.add(i); Collections.sort(l); for(int i=0;i<a.length;i++)a[i] = l.get(i); } private static void longSort(long[] a){ ArrayList<Long> l = new ArrayList<Long>(); for(long i:a) l.add(i); Collections.sort(l); for(int i=0;i<a.length;i++)a[i] = l.get(i); } public static int[][] prefixsum( int n , int m , int arr[][] ){ int prefixsum[][] = new int[n+1][m+1]; for( int i = 1 ;i <= n ;i++) { for( int j = 1 ; j<= m ; j++) { int toadd = 0; if( arr[i-1][j-1] == 1) { toadd = 1; } prefixsum[i][j] = toadd + prefixsum[i][j-1] + prefixsum[i-1][j] - prefixsum[i-1][j-1]; } } return prefixsum; } //call this method when you want to read an integer array; private static int[] readArray(int len) throws IOException{ int[] a = new int[len]; for(int i=0;i<len;i++)a[i] = in.nextInt(); return a; } //call this method when you want to read an Long array; private static long[] readLongArray(int len) throws IOException{ long[] a = new long[len]; for(int i=0;i<len;i++) a[i] = in.nextLong(); return a; } //call this method to print the integer array; private static void printArray(int[] array){ for(int now : array) out.print(now);out.print(' ');out.close(); } //call this method to print the long array; private static void printLongArray(long[] array){ for(long now:array) out.print(now); out.print(' '); out.close(); } /*Another way of Reading input...collected from a online blog from here => https://codeforces.com/contest/1625/submission/144334744;*/ private static class Reader { private static final int BUFFER_SIZE = 1 << 16; private final DataInputStream din; private final byte[] buffer; private int bufferPointer, bytesRead; Reader() {//Constructor; din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException {//To take user input for String values; final byte[] buf = new byte[1024]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { break; } buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextSign() throws IOException {//For taking the signs like plus or minus ... byte c = read(); while ('+' != c && '-' != c) { c = read(); } return '+' == c ? 0 : 1; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } public int skip() throws IOException { int b; // noinspection ALL while ((b = read()) != -1 && isSpaceChar(b)) { ; } return b; } public char nc() throws IOException { return (char) skip(); } public String next() throws IOException { int b = skip(); final StringBuilder sb = new StringBuilder(); while (!isSpaceChar(b)) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = read(); } return sb.toString(); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) { return -ret; } return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') { c = read(); } final boolean neg = c == '-'; if (neg) { c = read(); } do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) { return -ret; } return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) { buffer[0] = -1; } } private byte read() throws IOException { if (bufferPointer == bytesRead) { fillBuffer(); } return buffer[bufferPointer++]; } public void close() throws IOException { din.close(); } } /* A class representing a Mutable Multiset (Collectied From TechieDelight)*/ private static class Multiset<E> { /* List to store distinct values */ private List<E> values; /* List to store counts of distinct values */ private List<Integer> frequency; private final String ERROR_MSG = "Count cannot be negative: "; /* Constructor */ public Multiset() { values = new ArrayList<>(); frequency = new ArrayList<>(); } /** * Adds an element to this multiset specified number of times * * @param `element` The element to be added * @param `count` The number of times * @return The previous count of the element */ public int add(E element, int count) { if (count < 0) { throw new IllegalArgumentException(ERROR_MSG + count); } int index = values.indexOf(element); int prevCount = 0; if (index != -1) { prevCount = frequency.get(index); frequency.set(index, prevCount + count); } else if (count != 0) { values.add(element); frequency.add(count); } return prevCount; } /** * Adds specified element to this multiset * * @param `element` The element to be added * @return true always */ public boolean add(E element) { return add(element, 1) >= 0; } /** * Adds all elements in the specified collection to this multiset * * @param `c` Collection containing elements to be added * @return true if all elements are added to this multiset */ boolean addAll(Collection<? extends E> c) { for (E element: c) { add(element, 1); } return true; } /** * Adds all elements in the specified array to this multiset * * @param `arr` An array containing elements to be added */ public void addAll(E... arr) { for (E element: arr) { add(element, 1); } } /** * Performs the given action for each element of the Iterable, * including duplicates * * @param `action` The action to be performed for each element */ public void forEach(Consumer<? super E> action) { List<E> all = new ArrayList<>(); for (int i = 0; i < values.size(); i++) { for (int j = 0; j < frequency.get(i); j++) { all.add(values.get(i)); } all.forEach(action); } } /** * Removes a single occurrence of the specified element from this multiset * * @param `element` The element to removed * @return true if an occurrence was found and removed */ public boolean remove(Object element) { return remove(element, 1) > 0; } /** * Removes a specified number of occurrences of the specified element * from this multiset * * @param `element` The element to removed * @param `count` The number of occurrences to be removed * @return The previous count */ public int remove(Object element, int count) { if (count < 0) { throw new IllegalArgumentException(ERROR_MSG + count); } int index = values.indexOf(element); if (index == -1) { return 0; } int prevCount = frequency.get(index); if (prevCount > count) { frequency.set(index, prevCount - count); } else { values.remove(index); frequency.remove(index); } return prevCount; } /** * Check if this multiset contains at least one occurrence of the * specified element * * @param `element` The element to be checked * @return true if this multiset contains at least one occurrence * of the element */ public boolean contains(Object element) { return values.contains(element); } /** * Check if this multiset contains at least one occurrence of each element * in the specified collection * * @param `c` The collection of elements to be checked * @return true if this multiset contains at least one occurrence * of each element */ public boolean containsAll(Collection<?> c) { return values.containsAll(c); } /** * Update the frequency of an element to the specified count or * add element to this multiset if not present * * @param `element` The element to be updated * @param `count` The new count * @return The previous count */ public int setCount(E element, int count) { if (count < 0) { throw new IllegalArgumentException(ERROR_MSG + count); } if (count == 0) { remove(element); } int index = values.indexOf(element); if (index == -1) { return add(element, count); } int prevCount = frequency.get(index); frequency.set(index, count); return prevCount; } /** * Find the frequency of an element in this multiset * * @param `element` The element to be counted * @return The frequency of the element */ public int count(Object element) { int index = values.indexOf(element); return (index == -1) ? 0 : frequency.get(index); } /** * @return A view of the set of distinct elements in this multiset */ public Set<E> elementSet() { return values.stream().collect(Collectors.toSet()); } /** * @return true if this multiset is empty */ public boolean isEmpty() { return values.size() == 0; } /** * @return Total number of elements in this multiset, including duplicates */ public int size() { int size = 0; for (Integer i: frequency) { size += i; } return size; } @Override public String toString() { StringBuilder sb = new StringBuilder("["); for (int i = 0; i < values.size(); i++) { sb.append(values.get(i)); if (frequency.get(i) > 1) { sb.append(" x ").append(frequency.get(i)); } if (i != values.size() - 1) { sb.append(", "); } } return sb.append("]").toString(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
6c6d9b694e0886e62b03a2410fa127d6
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int num = s.nextInt(); int[] arr = new int[num]; for (int i = 0; i < num; i++) { arr[i] = s.nextInt(); } s.close(); for (int nums : arr) { sum += nums; for (int i = 1; i <= nums; i++) { for (int j = 1; j <= nums; j++) { if (i != j) { List<Integer> list = new ArrayList<>(); HashSet<Integer> set = new HashSet<>(); list.add(i); list.add(j); set.add(i); set.add(j); cal(nums, list, set); } } } } for (List<Integer> list : ans) { for (int number : list) { System.out.print(number + " "); } System.out.println(); } } static int sum = 0; static List<List<Integer>> ans = new ArrayList<>(); public static void cal(int num, List<Integer> list, HashSet<Integer> set) { if (ans.size() < sum) { if (list.size() == num) { ans.add(new ArrayList<>(list)); return; } for (int i = 1; i <= num; i++) { if (!set.contains(i)) { int size = list.size(); if (list.get(size - 1) + list.get(size - 2) != i) { set.add(i); list.add(i); cal(num, list, set); set.remove(i); list.remove(list.size() - 1); } } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
0fdb3c51d6a1f9151bcb184884090ab1
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.Scanner; public class B1644 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); for (int t=0; t<T; t++) { int N = in.nextInt(); if (N == 3) { System.out.println("3 2 1"); System.out.println("1 3 2"); System.out.println("3 1 2"); } else { for (int shift=0; shift<N; shift++) { StringBuilder sb = new StringBuilder(); for (int n=N-1; n>=0; n--) { sb.append((shift+n)%N + 1).append(' '); } System.out.println(sb); } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
8e3da9f7cdc85ba47441b4d8fd6c90f6
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.*; import javafx.scene.layout.Priority; public class Main { public static void main(String args[]) { FastScanner input = new FastScanner(); StringBuilder result = new StringBuilder(); int tc = input.nextInt(); work: while (tc-- > 0) { int n = input.nextInt(); if(n==1) { result.append("1\n"); continue work; } else if(n==2) { result.append("1 2\n"); result.append("2 1\n"); continue work; } else if(n==3) { result.append("3 2 1\n"); result.append("3 1 2\n"); result.append("2 3 1\n"); continue work; } for (int i = n; i >1; i--) { TreeSet<Integer> set = new TreeSet<>(); int temp = i; while(temp>=1) { set.add(temp); result.append(temp+" "); temp--; } temp = n; while(set.size()<n) { set.add(temp); result.append(temp+ " "); temp--; } result.append("\n"); } result.append("1 3 2 "); for (int i = 4; i <=n; i++) { result.append(i+" "); } result.append("\n"); } System.out.println(result); } static class FastScanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() throws IOException { return br.readLine(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
6cb51d1b027cacd47660d4dd133eeeff
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.awt.Desktop; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URI; import java.net.URISyntaxException; import java.sql.Array; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.Deque; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeMap; import java.util.TreeSet; import java.util.Vector; import org.w3c.dom.Node; public class codechef3 { static class comp implements Comparator<String> { @Override public int compare(String o1, String o2) { if(o1.length()>o2.length()) return 1; else if(o1.length()<o2.length()) return -1; else return o1.compareTo(o2); } } static class Pair<Integer,Intetger> { int k=0; int v=0; public Pair(int a,int b) { k=a; v=b; } public int getKey() { return k; } } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //------------------------------------------------------------------------------------------- public static void main(String[] args) { FastReader s=new FastReader(); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); for(int i=1;i<=n;i++) { System.out.print(i+" "); for(int j=n;j>=1;j--) { if(i!=j) System.out.print(j+" "); } } } } //1 1 1 1 1 1 1 1 1 1 1 1 }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c32f123b8c9ef99a01f6f04ca77dbe5c
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
//package algorithm; import java.util.Scanner; /** * @author Jeffrey.X.Sun * @date 2022/3/17 8:48 */ public class AntiFibonacci { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int times = scanner.nextInt(); int[] nums = new int[times]; for(int i = 0; i < times; i++){ nums[i] = scanner.nextInt(); } for(int j : nums){ for(int m = 1; m <= j; m++){ System.out.print(m + " "); for(int n = j; n >=1; n--){ if(n != m){ System.out.print(n + " "); } } System.out.println(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
90cb537c374135de49abf0f89964243d
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.util.Arrays; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pranay */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); int N = in.nextInt(); for(int i=1; i<=N; ++i) solver.solve(i, in, out); out.close(); } static class Task { public void solve(int testNumber, FastReader in, PrintWriter out) { int n = in.nextInt(); for(int i=1; i<=n; i++) { out.print(i+" "); for(int j=n; j>=1; j--) if(i!=j){ out.print(j+" "); } out.println(); } } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int[] readArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
70b0ee7efce7fff261669cb639e4537a
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.InputMismatchException; import java.util.Arrays; import java.io.IOException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Pranay */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task solver = new Task(); int N = in.nextInt(); for(int i=1; i<=N; ++i) solver.solve(i, in, out); out.close(); } static class Task { public void solve(int testNumber, FastReader in, PrintWriter out) { int n = in.nextInt(); for(int i=1; i<=n; i++) { out.print(i+" "); for(int j=n; j>=1; j--) if(i!=j){ out.print(j+" "); } out.println(); } } } static class FastReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private FastReader.SpaceCharFilter filter; public FastReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public int[] readArray(int size) { int[] array = new int[size]; for (int i = 0; i < size; i++) array[i] = nextInt(); return array; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } public String next() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
b1a76d5a098a686bc1082f563ff3c6e8
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.awt.*; import java.util.*; import java.io.*; public class Codeforces { static FScanner sc = new FScanner(); static PrintWriter out = new PrintWriter(System.out); static final Random random = new Random(); static long mod = 1000000007L; static HashMap<String, Integer> map = new HashMap<>(); static boolean[] sieve = new boolean[1000000]; static double[] fib = new double[1000000]; public static void main(String args[]) throws IOException { int T = sc.nextInt(); while (T-- > 0) { int n=sc.nextInt(); int[] a=new int[n]; for(int i=0;i<n;i++) a[i]=n-i; for(int i=0;i<n;i++) { int temp=a[i]; for(int j=i;j>0;j--) a[j]=a[j-1]; a[0]=temp; for(int j=0;j<n;j++) out.print(a[j]+" "); out.println(); temp=a[0]; for(int j=0;j<i;j++) a[j]=a[j+1]; a[i]=temp; } } out.close(); } // TemplateCode static void fib() { fib[0] = 0; fib[1] = 1; for (int i = 2; i < fib.length; i++) fib[i] = fib[i - 1] + fib[i - 2]; } static void primeSieve() { for (int i = 0; i < sieve.length; i++) sieve[i] = true; for (int i = 2; i * i <= sieve.length; i++) { if (sieve[i]) { for (int j = i * i; j < sieve.length; j += i) { sieve[j] = false; } } } } static int max(int a, int b) { if (a < b) return b; return a; } static int min(int a, int b) { if (a < b) return a; return b; } static void ruffleSort(int[] a) { int n = a.length; for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static <E> void print(E res) { System.out.println(res); } static int gcd(int a, int b) { if (b == 0) { return a; } return gcd(b, a % b); } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static int abs(int a) { if (a < 0) return -1 * a; return a; } static class FScanner { BufferedReader br; StringTokenizer st; public FScanner() { 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int[] readintarray(int n) { int res[] = new int[n]; for (int i = 0; i < n; i++) res[i] = nextInt(); return res; } long[] readlongarray(int n) { long res[] = new long[n]; for (int i = 0; i < n; i++) res[i] = nextLong(); return res; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
4f7ac8da8bc100bb74c1f7c3357fbc75
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); while (sc.hasNext()) { int m = sc.nextInt(); while (m-- > 0) { int n = sc.nextInt(); for (int i = 1; i <= n; i++) { System.out.print(i); for (int k =n ; k >0; k--) { if(i!=k) { System.out.print(" "+k); } } System.out.println(); } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
afe01142519571f995afa4a3f55208a5
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class Main { static Map<Integer, List<LinkedList<Integer>>> memo = new HashMap<>(); private static void solve(int t){ List<LinkedList<Integer>> res = helper(t); int count = 0; for(LinkedList<Integer> l: res){ Iterator it = l.iterator(); StringBuilder sb = new StringBuilder(); while(it.hasNext()){ sb.append(it.next()); sb.append(' '); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb); count++; if(count == t){ return; } } } static List<LinkedList<Integer>> helper(int t){ if(memo.containsKey(t)){ return memo.get(t); } List<LinkedList<Integer>> prev = helper(t - 1); List<LinkedList<Integer>> res = new ArrayList<>(); for(LinkedList<Integer> x: prev){ if(t + x.get(0) != x.get(1)){ LinkedList<Integer> ll = new LinkedList<>(x); ll.addFirst(t); res.add(ll); } } while(res.size() < t){ for(LinkedList<Integer> x: prev){ if(t + x.get(x.size() - 1) != x.get(x.size() - 2)){ LinkedList<Integer> ll = new LinkedList<>(x); ll.addLast(t); res.add(ll); } if(res.size() == t){ break; } } } memo.put(t, res); return res; } public static void main(String[] args){ MyScanner scanner = new MyScanner(); LinkedList<Integer> l1 = new LinkedList<>(); l1.addLast(3);l1.addLast(2);l1.addLast(1); LinkedList<Integer> l2 = new LinkedList<>(); l2.addLast(1);l2.addLast(3);l2.addLast(2); LinkedList<Integer> l3 = new LinkedList<>(); l3.addLast(3);l3.addLast(1);l3.addLast(2); memo.put(3, new ArrayList<>()); memo.get(3).add(l1); memo.get(3).add(l2); memo.get(3).add(l3); int num = scanner.nextInt(); for(int i = 0; i < num; i++){ solve(scanner.nextInt()); } } //public static PrintWriter out; public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
394cfdae8f8a5bfb9585df046c897ef3
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main { public static void main (String[] args) throws java.lang.Exception { Scanner c=new Scanner(System.in); int t; t=c.nextInt(); while(t-->0){ int n=c.nextInt(); for(int i=1;i<=n;i++){ System.out.print(i +" "); for(int j=n;j>0;j--){ if(j!=i) System.out.print(j +" "); } System.out.println(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
4554e2c2bd56fb88d4b3b346be91d48c
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class antifib { public static void main(String[] args) throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); while(T-- > 0) { int N = Integer.parseInt(br.readLine()); if(N == 3) { System.out.println("3 2 1"); System.out.println("1 3 2"); System.out.println("2 3 1"); } else { LinkedList<Integer> l = new LinkedList<>(); for(int i = N;i >= 1;i--) { l.add(i); } for(int i = 0;i < N;i++) { print(l); int temp = l.remove(); l.add(temp); } } } } private static void print(LinkedList<Integer> l) { for(int x: l) { System.out.print(x + " "); } System.out.println(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 8
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
3549f54c828505efb3c10ca9b053575e
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class Solution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while (t-- > 0) { int n= sc.nextInt(); if(n==3){ System.out.println("3 2 1\n" + "1 3 2\n" + "3 1 2"); } else { int c1 = n; int c2 = n+1; for (int i = 0; i < n; i++) { for (int j = c2; j <=n; j++) { if (j == 2) System.out.print("3 "); else if (j == 3) System.out.print("2 "); else System.out.print(j + " "); } for (int j = 1; j <= c1; j++) { if (j == 2) System.out.print("3 "); else if (j == 3) System.out.print("2 "); else { System.out.print(j + " "); } } c1--; c2--; System.out.println(); } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
b691c410537a0298c26485790ce5a652
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
// package codeforce; import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.io.*; public class A { static class Node { int id1; int id2; Node(int v1, int w1){ this.id1= v1; this.id2=w1; } Node(){} // int index() { // return ind; // } // int number() { // return num; // } // @Override // public int compare(Node p1, Node p2) { // // // if(p1.num<p2.num) { // return 1; // } // else if(p1.num > p2.num) { // return -1; // } // else { // if(p1.ind<p2.ind)return -1; // return 1; // } // // } } 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()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str = ""; try{ str = br.readLine(); } catch (IOException e){ e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc=new FastReader(); int t = sc.nextInt(); int mod = 1000000007; while(t--!=0) { int n=sc.nextInt(); // String a= sc.next(); // long[] arr = new long[n]; int[] arr= new int[n]; for(int i=n; i>=1; i--) { arr[n-i]= i; } if(n==3) { System.out.println("3 2 1"); System.out.println("1 3 2"); System.out.println("2 3 1"); } else if(n==4) { System.out.println("4 3 2 1"); System.out.println("4 2 3 1"); System.out.println("1 2 4 3"); System.out.println("1 3 2 4"); } else { // int temp = arr[2]; // arr[2]= arr[3]; // arr[3]=temp; for(int i=0; i<n ;i++) { System.out.print(arr[i]+" "); } System.out.println(); for(int i=1; i<n; i++) { int c = arr[i-1]; arr[i-1]=arr[i]; arr[i]= c; if(n%2==1) { if(i!=n/2+1) { for(int j=0; j<n ;j++) { System.out.print(arr[j]+" "); } System.out.println(); } } else { for(int j=0; j<n ;j++) { System.out.print(arr[j]+" "); } System.out.println(); } } if(n%2==1) { for(int i=1; i<=n; i++) { arr[i-1]= i; } int temp = arr[2]; arr[2]= arr[3]; arr[3]=temp; for(int j=0; j<n ;j++) { System.out.print(arr[j]+" "); } System.out.println(); } } } } static ArrayList<Node> al = new ArrayList<>(); static int[] gcd= {2, 11, 101, 1087, 15413, 100003, 1000003, 10000019, 999999937}; static long answer =0; static void solve(int[][] arr, int n, int m) { if(arr[0][0] >2 || arr[0][m-1]>2 || arr[n-1][0]>2 || arr[n-1][m-1]>2) { System.out.println("NO"); return; } for(int i=1; i< m; i++) { if(arr[0][i]>3 || arr[n-1][i]>3) { System.out.println("NO"); return; } arr[0][i]= 3; arr[n-1][i]=3; } for(int i=1; i< n; i++) { if(arr[i][0]>3 || arr[i][m-1]>3) { System.out.println("NO"); return; } arr[i][0]= 3; arr[i][m-1]=3; } arr[0][0] =2 ; arr[0][m-1]=2 ; arr[n-1][0]=2; arr[n-1][m-1]=2; for(int i=1 ; i<n-1 ;i++) { for(int j= 1; j<m-1 ; j++) { if(arr[i][j]>4) { System.out.println("NO"); return ; } arr[i][j]=4; } } System.out.println("YES"); for(int i=0; i<n; i++) { for(int j=0 ;j<m ;j++) { System.out.print(arr[i][j]+" "); } System.out.println(); } } public static boolean isValid(int x, int y, char[][] arr , boolean[][] vis) { if(x<0 || y<0 || x>= arr.length || y>=arr.length || vis[x][y]==true || arr[x][y]=='1')return false; return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static double pow(int a, int b) { long res= 1; while(b>0) { if((b&1)!=0) { res= (res*a); } a= (a*a); b= b>>1; } return res; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
f7131bf8d087c0be5315c98a8d29bcc1
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
//package com.company; // Java implementation of the approach import java.io.*; import java.util.Arrays; import java.util.*; import java.util.Queue; import java.util.Scanner; public class ww { public static void main(String[] args) throws IOException { // Scanner Reader = new Scanner(System.in); Reader.init(System.in); int t = Reader.nextInt(); while(t--> 0){ int m = Reader.nextInt(); if(m==3){ System.out.println("1 3 2"); System.out.println("2 3 1"); System.out.println("3 2 1"); } else { int[] arr = new int[m]; arr[0] = 1; arr[1] = 3; arr[2] = 2; for (int i = 3; i < m; i++) { arr[i] = i + 1; } for (int i = 0; i < m; i++) { int x = arr[0]; // System.out.println(x); for (int j = 1; j < m; j++) { // System.out.print(arr[j-1]+" "); arr[j - 1] = arr[j]; System.out.print(arr[j - 1] + " "); } arr[m - 1] = x; System.out.println(x); } } } } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) { reader = new BufferedReader( new InputStreamReader(input) ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static String nextLine() throws IOException { return reader.readLine(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static long nextLong() throws IOException{ return Long.parseLong(next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
44a65a2fddfb4b539e3ec536b8999a35
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import static java.lang.Math.max; import static java.lang.Math.min; import static java.lang.Math.abs; import static java.lang.Math.sqrt; import static java.lang.Math.pow; import static java.lang.System.out; import static java.lang.System.err; import java.util.*; import java.io.*; import java.math.*; public class Main { static FastReader sc; static long mod=((long)1e9)+7; // static FastWriter out; public static void main(String hi[]){ initializeIO(); sc=new FastReader(); int t=sc.nextInt(); // boolean[] seave=sieveOfEratosthenes((int)(1e7)); // int[] seave2=sieveOfEratosthenesInt((int)(1e4)); // int tp=1; while(t--!=0){ int n=sc.nextInt(); if(n==3){ out.println("3 2 1 \n 3 1 2 \n 1 3 2"); }else{ List<Integer> li=new ArrayList<>(); for(int i=n;i>=1;i--)li.add(i); // int i=0; for(int i=0;i<n;i++){ swap(li,0,i); for(int x:li)out.print(x+" "); out.println(); } } } // System.out.println(String.format("%.9f", max)); } private static int sizeOfSubstring(int st,int e){ int s=e-st+1; return (s*(s+1))/2; } private static int lessThen(long[] nums,long val){ int i=0,l=0,r=nums.length-1; while(l<=r){ int mid=l+((r-l)/2); if(nums[mid]<=val){ i=mid; l=mid+1; }else{ r=mid-1; } } return i; } private static int lessThen(List<Long> nums,long val){ int i=0,l=0,r=nums.size()-1; while(l<=r){ int mid=l+((r-l)/2); if(nums.get(mid)<=val){ i=mid; l=mid+1; }else{ r=mid-1; } } return i; } private static int greaterThen(long[] nums,long val){ int i=nums.length-1,l=0,r=nums.length-1; while(l<=r){ int mid=l+((r-l)/2); if(nums[mid]>=val){ i=mid; r=mid-1; }else{ l=mid+1; } } return i; } private static long sumOfAp(long a,long n,long d){ long val=(n*( 2*a+((n-1)*d))); return val/2; } //geometrics private static double areaOftriangle(double x1,double y1,double x2,double y2,double x3,double y3){ double[] mid_point=midOfaLine(x1,y1,x2,y2); // debug(Arrays.toString(mid_point)+" "+x1+" "+y1+" "+x2+" "+y2+" "+x3+" "+" "+y3); double height=distanceBetweenPoints(mid_point[0],mid_point[1],x3,y3); double wight=distanceBetweenPoints(x1,y1,x2,y2); // debug(height+" "+wight); return (height*wight)/2; } private static double distanceBetweenPoints(double x1,double y1,double x2,double y2){ double x=x2-x1; double y=y2-y1; return sqrt(Math.pow(x,2)+Math.pow(y,2)); } private static double[] midOfaLine(double x1,double y1,double x2,double y2){ double[] mid=new double[2]; mid[0]=(x1+x2)/2; mid[1]=(y1+y2)/2; return mid; } private static long sumOfN(long n){ return (n*(n+1))/2; } private static long power(long x,long y,long p){ long res = 1; // Initialize result x = x % p; // Update x if it is more than or // equal to p if (x == 0) return 0; // In case x is divisible by p; while (y > 0){ // If y is odd, multiply x with result if ((y & 1) != 0) res = (res * x) % p; // y must be even now y = y >> 1; // y = y/2 x = (x * x) % p; } return res; } /* Function to calculate x raised to the power y in O(logn)*/ static long power(long x, long y){ long temp; if( y == 0) return 1l; temp = power(x, y / 2); if (y % 2 == 0) return (temp*temp); else return (x*temp*temp); } private static StringBuilder reverseString(String s){ StringBuilder sb=new StringBuilder(s); int l=0,r=sb.length()-1; while(l<=r){ char ch=sb.charAt(l); sb.setCharAt(l,sb.charAt(r)); sb.setCharAt(r,ch); l++; r--; } return sb; } private static void swap(long arr[],int i,int j){ long t=arr[i]; arr[i]=arr[j]; arr[j]=t; } private static void swap(List<Integer> li,int i,int j){ int t=li.get(i); li.set(i,li.get(j)); li.set(j,t); } private static void swap(int arr[],int i,int j){ int t=arr[i]; arr[i]=arr[j]; arr[j]=t; } private static void swap(double arr[],int i,int j){ double t=arr[i]; arr[i]=arr[j]; arr[j]=t; } private static void swap(float arr[],int i,int j){ float t=arr[i]; arr[i]=arr[j]; arr[j]=t; } static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } static long lcm(long a, long b){ return (a / gcd(a, b)) * b; } private static String decimalToString(int x){ return Integer.toBinaryString(x); } private static boolean isPallindrome(String s){ int l=0,r=s.length()-1; while(l<r){ if(s.charAt(l)!=s.charAt(r))return false; l++; r--; } return true; } private static StringBuilder removeLeadingZero(StringBuilder sb){ int i=0; while(i<sb.length()&&sb.charAt(i)=='0')i++; // debug("remove "+i); if(i==sb.length())return new StringBuilder(); return new StringBuilder(sb.substring(i,sb.length())); } private static int stringToDecimal(String binaryString){ // debug(decimalToString(n<<1)); return Integer.parseInt(binaryString,2); } private static int stringToInt(String s){ return Integer.parseInt(s); } private static String toString(int val){ return String.valueOf(val); } private static void debug(int[][] arr){ for(int i=0;i<arr.length;i++){ err.println(Arrays.toString(arr[i])); } } private static void debug(long[][] arr){ for(int i=0;i<arr.length;i++){ err.println(Arrays.toString(arr[i])); } } private static void debug(List<int[]> arr){ for(int[] a:arr){ err.println(Arrays.toString(a)); } } private static void debug(float[][] arr){ for(int i=0;i<arr.length;i++){ err.println(Arrays.toString(arr[i])); } } private static void debug(double[][] arr){ for(int i=0;i<arr.length;i++){ err.println(Arrays.toString(arr[i])); } } private static void debug(boolean[][] arr){ for(int i=0;i<arr.length;i++){ err.println(Arrays.toString(arr[i])); } } private static void print(String s){ out.println(s); } private static void debug(String s){ err.println(s); } private static int charToIntS(char c){ return ((((int)(c-'0'))%48)); } private static void print(double s){ out.println(s); } private static void print(float s){ out.println(s); } private static void print(long s){ out.println(s); } private static void print(int s){ out.println(s); } private static void debug(double s){ err.println(s); } private static void debug(float s){ err.println(s); } private static void debug(long s){ err.println(s); } private static void debug(int s){ err.println(s); } private static boolean isPrime(int n){ // Check if number is less than // equal to 1 if (n <= 1) return false; // Check if number is 2 else if (n == 2) return true; // Check if n is a multiple of 2 else if (n % 2 == 0) return false; // If not, then just check the odds for (int i = 3; i <= Math.sqrt(n); i += 2) { if (n % i == 0) return false; } return true; } //read graph private static List<List<Integer>> readUndirectedGraph(int n){ List<List<Integer>> graph=new ArrayList<>(); for(int i=0;i<=n;i++){ graph.add(new ArrayList<>()); } for(int i=0;i<n;i++){ int x=sc.nextInt(); int y=sc.nextInt(); graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readUndirectedGraph(int[][] intervals,int n){ List<List<Integer>> graph=new ArrayList<>(); for(int i=0;i<=n;i++){ graph.add(new ArrayList<>()); } for(int i=0;i<intervals.length;i++){ int x=intervals[i][0]; int y=intervals[i][1]; graph.get(x).add(y); graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int[][] intervals,int n){ List<List<Integer>> graph=new ArrayList<>(); for(int i=0;i<=n;i++){ graph.add(new ArrayList<>()); } for(int i=0;i<intervals.length;i++){ int x=intervals[i][0]; int y=intervals[i][1]; graph.get(x).add(y); // graph.get(y).add(x); } return graph; } private static List<List<Integer>> readDirectedGraph(int n){ List<List<Integer>> graph=new ArrayList<>(); for(int i=0;i<=n;i++){ graph.add(new ArrayList<>()); } for(int i=0;i<n;i++){ int x=sc.nextInt(); int y=sc.nextInt(); graph.get(x).add(y); // graph.get(y).add(x); } return graph; } static String[] readStringArray(int n){ String[] arr=new String[n]; for(int i=0;i<n;i++){ arr[i]=sc.next(); } return arr; } private static Map<Character,Integer> freq(String s){ Map<Character,Integer> map=new HashMap<>(); for(char c:s.toCharArray()){ map.put(c,map.getOrDefault(c,0)+1); } return map; } static boolean[] sieveOfEratosthenes(long n){ boolean prime[] = new boolean[(int)n + 1]; for (int i = 2; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { // If prime[p] is not changed, then it is a // prime if (prime[p] == true){ // Update all multiples of p for (int i = p * p; i <= n; i += p) prime[i] = false; } } return prime; } static int[] sieveOfEratosthenesInt(long n){ boolean prime[] = new boolean[(int)n + 1]; Set<Integer> li=new HashSet<>(); for (int i = 1; i <= n; i++){ prime[i] = true; li.add(i); } for (int p = 2; p * p <= n; p++) { if (prime[p] == true){ for (int i = p * p; i <= n; i += p){ li.remove(i); prime[i] = false; } } } int[] arr=new int[li.size()+1]; int i=0; for(int x:li){ arr[i++]=x; } return arr; } public static long Kadens(List<Long> prices) { long sofar=0; long max_v=0; for(int i=0;i<prices.size();i++){ sofar+=prices.get(i); if (sofar<0) { sofar=0; } max_v=Math.max(max_v,sofar); } return max_v; } public static int Kadens(int[] prices) { int sofar=0; int max_v=0; for(int i=0;i<prices.length;i++){ sofar+=prices[i]; if (sofar<0) { sofar=0; } max_v=Math.max(max_v,sofar); } return max_v; } static boolean isMemberAC(int a, int d, int x){ // If difference is 0, then x must // be same as a. if (d == 0) return (x == a); // Else difference between x and a // must be divisible by d. return ((x - a) % d == 0 && (x - a) / d >= 0); } private static void sort(int[] arr){ int n=arr.length; List<Integer> li=new ArrayList<>(); for(int x:arr){ li.add(x); } Collections.sort(li); for (int i=0;i<n;i++) { arr[i]=li.get(i); } } private static void sortReverse(int[] arr){ int n=arr.length; List<Integer> li=new ArrayList<>(); for(int x:arr){ li.add(x); } Collections.sort(li,Collections.reverseOrder()); for (int i=0;i<n;i++) { arr[i]=li.get(i); } } private static void sort(double[] arr){ int n=arr.length; List<Double> li=new ArrayList<>(); for(double x:arr){ li.add(x); } Collections.sort(li); for (int i=0;i<n;i++) { arr[i]=li.get(i); } } private static void sortReverse(double[] arr){ int n=arr.length; List<Double> li=new ArrayList<>(); for(double x:arr){ li.add(x); } Collections.sort(li,Collections.reverseOrder()); for (int i=0;i<n;i++) { arr[i]=li.get(i); } } private static void sortReverse(long[] arr){ int n=arr.length; List<Long> li=new ArrayList<>(); for(long x:arr){ li.add(x); } Collections.sort(li,Collections.reverseOrder()); for (int i=0;i<n;i++) { arr[i]=li.get(i); } } private static void sort(long[] arr){ int n=arr.length; List<Long> li=new ArrayList<>(); for(long x:arr){ li.add(x); } Collections.sort(li); for (int i=0;i<n;i++) { arr[i]=li.get(i); } } private static long sum(int[] arr){ long sum=0; for(int x:arr){ sum+=x; } return sum; } private static long evenSumFibo(long n){ long l1=0,l2=2; long sum=0; while (l2<n) { long l3=(4*l2)+l1; sum+=l2; if(l3>n)break; l1=l2; l2=l3; } return sum; } private static void initializeIO(){ try { System.setIn(new FileInputStream("input.txt")); System.setOut(new PrintStream(new FileOutputStream("output.txt"))); System.setErr(new PrintStream(new FileOutputStream("error.txt"))); } catch (Exception e) { // System.err.println(e.getMessage()); } } private static int maxOfArray(int[] arr){ int max=Integer.MIN_VALUE; for(int x:arr){ max=Math.max(max,x); } return max; } private static long maxOfArray(long[] arr){ long max=Long.MIN_VALUE; for(long x:arr){ max=Math.max(max,x); } return max; } private static int[][] readIntIntervals(int n,int m){ int[][] arr=new int[n][m]; for(int j=0;j<n;j++){ for(int i=0;i<m;i++){ arr[j][i]=sc.nextInt(); } } return arr; } private static long gcd(long a,long b){ if(b==0)return a; return gcd(b,a%b); } private static int gcd(int a,int b){ if(b==0)return a; return gcd(b,a%b); } private static int[] readIntArray(int n){ int[] arr=new int[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextInt(); } return arr; } private static double[] readDoubleArray(int n){ double[] arr=new double[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextDouble(); } return arr; } private static long[] readLongArray(int n){ long[] arr=new long[n]; for(int i=0;i<n;i++){ arr[i]=sc.nextLong(); } return arr; } private static void print(int[] arr){ out.println(Arrays.toString(arr)); } private static void print(long[] arr){ out.println(Arrays.toString(arr)); } private static void print(String[] arr){ out.println(Arrays.toString(arr)); } private static void print(double[] arr){ out.println(Arrays.toString(arr)); } private static void debug(String[] arr){ err.println(Arrays.toString(arr)); } private static void debug(Boolean[][] arr){ for(int i=0;i<arr.length;i++)err.println(Arrays.toString(arr[i])); } private static void debug(int[] arr){ err.println(Arrays.toString(arr)); } private static void debug(long[] arr){ err.println(Arrays.toString(arr)); } static class FastReader{ BufferedReader br; StringTokenizer st; public FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next(){ while(st==null || !st.hasMoreTokens()){ try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt(){ return Integer.parseInt(next()); } long nextLong(){ return Long.parseLong(next()); } double nextDouble(){ return Double.parseDouble(next()); } String nextLine(){ String str=""; try { str=br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } } static class FastWriter { private final BufferedWriter bw; public FastWriter() { this.bw = new BufferedWriter(new OutputStreamWriter(System.out)); } public void print(Object object) throws IOException { bw.append("" + object); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } } static class Dsu { int[] parent, size; Dsu(int n) { parent = new int[n + 1]; size = new int[n + 1]; for (int i = 0; i <= n; i++) { parent[i] = i; size[i] = 1; } } private int findParent(int u) { if (parent[u] == u) return u; return parent[u] = findParent(parent[u]); } private boolean union(int u, int v) { // System.out.println("uf "+u+" "+v); int pu = findParent(u); // System.out.println("uf2 "+pu+" "+v); int pv = findParent(v); // System.out.println("uf3 " + u + " " + pv); if (pu == pv) return false; if (size[pu] <= size[pv]) { parent[pu] = pv; size[pv] += size[pu]; } else { parent[pv] = pu; size[pu] += size[pv]; } return true; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
9956973289959e92b50e5b0984837c13
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import javax.swing.*; import java.util.*; public class Solution { static int count; static int n; public static void main(String[] args) throws Exception { try { Scanner scan = new Scanner(System.in); int test = scan.nextInt(); for (int t = 0; t < test; t++) { int k = scan.nextInt(); n=k; int[] arr = new int[n]; for (int i = 0; i < n; i++) { arr[i] = n - i; } if (n==3){ System.out.println("3 2 1"); System.out.println("1 3 2"); System.out.println("3 1 2"); }else { for (int i = 0; i < n; i++) { rotate(arr, n - i, n - 1); rotate(arr, 0, n - i - 1); System.out.println(); } } } } catch (Exception e) { return; } } public static void rotate(int[] arr, int l, int r) { for (int i = l; i <= r&&i<n; i++) { System.out.print(arr[i] + " "); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
024b95b1f92868bcd92a08338ec9bb11
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class MainB { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); int numCases = Integer.parseInt(br.readLine()); for (int i = 0; i < numCases; i++) { int n = Integer.parseInt(br.readLine()); if (n != 3) { int[] ans = new int[n]; for (int j = 0; j < n; j++) { ans[j] = n - j; } for (int j = 0; j < n; j++) { if (j > 1) { if (ans[j - 1] + ans[j - 2] != ans[j]) { for (int k = 0; k < n; k++) { pw.print(ans[k] + " "); } pw.println(); } } else { for (int k = 0; k < n; k++) { pw.print(ans[k] + " "); } pw.println(); } if (j < n - 1) { int temp = ans[j]; ans[j] = ans[j + 1]; ans[j + 1] = temp; } } if (n % 2 == 1) { for (int j = 0; j < n; j++) { if (j == 1) pw.print(3 + " "); else if (j == 2) pw.print(2 + " "); else pw.print(j + 1 + " "); } pw.println(); } } else { pw.println("3 2 1\n" + "1 3 2\n" + "3 1 2"); } } br.close(); pw.close(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c2be7368bbdd47678ee62effb25e5fef
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.security.cert.X509CRL; import java.util.*; import java.lang.*; import java.util.stream.Collector; import java.util.stream.Collectors; @SuppressWarnings("unused") public class Main { static InputStream is; static PrintWriter out; static String INPUT = ""; static String OUTPUT = ""; //global private final static long BASE = 998244353L; private final static int ALPHABET = (int)('z') - (int)('a') + 1; //private final static int BASE = 1000000007; private final static int INF_I = (1<<31)-1; private final static long INF_L = (1l<<63)-1; private final static int MAXN = 200100; private final static int MAXK = 31; private final static int[] DX = {-1,0,1,0}; private final static int[] DY = {0,1,0,-1}; static void solve() { int ntest = readInt(); for (int test=0;test<ntest;test++) { int N = readInt(); int[] ans = new int[N]; for (int i=0;i<N;i++) ans[i] = N-i; for (int i=0;i<N;i++) out.print(ans[i] + " "); out.println(); for (int t=0;t+1<N;t++) { int tmp = ans[t]; ans[t] = ans[t+1]; ans[t+1] = tmp; for (int i=0;i<N;i++) out.print(ans[i] + " "); out.println(); tmp = ans[t]; ans[t] = ans[t+1]; ans[t+1] = tmp; } } } public static void main(String[] args) throws Exception { long S = System.currentTimeMillis(); if (INPUT=="") { is = System.in; } else { File file = new File(INPUT); is = new FileInputStream(file); } if (OUTPUT == "") out = new PrintWriter(System.out); else out = new PrintWriter(OUTPUT); solve(); out.flush(); long G = System.currentTimeMillis(); } private static class Point<T extends Number & Comparable<T>> implements Comparable<Point<T>> { private T x; private T y; public Point(T x, T y) { this.x = x; this.y = y; } public T getX() {return x;} public T getY() {return y;} @Override public int compareTo(Point<T> o) { int cmp = x.compareTo(o.getX()); if (cmp==0) return y.compareTo(o.getY()); return cmp; } } private static class ClassComparator<T extends Comparable<T>> implements Comparator<T> { public ClassComparator() {} @Override public int compare(T a, T b) { return a.compareTo(b); } } private static class ListComparator<T extends Comparable<T>> implements Comparator<List<T>> { public ListComparator() {} @Override public int compare(List<T> o1, List<T> o2) { for (int i = 0; i < Math.min(o1.size(), o2.size()); i++) { int c = o1.get(i).compareTo(o2.get(i)); if (c != 0) { return c; } } return Integer.compare(o1.size(), o2.size()); } } private static boolean eof() { if(lenbuf == -1)return true; int lptr = ptrbuf; while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false; try { is.mark(1000); while(true){ int b = is.read(); if(b == -1){ is.reset(); return true; }else if(!isSpaceChar(b)){ is.reset(); return false; } } } catch (IOException e) { return true; } } private static byte[] inbuf = new byte[1024]; static int lenbuf = 0, ptrbuf = 0; private static int readByte() { if(lenbuf == -1)throw new InputMismatchException(); if(ptrbuf >= lenbuf){ ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if(lenbuf <= 0)return -1; } return inbuf[ptrbuf++]; } private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } // private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); } private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; } private static double readDouble() { return Double.parseDouble(readString()); } private static char readChar() { return (char)skip(); } private static String readString() { int b = skip(); StringBuilder sb = new StringBuilder(); while(!(isSpaceChar(b))){ sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private static char[] readChar(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while(p < n && !(isSpaceChar(b))){ buf[p++] = (char)b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private static char[][] readTable(int n, int m) { char[][] map = new char[n][]; for(int i = 0;i < n;i++)map[i] = readChar(m); return map; } private static int[] readIntArray(int n) { int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = readInt(); return a; } private static long[] readLongArray(int n) { long[] a = new long[n]; for (int i=0;i<n;i++) a[i] = readLong(); return a; } private static int readInt() { int num = 0, b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static long readLong() { long num = 0; int b; boolean minus = false; while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')); if(b == '-'){ minus = true; b = readByte(); } while(true){ if(b >= '0' && b <= '9'){ num = num * 10 + (b - '0'); }else{ return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
ec24fdbb55f48fb0daf030a6267d409b
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class antiFib{ public int[] shift(int ar[], int rotate){ int p[] = new int[ar.length]; for(int i=0;i<ar.length-rotate; i++){ p[i+rotate] = ar[i]; } int a =ar.length-rotate; for(int i= 0; i<rotate; i++){ p[i] = ar[a]; a++; } return p; } public static void main(String args[])throws IOException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); antiFib ob = new antiFib(); int test = Integer.parseInt(br.readLine()); for(int tt=1; tt<=test; tt++){ int x = Integer.parseInt(br.readLine()); if(x!=3){ int ar[] = new int[x]; for(int i=0; i<x; i++){ ar[x-1-i] = i+1; } for(int i=0; i<x; i++){ if(i!=0){ ar = ob.shift(ar,1); } for(int k=0;k<x; k++){ System.out.print(ar[k]+" "); } System.out.println(); } } else{ System.out.println("3 2 1"); System.out.println("3 1 2"); System.out.println("2 3 1"); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
29d626ed1d6dd7ce6b35017c7c02e593
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; import java.math.*; public class Main { // -- static variables --- // static FastReader sc = new FastReader(); static PrintWriter out = new PrintWriter(System.out); static int mod = (int) 1000000007; public static void main(String[] args) throws Exception { int t = sc.nextInt(); while (t-- > 0) Main.go(); // out.println(); out.flush(); } // >>>>>>>>>>>>>>>>>>> Code Starts <<<<<<<<<<<<<<<<<<<< // static class pair { int x, y; pair(int x, int y) { this.x = x; this.y = y; } } /* * 1) Read the statements and abstract out the task. * 2)Read the constraints carefully to note some limitations. * 3)Do look at the sample values if you to be sure that what you have understood is correct. * 4)Think about the problem and see if there is a connection between any previously solved problems. * 5)Write any brute force approach first and try to optimise it. * 6)Try some elimination process, try out by taking small examples and asking question to yourself. * 7) Structure code before you write the code. * 8)Debug the code, by trying to some few more testcase. Going through the code from beginning. * 9)Don't stuck on a particular idea. * 10)Try same problem with some different idea. */ static void go() throws Exception { int n=sc.nextInt(); int a[]=new int[n]; for(int i=0;i<n;i++)a[i]=n-i; // a[0]=3; // a[1]=1;a[2]=2; int k=0; for(int i=1;i<n;i++) { for(int j=0;j<n;j++) { out.print(a[j]+" "); } out.println(); int temp=a[(k)%n]; a[(k)%n]=a[(k+1)%n]; a[(k+1)%n]=temp; k++; if(check(a)) { // out.println("->"+Arrays.toString(a)); if(i!=n-1) { temp=a[(k)%n]; a[(k)%n]=a[(k+1)%n]; a[(k+1)%n]=temp; k++; } } } a[0]=1; a[1]=3; a[2]=2; out.print(1+" "+3+" "+2+" "); for(int i=4;i<=n;i++) { out.print(i+" "); } out.println(); } static boolean check(int a[]) { for(int i=2;i<a.length;i++) { if(a[i]==a[i-1]+a[i-2]) { return true; } } return false; } static long lcm(long a, long b) { return a * b / gcd(a, b); } // >>>>>>>>>>> Code Ends <<<<<<<<< // // --For Rounding--// static double round(double value, int places) { if (places < 0) throw new IllegalArgumentException(); BigDecimal bd = new BigDecimal(Double.toString(value)); bd = bd.setScale(places, RoundingMode.HALF_UP); return bd.doubleValue(); } // ----Greatest Common Divisor-----// static long gcd(long a, long b) { if (b == 0) { return a; } return gcd(b, a % b); } // --- permutations and Combinations ---// static long fact[]; static long invfact[]; static long ncr(int n, int k) { if (k < 0 || k > n) { return 0; } long x = fact[n]; long y = fact[k]; long yy = fact[n - k]; long ans = (x / y); ans = (ans / yy); return ans; } // ---sieve---// static int prime[] = new int[1000006]; // static void sieve() { // Arrays.fill(prime, 1); // prime[0] = 0; // prime[1] = 0; // for (int i = 2; i * i <= 1000005; i++) { // if (prime[i] == 1) // for (int j = i * i; j <= 1000005; j += i) { // prime[j] = 0; // } // } // } // ---- Manual sort ------// static void sort(long[] a) { ArrayList<Long> aa = new ArrayList<>(); for (long i : a) { aa.add(i); } Collections.sort(aa); for (int i = 0; i < a.length; i++) a[i] = aa.get(i); } static void sort(int[] a) { ArrayList<Integer> aa = new ArrayList<>(); for (int i : a) { aa.add(i); } Collections.sort(aa); for (int i = 0; i < a.length; i++) a[i] = aa.get(i); } // --- Fast exponentiation ---// static long pow(long x, long y) { long res = 1l; while (y != 0) { if (y % 2 == 1) { res = (x * res); } y /= 2; x = (x * x); } return res; } // >>>>>>>>>>>>>>> Fast IO <<<<<<<<<<<<<< // 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } int[] intArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = sc.nextInt(); return a; } long[] longArray(int n) { long a[] = new long[n]; for (int i = 0; i < n; i++) a[i] = sc.nextLong(); return a; } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
94d2d1083f07cf87b519e731d17ca6b9
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.io.*; public class AntiFibonacciPermutation { public static void main(String[] args){ Kattio io=new Kattio(); int t=io.nextInt(); while(t>0) { int n=io.nextInt(); for(int i=1;i<n+1;i++) { io.print(i); for(int j=n;j>0;j--) { if(j!=i) { io.print(" "); io.print(j); } } io.print("\n"); } t--; } io.close(); } static class Kattio extends PrintWriter { private BufferedReader r; private StringTokenizer st; // standard input public Kattio() { this(System.in, System.out); } public Kattio(InputStream i, OutputStream o) { super(o); r = new BufferedReader(new InputStreamReader(i)); } // USACO-style file input public Kattio(String problemName) throws IOException { super(problemName + ".out"); r = new BufferedReader(new FileReader(problemName + ".in")); } // returns null if no more input public String next() { try { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(r.readLine()); return st.nextToken(); } catch (Exception e) { } return null; } public int nextInt() { return Integer.parseInt(next()); } public double nextDouble() { return Double.parseDouble(next()); } public long nextLong() { return Long.parseLong(next()); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
e458765e57932a775580ea7c7ab5bf4f
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.*; import java.util.*; public class example { 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader sc = new FastReader() ; long t=sc.nextLong(); while(t--!=0) { int n=sc.nextInt(); int b[]=new int[n];int y=n; if(n==3) { System.out.println(3+" "+2+" "+1); System.out.println(3+" "+1+" "+2); System.out.println(1+" "+3+" "+2); } else { for(int i=0;i<n;i++) { b[i]=y; y--; } for(int i=1;i<=n;i++) { int x=1; for(int j=0;j<x;j++){ int last; last=b[b.length-1]; for(int k1=b.length-1;k1>0;k1--) { b[k1]=b[k1-1]; } b[0]=last; } for(int m=0;m<n;m++) { System.out.print(b[m]+" "); } System.out.println(); } } } }// main method ends static boolean isPrime(long n) { // Corner cases if (n <= 1) return false; if (n <= 3) return true; // This is checked so that we can skip // middle five numbers in below loop if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } }//class ends
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
227b68fc528fb490ef08891ead6b9a35
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.util.*; public class Main { 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String[] args) { FastReader s = new FastReader(); int t = s.nextInt(); while (t-- > 0){ int n = s.nextInt(); int[] ar = new int[n]; int j = 0; for (int i = n; i > 0; i--){ ar[j++] = i; } for (int e: ar) System.out.print(e + " "); System.out.println(); int k = n-1; for (int i = k; i > 0; i--){ int temp = ar[i]; ar[i] = ar[i-1]; ar[i-1] = temp; for (j = 0; j < n; j++){ System.out.print(ar[j] + " "); } System.out.println(); } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
abb36b332fbe03d63fb0abec90bf3829
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class Anti_FibonacciPermutation { public static void main(String[] args) { Scanner sc =new Scanner(System.in); int t = sc.nextInt(); while(t--!=0) { int test = sc.nextInt(); int[] arr = new int[test]; int count = test; for(int i =0;i<arr.length;i++) { arr[i]=count--; } for(int i : arr) { System.out.print(i+" "); } // first pattern System.out.println(); int remaining = test - 1; int index = 0; while(remaining!=0) { int temp[] = arr.clone(); swap(index,index+1,temp); remaining--; index++; } } } public static void swap(int si,int ei,int arr[]) { int temp = arr[si]; arr[si] = arr[ei]; arr[ei]=temp; for(int i : arr) { System.out.print(i+" "); } System.out.println(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
60605504491152bd62e2dc9db34e9d31
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class SolnB { static boolean checkPerfectSquare(double number) { double sqrt=Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static boolean checkPerfectCube(double number) { double cbrt=Math.cbrt(number); return ((cbrt - Math.floor(cbrt)) == 0); } public static int reverseInt(int i) { int n = 0; while(i!=0) { n=n*10+i%10; i=i/10; } return n; } public static Long reverseLong(long i) { long n = 0; while(i!=0) { n=n*10+i%10; i=i/10; } return n; } public static long gcdl(long a,long b) { if(b==0) return a; return gcdl(b,a%b); } public static long gcdi(int a,int b) { if(b==0) return a; return gcdi(b,a%b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { t--; run(sc); } sc.close(); } public static void run(Scanner sc) { int n=sc.nextInt(); int[] a = new int[n]; for(int i=1;i<n+1;i++) { a[n-i]=i; } for(int j=0;j<n;j++) { System.out.print(a[j]+" "); } System.out.println(); for(int i=0;i<n-1;i++){ int t = a[i]; a[i]=a[i+1]; a[i+1]=t; for(int j=0;j<n;j++) { System.out.print(a[j]+" "); } System.out.println(); t = a[i]; a[i]=a[i+1]; a[i+1]=t; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
c052cddd428036e0cc84b688660fc20b
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class SolnB { static boolean checkPerfectSquare(double number) { double sqrt=Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static boolean checkPerfectCube(double number) { double cbrt=Math.cbrt(number); return ((cbrt - Math.floor(cbrt)) == 0); } public static int reverseInt(int i) { int n = 0; while(i!=0) { n=n*10+i%10; i=i/10; } return n; } public static Long reverseLong(long i) { long n = 0; while(i!=0) { n=n*10+i%10; i=i/10; } return n; } public static long gcdl(long a,long b) { if(b==0) return a; return gcdl(b,a%b); } public static long gcdi(int a,int b) { if(b==0) return a; return gcdi(b,a%b); } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t>0) { t--; run(sc); } sc.close(); } public static void run(Scanner sc) { int n=sc.nextInt(); int[] a = new int[n]; for(int i=1;i<n+1;i++) { a[n-i]=i; } for(int i=0;i<n;i++) { for(int j=0;j<n;j++) { System.out.print(a[j]+" "); } System.out.println(); if(i<n-1) { int t = a[0]; a[0]=a[i+1]; a[i+1]=t; } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
a746c8d07104ce2eec883d3bba5aaf16
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Test { final static FastReader fr = new FastReader(); final static PrintWriter out = new PrintWriter(System.out) ; static long mod = (long)1e9 + 7 ; static int dp[] ; static void solve() { int n = fr.nextInt(); int arr[] = new int[n] ; for (int i = 0 ; i < n ; i++){ arr[i] = n - i ; out.print(arr[i]+" "); } out.println(); int cnt = n - 1 ; int j = 1 ; while (cnt > 0){ int temp = arr[n-j] ; arr[n-j] = arr[n-j-1] ; arr[n-j-1] = temp ; for (int i = 0 ; i < n ; i++){ out.print(arr[i]+" "); } out.println(); cnt-- ; j++ ; if (j == n) j = 1 ; } } static boolean helper(int arr[]){ for (int i = 2 ; i < arr.length; i++){ if (arr[i] == arr[i-1] + arr[i-2]) return false ; } return true ; } public static void main(String[] args) { int testCases = 1 ; testCases = fr.nextInt() ; while (testCases-- > 0) { solve() ; } out.close() ; } static long getMax(long ... a) { long max = Long.MIN_VALUE ; for (long x : a) max = Math.max(x, max) ; return max ; } static long getMin(long ... a) { long max = Long.MAX_VALUE ; for (long x : a) max = Math.min(x, max) ; return max ; } static long fastPower(double a, long b) { double ans = 1 ; while (b > 0) { if ((b & 1) != 0) ans *= a ; a *= a ; b >>= 1 ; } return (long)(ans + 0.5) ; } static long fastPower(long a, long b, long mod) { long ans = 1 ; while (b > 0) { if ((b&1) != 0) ans = (ans%mod * a%mod) %mod; b >>= 1 ; a = (a%mod * a%mod)%mod ; } return ans ; } static int lower_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key) ; if (pos < 0) { pos = - (pos + 1) ; } return pos ; } static int upper_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key); pos++ ; if (pos < 0) { pos = -(pos) ; } return pos ; } static int upper_bound(int arr[], int key) { int start = 0 , end = arr.length - 1 ; int ans = -1 ; while (start <= end) { int mid = start + ((end - start) >> 1) ; if (arr[mid] == key) ans = mid ; if (arr[mid] <= key) start = mid + 1 ; else end = mid-1 ; } return ans ; } static int lower_bound(int arr[], int key) { int start = 0 , end = arr.length -1; int ans = -1 ; while (start <= end) { int mid = start + ((end - start )>>1) ; if (arr[mid] == key) { ans = mid ; } if (arr[mid] >= key){ end = mid - 1 ; } else start = mid + 1 ; } return ans ; } static class Pair{ long x; long y ; Pair(long x, long y){ this.x = x ; this.y= y ; } } static long gcd(long a, long b) { if (b == 0) return a ; return gcd(b, a%b) ; } static long lcm(long a, long b) { long lcm = a/gcd(a, b)*b ; return lcm ; } static List<Long> seive(int n) { // all are false by default // false -> prime, true -> composite int nums[] = new int[n+1] ; for (int i = 2 ; i <= Math.sqrt(n); i++) { if (nums[i] == 0) { for (int j = i*i ; j <= n ; j += i) { nums[j] = 1 ; } } } long freq[] = new long[1000001] ; freq[2] = 1 ; for (int i = 2 ; i <= n ; i++) { if (nums[i] == 0) freq[i] = freq[i-1]+1 ; else freq[i] = freq[i-1] ; } ArrayList<Long>primes = new ArrayList<>() ; for (int i = 2 ; i <=n ; i++) { if (nums[i] == 0) primes.add(i*1l) ; } return primes ; } static boolean isVowel(char ch) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true ; return false ; } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
061bace549fcaad7994db6f05dcb3255
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class Test { final static FastReader fr = new FastReader(); final static PrintWriter out = new PrintWriter(System.out) ; static long mod = (long)1e9 + 7 ; static int dp[] ; static void solve() { int n = fr.nextInt(); int arr[] = new int[n] ; for (int i = 0 ; i < n ; i++){ arr[i] = n - i ; out.print(arr[i]+" "); } out.println(); int cnt = n - 1 ; int j = 1 ; while (cnt > 0){ int temp = arr[n-j] ; arr[n-j] = arr[n-j-1] ; arr[n-j-1] = temp ; for (int i = 0 ; i < n ; i++){ out.print(arr[i]+" "); } out.println(); cnt-- ; j++ ; if (j == n) j = 1 ; } } static boolean helper(int arr[]){ for (int i = 2 ; i < arr.length; i++){ if (arr[i] == arr[i-1] + arr[i-2]) return false ; } return true ; } public static void main(String[] args) { int testCases = 1 ; testCases = fr.nextInt() ; while (testCases-- > 0) { solve() ; } out.close() ; } static long getMax(long ... a) { long max = Long.MIN_VALUE ; for (long x : a) max = Math.max(x, max) ; return max ; } static long getMin(long ... a) { long max = Long.MAX_VALUE ; for (long x : a) max = Math.min(x, max) ; return max ; } static long fastPower(double a, long b) { double ans = 1 ; while (b > 0) { if ((b & 1) != 0) ans *= a ; a *= a ; b >>= 1 ; } return (long)(ans + 0.5) ; } static long fastPower(long a, long b, long mod) { long ans = 1 ; while (b > 0) { if ((b&1) != 0) ans = (ans%mod * a%mod) %mod; b >>= 1 ; a = (a%mod * a%mod)%mod ; } return ans ; } static int lower_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key) ; if (pos < 0) { pos = - (pos + 1) ; } return pos ; } static int upper_bound(List<Integer> arr, int key) { int pos = Collections.binarySearch(arr, key); pos++ ; if (pos < 0) { pos = -(pos) ; } return pos ; } static int upper_bound(int arr[], int key) { int start = 0 , end = arr.length - 1 ; int ans = -1 ; while (start <= end) { int mid = start + ((end - start) >> 1) ; if (arr[mid] == key) ans = mid ; if (arr[mid] <= key) start = mid + 1 ; else end = mid-1 ; } return ans ; } static int lower_bound(int arr[], int key) { int start = 0 , end = arr.length -1; int ans = -1 ; while (start <= end) { int mid = start + ((end - start )>>1) ; if (arr[mid] == key) { ans = mid ; } if (arr[mid] >= key){ end = mid - 1 ; } else start = mid + 1 ; } return ans ; } static class Pair{ long x; long y ; Pair(long x, long y){ this.x = x ; this.y= y ; } } static long gcd(long a, long b) { if (b == 0) return a ; return gcd(b, a%b) ; } static long lcm(long a, long b) { long lcm = a/gcd(a, b)*b ; return lcm ; } static List<Long> seive(int n) { // all are false by default // false -> prime, true -> composite int nums[] = new int[n+1] ; for (int i = 2 ; i <= Math.sqrt(n); i++) { if (nums[i] == 0) { for (int j = i*i ; j <= n ; j += i) { nums[j] = 1 ; } } } long freq[] = new long[1000001] ; freq[2] = 1 ; for (int i = 2 ; i <= n ; i++) { if (nums[i] == 0) freq[i] = freq[i-1]+1 ; else freq[i] = freq[i-1] ; } ArrayList<Long>primes = new ArrayList<>() ; for (int i = 2 ; i <=n ; i++) { if (nums[i] == 0) primes.add(i*1l) ; } return primes ; } static boolean isVowel(char ch) { if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') return true ; return false ; } 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()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
4d46e138c5a2b666cfecdf44b98a21fa
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class test { public static void main(String[] args) throws java.lang.Exception { Scanner scanner = new Scanner(System.in); Integer len = scanner.nextInt(); for (int j = 0; j < len; j++) { Integer n = scanner.nextInt(); Integer m = n; int count = 0; for (int k = 0; k < n; k++) { boolean started = false; if (!(n%2 !=0 && k == (n/2)+1)) { started = true; for (int i = n; i > 0; i--) { if(n-i < k){ System.out.print(Integer.valueOf(i-1) +" "); } else if (n-i == k) { System.out.print(n+" "); } else { System.out.print(i+" "); } } } if (started) { count = count + 1; System.out.print("\n"); } } if (count < m) { n = n-1; for (int k = 1; k < n; k++) { boolean started = false; if (count == m){ break; } if (!(n%2 !=0 && k == (n/2)+1)) { started = true; System.out.print(m+" "); for (int i = n; i > 0; i--) { if(n-i < k){ System.out.print((String.valueOf(i-1) +" ")); } else if (n-i == k) { System.out.print(n+" "); } else { System.out.print(i+" "); } } } if (started) { count = count + 1; System.out.print("\n"); } } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
fec59ae9cba0016fa3268cf43b943b5a
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; public class solution { public static void main (String[] args) throws java.lang.Exception { // your code goes here Scanner scn = new Scanner(System.in); int t = scn.nextInt(); while(t-->0){ int n = scn.nextInt(); int[] arr = new int[n]; for(int i = 0;i<n;i++){ arr[i] = n-i; } print(arr); for(int i = 0;i<n-2;i++){ swap(arr,i,i+1); print(arr); } if(n==3) swap(arr,n-3,n-1); else{ swap(arr,n-2,n-1); } print(arr); } } public static void swap(int[] arr,int i,int j){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; if(i+2<arr.length&&arr[i]+arr[i+1]==arr[i+2]){ swap(arr,i,i+2); } if(i-1 >=0 && arr[i-1]+arr[i]==arr[i+1]){ swap(arr,i-1,i+1); } } public static void print(int[] arr){ for(int val:arr){ System.out.print(val+" "); } System.out.println(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
a69dd22d7f73a65e2d6f35b59c9084f5
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
//package com.codeforces.ERound123; import java.io.*; public class pr02 { public static void main(String[] args)throws IOException { Reader scan=new Reader(); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); int t=scan.nextInt(); while (t-->0) { int n = scan.nextInt(); if(n==3){ bw.write("3 2 1"); bw.newLine(); bw.write("1 3 2"); bw.newLine(); bw.write("3 1 2"); bw.newLine(); bw.flush(); continue; } int[] arr=new int[n]; int p=0; for (int i = n; i >=1 ; i--) { arr[p++]=i; bw.write(arr[p-1]+" "); } bw.newLine(); for (int i = 1; i <= n-1; i++) { int temp=arr[n-1]; for (int j = n-1; j >=1; j--) { arr[j]=arr[j-1]; } arr[0]=temp; for (int j = 0; j < n; j++) { bw.write(arr[j]+" "); } bw.newLine(); } bw.flush(); } } //FAST READER static class Reader { public int BS = 1<<16; public char NC = (char)0; byte[] buf = new byte[BS]; int bId = 0, size = 0; char c = NC; double num = 1; BufferedInputStream in; public Reader() { in = new BufferedInputStream(System.in, BS); } public Reader(String s) throws FileNotFoundException { in = new BufferedInputStream(new FileInputStream(new File(s)), BS); } public char nextChar(){ while(bId==size) { try { size = in.read(buf); }catch(Exception e) { return NC; } if(size==-1)return NC; bId=0; } return (char)buf[bId++]; } public int nextInt() { return (int)nextLong(); } public long nextLong() { num=1; boolean neg = false; if(c==NC)c=nextChar(); for(;(c<'0' || c>'9'); c = nextChar()) { if(c=='-')neg=true; } long res = 0; for(; c>='0' && c <='9'; c=nextChar()) { res = (res<<3)+(res<<1)+c-'0'; num*=10; } return neg?-res:res; } public double nextDouble() { double cur = nextLong(); return c!='.' ? cur:cur+(cur < 0 ? -1*nextLong()/num : nextLong()/num); } public String next() { StringBuilder res = new StringBuilder(); while(c<=32)c=nextChar(); while(c>32) { res.append(c); c=nextChar(); } return res.toString(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
cccf8634dc74c0be60f3959dd47433e6
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class Main{ public static void main (String[] args) throws java.lang.Exception{ Scanner scn = new Scanner(System.in); int t = scn.nextInt(); for(int k =0 ; k < t ;k++){ int n = scn.nextInt(); int[]arr = new int[n]; for(int i =1 ; i < n ;++i){ arr[i] = n - i + 1; } find(arr); } } public static void find(int[]arr){ arr[0] = 1; for(int i =0 ;i < arr.length -1 ;i++){ use(arr); swap(i , i + 1 , arr); } use(arr); } public static void use(int[]arr){ for(int i = 0 ; i < arr.length ;i++){ System.out.print(arr[i] + " "); } System.out.println(); } public static void swap(int i , int j , int[]arr){ int temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
5be9576ee3f1eee77c01607b94447b10
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class antifib{ public static void main(String[] args){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0){ int n=sc.nextInt(); if(n>2){ int arr[]=new int[n]; for(int i=0;i<n;i++){ arr[i]=n-i; } for(int i=0;i<n;i++){ System.out.print(arr[i]+" "); } System.out.println(); for(int i=n-1;i>0;i--){ int temp=arr[i]; arr[i]=arr[i-1]; arr[i-1]=temp; for(int j=0;j<n;j++){ System.out.print(arr[j]+" "); if(j<n-2){ if(arr[j]+arr[j+1]==arr[j+2]) System.out.println("Pap ho gya"); } } System.out.println(); } } } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
86736e236279ab3f28c3cae3ad7311f5
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; public class AntifibonacciNumbers { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); for(int i = n;i>=1;i--) arr.add(i); for(int i = n-1;i>=1 ;i--){ for(int j = 0;j< n ; j++) System.out.print(arr.get(j)+" "); System.out.println(); Collections.swap(arr,i,i-1); } // Collections.swap(arr, n-2, n-1); for(int j = n-1;j>= 0 ; j--) System.out.print(arr.get(j)+" "); System.out.println(); } } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output
PASSED
0819f7fdb57d04856815f70e25996efd
train_108.jsonl
1645540500
Let's call a permutation $$$p$$$ of length $$$n$$$ anti-Fibonacci if the condition $$$p_{i-2} + p_{i-1} \ne p_i$$$ holds for all $$$i$$$ ($$$3 \le i \le n$$$). Recall that the permutation is the array of length $$$n$$$ which contains each integer from $$$1$$$ to $$$n$$$ exactly once.Your task is for a given number $$$n$$$ print $$$n$$$ distinct anti-Fibonacci permutations of length $$$n$$$.
256 megabytes
import java.util.*; import java.lang.*; import java.io.*; public class div2 { public static void main(String[] args) throws IOException { Reader sc=new Reader(); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int a[]=new int[n]; int p=0; for(int i=n-1;i>=0;i--) { a[p++]=i+1; } if(n==3) { System.out.println("3 2 1"); System.out.println("1 3 2"); System.out.println("2 3 1"); } else { int temp=0; while(temp<n) { for(int i=n-temp;i<n;i++) { System.out.print(a[i]+" "); } for(int j=0;j<n-temp;j++) { System.out.print(a[j]+" "); } System.out.println(); temp++; } } } } private static void swap(int[] a, int i, int j) { int t=a[i]; a[i]=a[j]; a[j]=t; } private static boolean pal(String con1) { int i=0,j=con1.length()-1; while(i<=j) { if(con1.charAt(i)!=con1.charAt(j)) { return false; } i++; j--; } return true; } } class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(String file_name) throws IOException { din = new DataInputStream( new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') { if (cnt != 0) { break; } else { continue; } } buf[cnt++] = (byte)c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') { c = read(); } boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.close(); } }
Java
["2\n\n4\n\n3"]
2 seconds
["4 1 3 2\n1 2 4 3\n3 4 1 2\n2 4 1 3\n3 2 1\n1 3 2\n3 1 2"]
null
Java 11
standard input
[ "brute force", "constructive algorithms", "implementation" ]
85f0621e6cd7fa233cdee8269310f141
The first line contains a single integer $$$t$$$ ($$$1 \le t \le 48$$$) — the number of test cases. The single line of each test case contains a single integer $$$n$$$ ($$$3 \le n \le 50$$$).
800
For each test case, print $$$n$$$ lines. Each line should contain an anti-Fibonacci permutation of length $$$n$$$. In each test case, you cannot print any permutation more than once. If there are multiple answers, print any of them. It can be shown that it is always possible to find $$$n$$$ different anti-Fibonacci permutations of size $$$n$$$ under the constraints of the problem.
standard output