Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int v[100005] = {0}; int q[100005] = {0}; int main() { int n; scanf("%d", &n); memset(v, -1, sizeof(v)); if ((n - (n % 2)) % 4) { printf("-1\n"); return 0; } int cur = 0; int sz = 1; for (int i = 0; i < n / 2; i += 2) { q[cur] = i; v[i] = 0; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.*; import java.util.*; public class A { public static void main(String[] args) { new A().run(); } BufferedReader br; StringTokenizer in; PrintWriter out; public String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) { in = new StringTokenizer(br.readLine()); }...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int arr[100005]; int main() { memset(arr, -1, sizeof arr); int n; cin >> n; if (n & 1) arr[n / 2 + 1] = n / 2 + 1; for (int i = 1; i < n / 2; i += 2) { arr[i] = i + 1; arr[i + 1] = n - i + 1; arr[n - i] = i; arr[n - i + 1] = n - i; } for (int i...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import sys n = int(sys.stdin.read().strip()) if n == 1: res = [1] elif n % 4 in [2, 3]: res = [-1] elif n % 4 == 1: res = [0] * n for i in xrange(0, n, 2): res[i] = i+2 for i in xrange(1, n, 2): res[i] = n-i-1 for i in xrange(n/2, n, 2): res[i] -= 2 for i in xrange(...
PYTHON
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.*; import java.math.*; import java.io.*; public class A{ static FastReader scan=new FastReader(); public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); static LinkedList<Edge>edges[]; static boolean stdin = true; static String filein = "input"; static S...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
a = [0]*100010 n = int(raw_input()) if n % 4 > 1: print '-1' else: stpos = 1 edpos = n-1 stval = 2 edval = 1 cnt = n/4 for i in range(cnt): a[stpos] = stval a[edpos] = edval a[stpos+1] = n +2 - stval a[edpos+1] = n - edval stpos += 2 edpos -= ...
PYTHON
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
n = input() p = [] for i in range(0, n / 2, 2): p += [i + 2, n - i] if n % 4: p += [n / 2 + 1] for i in range(n / 2 - 1, 0, -2): p += [i, n - i] if n % 4 > 1: p = [-1] print ' '.join(map(str, p))
PYTHON
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.io.IOException; import java.io.InputStreamReader; import java.io.File; import java.io.FileNotFoundException; import java.util.StringTokenizer; import java.io.Writer; ...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author vadimmm */ public class Mai...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> long a[110000]; int main() { int n, i, j; scanf("%d", &n); if ((n % 4) > 1) { printf("-1\n"); } else { for (i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i] = i; a[n - i + 1] = n - i; } if ((n % 2) == 1) { a[n / 2 + ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.Scanner; public class CodeForces { public static void main(String[] args) { Scanner s = new Scanner(System.in); while (s.hasNext()) { int n = s.nextInt(); int[] p = new int[n+1]; p = getLuckyPerm(p, n); if (p[0] == 0) { System.out.println("-1"); } else { for (int i=1; i...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> const int N = 100100; using namespace std; int n, p[N]; int l; void dfs(int x) { p[p[x]] = n - x + 1; int y = p[x]; while (y != x) { p[p[y]] = n - y + 1; y = p[y]; } } int main() { ios_base::sync_with_stdio(0); cin >> n; if (n % 2) p[n / 2 + 1] = n / 2 + 1; for (int i = ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int n, t, a[110000], tnum, cas; int main() { cas = 0; scanf("%d", &n); if (n == 1) { printf("1\n"); } else { if (n % 2 != 0) { a[(n / 2) + 1] = (n / 2) + 1; tnum = n - 1; } else { tnum = n; } if (tnum % 4 != 0) { printf("-1\n"); } else { ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.StreamTokenizer; public class C { static StreamTokenizer st; static PrintWriter pw; private static int nextInt...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; bool flag[20]; int ans[20]; bool dfs(int k, int n) { if (k > n) { bool temp = true; for (int i = 1; i <= n; i++) if (ans[ans[i]] != n - i + 1) temp = false; if (temp) { for (int i = 1; i <= n; i++) printf("%d ", ans[i]); printf("\n"); r...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } int ans[n + 10]; if (n % 4 == 1) { ans[n / 2 + 1] = n / 2 + 1; } for (int i = 1; i < n / 2; i += 2) { ans[i] = i + 1; ans[i + 1] = n + 1 - i; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } int lo, hi; int A[100006]; lo = 1; hi = n; while (lo < hi) { A[lo] = lo + 1; A[lo + 1] = hi; A[hi] = hi - 1; A[hi - 1] = lo; lo += ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int a[100001]; int main() { int n, i; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) printf("-1\n"); else { for (i = 1; i <= n / 2; i = i + 2) { a[i] = i + 1; a[i + 1] = n + 1 - i; a[n - i] = i; a[n + 1 - i] = n - i; } if (n % 4 == 1) a[i] = i; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { int n; cin >> n; if (n % 4 >= 2) return puts("-1"), 0; for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[n - i] = i; } if (n % 2 == 1) a[n / 2 + 1] = n / 2 + 1; for (in...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int a[100005], n; bool tui() { int nd2 = n / 2, w = 2; if (n % 4 == 0) { for (int i = 1; i <= nd2; i += 2) { a[i] = w, a[i + 1] = n + 2 - w; w += 2; } w = nd2 - 1; for (int i = nd2 + 1; i <= n; i += 2) { a[i] = w, a[i + 1] = n - w, w -=...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int p[100009], n, s, t, i; bool none = false; int main() { scanf("%d", &n); for (s = 1, t = n; s <= t;) { if (t - s + 1 >= 4) { p[s] = s + 1; p[s + 1] = t; p[t] = t - 1; p[t - 1] = s; s += 2; t -= 2; } else { if (t - s + 1 >= 2) { no...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
n = input() if 2 == n % 4 or 3 == n % 4: print -1 exit() cnt4 = n / 4 a = [0] * n i = 0 while cnt4 > 0: cnt4 -= 1 a[i] = i + 2 a[i + 1] = n - i a[n - 1 - i] = n - i - 1 a[n - 2 - i] = i + 1 i += 2 if 1 == n % 4: a[i] = i + 1 for x in a: print x,
PYTHON
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int a[100009]; bool FL; void f(int st, int en, int i, int j) { if (st > en) return; if (st == en) a[i] = st; else { if ((j - i) == 1 || (j - i) == 2) { FL = false; return; } a[i] = st + 1; a[i + 1] = en; a[j] = en - 1; a[j - 1] ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
n = int(input()) if n%4 > 1: print(-1) exit() a = [(n+1) // 2] * n for i in range(n//4): j = 2*i a[j], a[j+1], a[-j-2], a[-j-1] = j+2, n-j, j+1, n-j-1 print(' '.join(map(str, a)))
PYTHON3
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; long long int inf = 1e14; long long int mod = 1e9 + 7; char en = '\n'; long long int arr[300005]; long long int res[300005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); memset(arr, 0, sizeof(arr)); long long int n; cin >> n; if ((n % 4 == 2) or...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.*; import java.util.*; public class Main { private InputStream is; private PrintWriter out; int time = 0, val[][], dp[][], DP[], start[], end[], dist[], black[], MOD = (int)(1e9+7), arr[], weight[][], x[], y[], parent[]; int MAX = 800000, N, K; long red[]; ArrayList<Integer>[] amp...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int n, x, y, a[100010]; int main() { scanf("%d", &n); if (n % 4 != 0 && n % 4 != 1) { printf("-1"); return 0; } for (int i = 1; i <= n / 2; i += 2) { int x = i, y = i + 1; for (int j = 1; j <= 4; j++) { a[x] = y; y = n - x + 1; x = ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int a[1000000 + 10]; void dfs(int l, int r) { if (r - l + 1 < 4) return; a[l] = l + 1; a[l + 1] = r; a[r] = r - 1; a[r - 1] = l; dfs(l + 2, r - 2); } int main() { int xiaohao; int zheshixiaohao; int n; cin >> n; if (n == 1) { cout << "1"; } if ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
//package round176; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A { InputStream is; PrintWriter out; String INPUT = ""; void solve() { int n = ni(); if(...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { long time = System.nanoTime(); int n = next(); if (n % 4 == 2 || n % 4 == 3) { out.println(-1); out.close(); return; } int[] x = new int[n]; for (int i = 0; 2*i + 1 < n; i += 2)...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.Scanner; public class c_176 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if ((n-1) % 4 == 1 || (n-1) % 4 == 2) { System.out.println(-1); return; } if (n % 2 == 0) { for (int i = 2; i <= n / 2; i += 2) { System.out.print(i...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
n=int(input()) if n%4>1:print(-1) else: ans=[i for i in range(1,n+1)] for i in range(0,n//2,2): ans[i]=i+2 ans[i+1]=n-i ans[n-i-1]=n-i-1 ans[n-i-2]=i+1 print(*ans)
PYTHON3
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int a[100001]; int main() { int i, j, k, m, n; cin >> n; if (n % 4 > 1) { cout << "-1" << endl; return 0; } int _front = 0, end_ = n - 1; list<int> L; for (i = 1; i <= n; i++) L.push_back(i); while (!L.empty()) { if (_front == end_) { a[end...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int i, n; bool was[1000001]; vector<int> ans, a; int main() { cin >> n; for (i = 1; i <= n; i += 2) { if (i + 1 > n - i + 1) break; ans.push_back(i + 1); ans.push_back(n - i + 1); was[i + 1] = was[n - i + 1] = true; } for (i = 1; i <= n; i++) { i...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 2e1 + 4; vector<int> circle; bool vis[N]; int parent[N]; int chk[N]; int color[N]; int tim[N]; int dis[N]; int position[N]; vector<int> adj[N]; vector<int> adj1[N]; vector<int> graph[N]; bool has_cycle; int maxdis, maxnode, Totnode, depth...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int a[100005]; int main() { int n, i; while (~scanf("%d", &n)) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } else { for (i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[n - i] ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; long a[100005]; int main(void) { long n; cin >> n; if (n == 1) cout << "1" << endl; else if (n % 4 == 0) { for (int i = 1; i <= n / 2; i += 2) a[n - i] = i; for (int i = 2; i <= n / 2; i += 2) a[i - 1] = i; for (int i = n; i > n / 2; i -= 2) a[n + 2 ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int n; void solve() { if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; return; } if (n == 1) { cout << 1 << endl; return; } cout << 2 << ' ' << n; for (int i = 1; i < n / 4; ++i) cout << ' ' << 2 * (i + 1) << ' ' << (n - 2 * i); if (n & ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.*; import java.math.BigInteger; import java.util.*; public class A { int[] doit(int n){ int[] a=new int[n]; int count=0; int cur=0; int x=0; int val=2; if(n==1)val=1; while(count!=n){ while(a[x]==0){ a[x]=val; ...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
n = int(raw_input()) if n%4 in [0,1]: p = range(n) l = [(i,n-i-1) for i in xrange(n/2)] while l: (a,b),(c,d) = l.pop(),l.pop() p[a] = c p[c] = b p[b] = d p[d] = a print ' '.join(str(x+1) for x in p) else: print -1
PYTHON
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int n; int *a; void foo(int k, int i) { a[i] = k; a[k] = n - i + 1; a[n - k + 1] = i; a[n - i + 1] = n - k + 1; } void Zero() { for (int i = 1; i <= n; ++i) { a[i] = 0; } } void Print() { for (int i = 1; i <= n; ++i) { cout << a[i] << " "; } } int ma...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 300; const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; int n, p[110000]; int main() { cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; return 0; } for (int i = n; i > n / 2 + 1; i -= 2) { p[i] = i - 1; p[i - 1...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.Arrays; import java.util.Scanner; public class LuckyPermutation { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); sc.close(); int[] numeros = new int[n + 1]; Arrays.fill(numeros, 0); if (n%4 > 1){ System.out.println(-1); return; ...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; Outpu...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int oo = 0x3f3f3f3f; long long mod = 1e9 + 7; double eps = 1e-9; double pi = acos(-1); long long fastpower(long long b, long long p) { double ans = 1; while (p) { if (p % 2) { ans = (ans * b); } b = b * b; p /= 2; } return ans; } bool val...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int a[111111]; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) printf("-1\n"); else { int b = 1, e = n, mn = 1, mx = n; while (e - b + 1 >= 4) { a[b] = mn + 1; a[b + 1] = mx; a[e - 1] = mn; a[e] = mx - 1; b += 2; e -= 2;...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int size = 100008; int p[size], n; void dfs_p(int i, int x) { if (x > 4) return; p[p[i]] = n - i + 1; dfs_p(p[i], x + 1); } int main() { int k, i, j, id; while (cin >> n) { memset(p, 0, sizeof(p)); if (n % 4 == 0 || n % 4 == 1) { k = n / 4; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int oo = 2000000009; const int mx = 100005; int mustbe[mx], p[mx], n; void solve(int a, int b) { if (b - a < 0) return; if (b - a == 0) { p[a] = a; return; } p[a] = a + 1; p[a + 1] = b; p[b - 1] = a; p[b] = b - 1; solve(a + 2, b - 2); } int mai...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; long long n, a[((long long)101 * 1000)], p[((long long)101 * 1000)]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; if (n == 2 || n % 4 == 3 || n % 4 == 2) return cout << -1, 0; for (int i = 1, l = 1, r = n; i <= n - (n % 2); l += ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class A { BufferedReader reader; StringTokenizer tokenizer; PrintWriter out; public void solve() throws IOException { int N = nextInt(...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int a[n + 1]; if (n % 4 > 1) cout << -1 << endl; else { for (int i = 1; i < n / 2; i += 2) a[i] = i + 1, a[n - i + 1] = n - i, a[i + 1] = n - i + 1, a[n - i] = i; if (n % 4 ==...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.*; public class LuckPerm286A { public static void main(String[] args) { // Set up scanner Scanner sc = new Scanner(System.in); // System.out.println("Enter n"); int n = sc.nextInt(); if (n==1) { System.out.println(1); ...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793238; template <typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vector) { for (size_t i = 0; i < vector.size(); ++i) { os << vector[i] << " "; } return os; } vector<int> FindHappyPermutaion(int n) { ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010 * 2; int p[MAXN]; int main() { int N; cin >> N; if (N % 4 > 1) puts("-1"); else { for (int i = 1; i * 2 < N; i += 2) { p[i] = i + 1; p[i + 1] = N + 1 - i; p[N + 1 - i] = N - i; p[N - i] = i; } if (N % 2...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; template <class T> T _max(T a, T b) { return a > b ? a : b; } template <class T> T _min(T a, T b) { return a < b ? a : b; } int sgn(const double &x) { return (x > 1e-8) - (x < -1e-8); } int a[100010]; int main() { int n; cin >> n; if (n % 4 > 1) { puts("-1"); ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } const int INF = 1 << 29; inline int two(int n) { return 1 << n; } inline int test(int n, int b) { return (n >> b) & 1; } inline void set_bit(int& n, int b) { n |= two(b); } inline void unset_bit(int& n, int b...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
n = int(input()) if n % 4 > 1: print(-1) exit() a = [i for i in range(0, n+1)] for i in range(1, n//2+1, 2): p, q, r, s = i, i+1, n-i,n-i+1 a[p], a[q], a[r], a[s] = a[q], a[s], a[p], a[r] def check(arr): for i in range(1, n+1): k = arr[i] if arr[arr[k]] != n-k+1: ...
PYTHON3
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package luckyperm; import java.util.Scanner; /** * * @author admin */ public class Main { /** * @param args the command line arguments */ public static void main(String[] args) { // TOD...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int main(void) { int n; cin >> n; if ((n - (n & 1)) % 4 != 0) cout << -1; else { set<int> disp; int v[n + 1], k = 1; memset(v, -1, sizeof v); for (int i = 1; i <= n; i++) disp.insert(i); if (n & 1) { v[(n + 1) / 2] = (n + 1) / 2; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int a[1000001], n; int main() { cin >> n; if ((n / 2) % 2) { cout << -1 << endl; return 0; } int l = 2, r = n; for (int i = 1; i <= n / 2; i++) { if (i % 2) a[i] = l, a[n - i] = l - 1, l += 2; else a[i] = r, a[n - i + 2] = r - 1, r -= 2...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.Scanner; public class C { public static void main(String args[]){ Scanner in = new Scanner(System.in); int n=in.nextInt(); int a[]=new int[n+1]; boolean b[]=new boolean[n+1]; a[n-1]=1; b[n-1]=true; if(n%4==0 || n%4==1 ){ for(int j=0;j<n/2;j+=2){ a[j+1]=j+2; a[...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
n = int(input()) p = [0] * n if n == 1: print(1) exit() for sh in range(n // 4): p[n - sh * 2 - 2] = n - sh * 2 p[sh * 2] = n - 1 - sh * 2 p[n - sh * 2 - 1] = 2 + sh * 2 p[sh * 2 + 1] = 1 + sh * 2 if n % 4 == 1: p[n // 2] = n // 2 + 1 if n % 4 == 2: print(-1) exit() if n % 4 == ...
PYTHON3
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author ocelopilli */ public class ...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.*; public class SinIsh { public static void main(String [] args){ Scanner in = new Scanner(System.in); int n=in.nextInt(); int array[]=new int[n]; boolean flag=false; if(n==1) System.out.print("1"); else if(n%4==3||n%4==2) System.out.print("-1"); else{ if(n%4==1) flag=true; for(int i=0;i<n/2;i+=2){ arr...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class ProblemA { public static void main(String[] args) throws IOException { Problem...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
def main(): n = int(raw_input()) a = [0] * (n+1) if n % 4 > 1: print -1 return for y in xrange(n/4): x = y * 2 a[x+1] = x+2 a[x+2] = n-x a[n-x] = n-x-1 a[n-x-1] = x+1 if n % 4 == 1: a[(n+1)/2] = (n+1)/2 for x in a[1:]: print...
PYTHON
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int p[100001]; bool v[100001]; int main() { int n; scanf("%d", &n); int fill = 1; int c = 0; while (fill <= n) { while (p[fill] != 0 && fill <= n) fill++; if (fill > n) break; if (c == n - 1) { p[fill] = fill; if (n - fill + 1 == fill) c++; break; } ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; char f(vector<int> a) { int n = a.size() - 1; for (int i = 1; i <= n; i++) if (a[a[i]] != n - i + 1) return false; return true; } int main() { int n; scanf("%d", &n); vector<int> a(n + 1, -1); a[1] = 2; a[n - 1] = 1; a[n] = n - 1; if (n % 2 == 0) { ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int p[100002]; int vis[100002]; int main() { int n; while (scanf("%d", &n) != EOF) { if (n % 4 != 0 && n % 4 != 1) { printf("-1\n"); continue; } else { memset(vis, 0, sizeof(vis)); for (int i = 1; i <= n / 2; i++) { if (vis[i] == 0) { p[i] =...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 100100; int p[N]; int main() { int n; cin >> n; int t = n % 4; if (t < 2) { if (t == 1) { p[n / 2 + 1] = n / 2 + 1; } for (int i = 1; 2 * i <= n; i += 2) { p[i] = i + 1; p[i + 1] = n - i + 1; p[n - i + 1] = n - i; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; public class A { final static boolean autoflush = false; public A () { int N = sc.nextInt(); int [] res = new int [N]; switch(N%4) { case 1: res[(N-1)/2] = (N-1...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.*; import java.util.*; import java.math.*; public class A implements Runnable { static BufferedReader in; static PrintWriter out; static StringTokenizer st; static Random rnd; void solve() throws IOException { int n = nextInt(); if (n == 1) { out.println(1); } else if (n == 2) { out.p...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } template <typename T> inline T gcd(T a, T b) { if (b == 0) return a; else return gcd(b, a % b); } template <typename T> inline T lcm(T a, T b) { return (a * b) / gcd(a, b); } template <typename ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int p[200000]; int pp[200000]; int a[200000]; int n; bool f() { for (int(i) = (0); (i) < (n); ++(i)) if (a[a[i + 1]] != n - i) return 0; return 1; } void ff(int id, int x) { if (a[id]) return; a[id] = x; ff(x, n - id + 1); } int main() { cin >> n; if (n ==...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; long long k, a, b; int main() { long long n; cin >> n; long long ans[100000 + 1] = {}; if (n % 4 == 1) { ans[(n + 1) / 2] = (n + 1) / 2; long long mid = (n + 1) / 2; for (long long i = 1; i <= (n + 1) / 2; i++) { if (i % 2) { ans[mid - i] =...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int m, n; int a[100050]; int main() { int i, j, k, x, y, z; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) puts("-1"); else { j = n; i = 1; while (j >= i) { if (j == i) a[i] = i; else { a[i] = i + 1; a[i + 1] = j; a[j] = n - i;...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, Mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; if (n % 4 > 1) cout << "-1\n", exit(0); int Arr[n + 2]; if (n & 1) Arr[n / 2 + 1] = n / 2 + 1; for (int i = 1; i <= n / 2; i += 2) { ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; #pragma comment(linker, "/STACK:102400000,102400000") inline void read(int &x) { x = 0; char ch = getchar(); while (ch < '0') ch = getchar(); while (ch >= '0') { x = x * 10 + ch - 48; ch = getchar(); } } int a[100010], ans; bool f[100010]; int main() { i...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int p[100005]; bitset<100005> viz, ap; int main() { int n, sf; cin >> n; sf = n; if (n == 1) { cout << 1; return 0; } if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } for (int i = 1; i <= n; ++i) if (viz[i] == 0) { if (!(n % ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
# Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase from collections import deque def main(): n=int(input()) if n%4==2 or n%4==3: print(-1) else: a=deque(list(range(1,n+1))) ans=[0]*n for i in range(0,n//2,2): ...
PYTHON3
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.*; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.StringTokenizer; public class C implements Runnable { // leave empty to read from stdin/stdout private static final String TASK_NAME_FOR_IO = ""; // file names p...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int p[100005]; int main() { int n; scanf("%d", &n); memset(p, 0, sizeof(p)); if (n == 1) { printf("1\n"); return 0; } if (n == 2 || n == 3 || n % 4 == 3 || n % 4 == 2) { printf("-1\n"); return 0; } if (n >= 4) { for (int i = 1; i <= n / 4; i++) { p[2 * ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.*; public class Main { public static void main(String args[]) { (new Main()).solve(); } void solve() { Scanner cin = new Scanner(System.in); while( cin.hasNextInt() ) { int N = cin.nextInt(); if( N % 4 >= 2 ) { System.out.println(-1); continue; ...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int a[100010]; int main() { int i, j, k = 1, n, m; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1\n"; return 0; } for (i = 0; i < n / 4; i++) { int x = 2 * i + 1; a[x] = x + 1; a[n - x] = x; a[n + 1 - x] = n - x; a[x + 1] = n + 1...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.*; import java.util.*; public class z3 { public static void wiw(long a,long b) { if (a<=b) {if (a==b) System.out.print(""+a+" "); else { System.out.print(""+(a+1)+" "+b+" "); wiw(a+2,b-2); System.out.print(""+(a)+" "+(b-1)+" "); }} } public static void main(String[] args) throws IOExcep...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, i; int num1, num2, cnt; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } if (n % 4 == 0) { cnt = n / 2; num1 = 2, num2 = n; while (num1 <= cnt) { cout << num1 << " " << num2 << " "; num1 += 2, num2 -= 2; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int output[100010]; int main() { int n; while (cin >> n) { if (n % 4 == 2 || n % 4 == 3) cout << -1 << endl; else { int front1 = 2, front2 = n, rear1 = n - 1, rear2 = 1; int i, count = 0; for (i = 1; count < n / 4; i += 2) { outpu...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.InputStreamReader; import java.io.IOException; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author ocelopilli */ public class ...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; long long Set(long long N, long long pos) { return N = N | (1 << pos); } long long reset(long long N, long long pos) { return N = N & ~(1 << pos); } bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); } void CI(long long &_x) { scanf("%d", &_x); } void C...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; long long n, i, f, m, a[211111], ans; vector<long long> v; double d; int main() { cin >> n; if (n == 1) cout << 1; else if (n % 4 == 2 || n % 4 == 3) cout << -1; else { for (i = 0; i < n / 2; i++) { if (i % 2 == 0) { a[i] = i + 1; a...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int arr[100100]; int main() { int n; cin >> n; if (n == 1) { cout << "1" << endl; return 0; } memset(arr, 0, sizeof(arr)); bool f = true; int k = 0; if (n % 2) arr[n / 2 + 1] = n / 2 + 1; for (int i = 1; i <= n; i++) { if (arr[i] == 0 && k < n ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> int main() { int n, k = 1, i, j, a[100001]; scanf("%d", &n); if (n == 1) { printf("1"); return 0; } k = n / 2; for (i = 1, j = n; i < j; i++, j--) { if (i % 2 == 0) { a[i] = k; a[j] = n - k + 1; } else { a[i] = n - k + 1; a[j] = k; } k...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int v[100001]; int main() { int i, f, n; cin >> n; if (n % 4 == 2 || n % 4 == 3) cout << -1 << endl; else { if (n % 4 == 1) v[(n + 1) / 2] = (n + 1) / 2; i = 1; f = n; while (i < f) { v[i] = f - 1; v[f - 1] = f; v[f] = i + 1; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; int p[MAXN]; int ans[MAXN]; int l, r; void put_left(int x) { ans[l] = x; ++l; } void put_right(int x) { ans[r] = x; --r; } int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { puts("-1"); return 0; } l = 0, ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; int n, p[1010000]; int main() { cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; exit(0); } if (n % 4 == 0) { for (int i = 1; i <= n / 2; i++) { if (i % 2 == 1) p[i] = i + 1, p[n + 1 - i] = n - i; else p[i] = n + 2 - i, p...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.util.Scanner; import java.io.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author Dzmitry Paulenka */ public class Main { public static void main(String[] args) { InputSt...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 100; const int mod = 1e9 + 7; int p[maxn]; bool mark[maxn]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; if (n % 4 > 1) return (cout << -1, 0); if (n % 4 == 1) p[n / 2 + 1] = n / 2 + 1; for (...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; const double infd = 2e+9; const int infi = INT_MAX; template <class T> inline T sqr(T x) { return x * x; } int main() { ios_base::sync_with_stdio(false); int n; cin >> n; if (n % 4 != 0 && n % 4 != 1) { cout << -1; ...
CPP
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class P286A_LuckyPermutation { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(in.read...
JAVA
287_C. Lucky Permutation
A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≀ pi ≀ n). A lucky permutation is such permutation p, that any integer i (1 ≀ i ≀ n) meets this condition ppi = n - i + 1. You have integer n. Find some lucky permutation p of size n. Input T...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 5; int n, p[MAXN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } int l = 1, r = n, div = n; while (div / 4) { p[l] = l + 1; p[l + 1] = r; ...
CPP