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
import java.util.*; import java.math.*; public class Main { /** * @param args */ public static void main(String[] args) { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); if (n==1) { System.out.println("1"); } else if(n%4==2 || n%4==3) { System.out.println("-1"); } else { for(in...
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.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class C { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); if (((n / 2) * 2) % 4 != 0) { System.out.println(-1); } else { int[] perm = new int[n]; for (int i = 0; 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 MAXN = 100010; int n, a[MAXN]; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1"); return 0; } if (n % 4 == 0) { for (int i = 1; i <= n / 2 - 1; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i + 1] = n - i; a[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.util.Scanner; public class C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); if (n % 4 > 1) System.out.println(-1); else { int[] P = new int[n]; int start = 0; int end ...
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
from itertools import permutations from sys import stdin def checkit(vector, upto=-1): if upto == -1: upto = len(vector) for i in range(0, upto): if vector[vector[i] - 1] != len(vector) - (i + 1) + 1: return False return True def calculate(n): numbers = list(range(1, n + ...
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 main() { int n, a[100005] = {0}, i, j; cin >> n; if (n % 4 > 1) { cout << -1; return 0; } a[n / 2 + 1] = n / 2 + 1; for (j = 1; j <= n / 4; j++) { a[n - j * 2 + 1] = j * 2 - 1; i = n - j * 2 + 1; do { a[a[i]] = n - i + 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; long long n, a[100005]; int main() { cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1\n"; return 0; } long long f = 1; long long b = n; while (f < b) { if (f == b) { a[f] = f; break; } a[f] = f + 1; a[f + 1] = b; a[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
#include <bits/stdc++.h> using namespace std; int d[100100]; int main() { int n; while (scanf(" %d", &n) == 1) { if (n % 4 == 0) { int r = n; for (int i = 1; i < n;) { d[i] = i + 1; d[i + 1] = n; d[n] = n - 1; d[n - 1] = i; i += 2; 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 a[200009]; int main() { int i, j, k, n; scanf("%d", &n); if (n == 1) { printf("1\n"); } else if (n % 4 > 1) { printf("-1\n"); } else { for (i = 1; i < n / 2; i += 2) { a[i] = i + 1; j = i; while (!a[a[j]]) { a[a[j]] = 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.BufferedWriter; import java.util.InputMismatchException; import java.io.InputStream; import java.util.NoSuchElementException; import java.io.OutputStreamWriter; import java.math.BigInteger; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Writer; import java.io.IOException; /** *...
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 p[100500]; set<int> nused; int n; void sol() { if (n == 1) cout << 1; else if (((n - 1) % 4 == 0) || (n % 4 == 0)) { for (int i = (1); i <= (n); i++) nused.insert(i); memset(p, 0, sizeof(p)); int i = 1; for (int i = (1); i <= (n / 2); 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> #pragma comment(linker, "/stack:336777216") #pragma GCC optimize("O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using ll = long long; using ull = unsigned long long; using ld = long double; using ui = unsigned int; template <typename T> ...
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); int p[n + 1]; if (n % 4 <= 1) { if (n % 2 == 1) p[(n + 1) / 2] = (n + 1) / 2; for (int s = 1, e = n; s < e; s += 2, e -= 2) { p[s] = s + 1; p[s + 1] = e; p[e] = e - 1; p[e - 1] = s; } 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
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class Main { private static void debug(Object... args) { System.out.println(Arrays.deepToString(args)); } public static void main(String[] rags) throws Exception { ...
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 main() { int n, m, i, x, y; scanf("%d", &n); m = n / 2; if (m % 2 == 0) { x = m / 2; for (i = 0; i < x; i++) printf("%d ", m - i); for (i = x - 1; i >= 0; i--) printf("%d ", n - i); if (n % 2 == 1) printf("%d ", m + 1); for (i = 1; i <= x; i++) printf("%d ", 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> const int N = 100010; int p[N]; int L[N]; int cnt[N]; int partner[N]; int list[N]; void combine(int i, int j) { assert(L[i] == L[j]); assert(L[i] > 0 && !(L[i] & 1)); int flag = 0; list[0] = i; list[1] = j; int n = 2; int ci = p[i], cj = p[j]; while (ci != i && cj != j) { li...
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 argc, char *argv[]) { int n; cin >> n; if (n % 4 == 0 || n % 4 == 1) { int a[n]; int low = 1, high = n; int i = 0; while (low < high) { a[i] = low + 1; a[i + 1] = high; a[n - i - 1] = high - 1; a[n - i - 2] = low; ...
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 n%4 not in {0,1}: print -1;exit() p=[(n+1)/2]*n for i in range(n/4): a=i*2 p[a],p[a+1],p[-a-2],p[-a-1]=a+2,n-a,a+1,n-a-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.*; import java.util.*; public class LuckyPermutation { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(f.readLine()); if (n % 4 == 2 || n % 4 == 3) { ...
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[100000 + 10]; int main() { int n; while (scanf("%d", &n) != EOF) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } 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;...
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[100010]; int main(int argc, char *argv[]) { scanf("%d", &N); if (N % 4 == 2 || N % 4 == 3) { printf("-1\n"); return 0; } int K = N >> 1; for (int i = 1; i <= K; i++) if (P[i] == 0) { P[i] = i + 1; P[i + 1] = N - i + 1; P[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; int mark[100002], p[100002]; int main() { int t, n; while (scanf("%d", &n) != EOF) { int next = 2; mark[0] = 0; for (int i = 1; i <= n; i++) { mark[i] = 0; p[i] = 0; } int f = 0; for (int i = 1; i <= n; i++) { if (p[i] != 0) con...
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 A { public static final boolean DEBUG = false; Scanner sc; public void debug(Object o) { if (DEBUG) { int ln = Thread.currentThread().getStackTrace()[2].getLineNumber(); String fn = Thread.currentThread().getStackTrace()[2].getFileName(); System.out.println("(" +...
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 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: int m = (N-1)/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
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const double pi = acos(-1); const double EPS = 1e-9; long long binpowmod(long long a, long long b) { a %= MOD; long long ret = 1; while (b) { if (b & 1) ret = ret * a % MOD; a = a * a % MOD; b >>= 1; } return ret % MOD; } long ...
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:250777216") using namespace std; const int MOD = int(1e9) + 7; const int HMOD = (1 << 22) - 1; int p1[110000] = {}; int n; int main() { scanf("%d", &n); int num = n; int i = 1; for (i = 1; num > 3; i += 2) { p1[i + 1] = i; p1[i] = n - i; p1[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.util.*; import java.lang.*; import java.io.*; import java.text.*; /** * @author soumitri12 */ /* Name of the class has to be "Main" only if the class is public*/ public class CF287C { static class FastReader { BufferedReader br; StringTokenizer st; public Fast...
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
# -*- coding:utf-8 -*- def PrintPermutation(n): if n % 4 != 0 and (n-1) %4 != 0: print '-1' return data = [0] * (n + 1) if n%2 == 1: data[(n+1)/2] = (n+1)/2 i0 = 1 i1 = n while True: j0 = i0+1 j1 = i1-1 if j0 >= j1 : break; da...
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 = int(raw_input()) p = [0] * (n+1) lo, hi = 1, n possible = True while hi - lo > 2: if not p[hi-1]: p[hi-1] = lo if not p[lo]: p[lo] = lo+1 if not p[hi]: p[hi] = hi-1 if not p[lo+1]: p[lo+1] = hi lo += 2 hi -= 2 n -= 4 # lo is the first zero if n == 1: p[lo] = lo elif n != 0: possible =...
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; template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double pi = 3.1415926535897932384626433832795; const long double eps = 1e-9; const int INF = (int)1e9; const int N = (int)1e5 + 10; long long n, k; int ...
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.*; import java.io.*; public class Main implements Runnable { public void solve() throws IOException { int N = nextInt(); int[] ans = new int[N]; 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
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int a[maxn]; int main() { int n; scanf("%d", &n); if (n & 1) { if ((n - 1) % 4) { puts("-1"); return 0; } else { for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n + 1 - i; a[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.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 dy */ public class Main { public static void main(String[] args) { InputStream inputStre...
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 N = 100010; int n, res[N]; int main() { scanf("%d", &n); if ((n / 2) % 2 == 1) { puts("-1"); } else { res[n / 2] = n / 2; for (int i = 0; i < n / 2; i += 2) { res[i] = i + 1; res[i + 1] = n - i - 1; res[n - i - 1] = n - 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; int n, i, a[100005]; int main() { scanf("%d", &n); if (n % 4 != 0 && n % 4 != 1) { printf("-1\n"); return 0; } for (i = 1; i <= n / 4; i++) { a[(i - 1) * 2 + 1] = i * 2; a[i * 2] = n - (i - 1) * 2; a[n - (i - 1) * 2] = n - (i - 1) * 2 - 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; const int MaxN = 100000; int main() { int n; static int p[MaxN + 1]; cin >> n; if ((n / 2) % 2 != 0) cout << "-1" << endl; else { for (int i = 1; i <= n - i + 1; i += 2) { if (i == n - i + 1) p[i] = i; else { p[i] = 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
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.util.*; import java.io.*; import java.math.*; import java.lang.*; /** * * @author calcsaransh */ public class Main { /** * @param args the command line arguments */ static int 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.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.PrintWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.StringTokenizer; public class Solver { public static void main(String[] Args) t...
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.BufferedWriter; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Scanner; public class cf287c { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));...
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 == 2 or n % 4 == 3: print "-1" else: perm = [0 for i in range(n)] d = n/4 for i in range(d): perm[2*i] = 2*i + 2 perm[2*i + 1] = n - 2*i perm[n - 2*i - 1] = n - 2*i - 1 perm[n - 2*i - 2] = 2*i + 1 if n % 2 == 1: perm[n...
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, a[100009]; int main() { cin >> n; if (n == 1) cout << 1; else if ((n / 2) % 2 == 1) cout << -1; else { for (int i = 1; i <= (n / 2 / 2); i++) { a[i * 2 - 1] = i * 2; a[i * 2] = n - (i - 1) * 2; a[n - i * 2 + 1] = i * 2 - 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> const int N = 1e5 + 10; int n, m, i, t, x, a[N]; bool e[N]; int check() { int i, x; for (i = 1; i <= n; i++) { x = a[a[i]]; if (x + i == n + 1) ; else return 0; } return 1; } void print() { int i; for (i = 1; i < n; i++) printf("%d ", a[i]); printf("%d\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.util.Scanner; // http://codeforces.com/contest/287/problem/C public class LuckyPermutation { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); s.close(); if (n % 4 == 0 || (n - 1) % 4 == 0) { int p = n / 4; ...
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; void solve() { int n; cin >> n; if (n == 4) { cout << "2 4 1 3" << endl; return; } int a[n]; if (n % 4 == 0 || (n - 1) % 4 == 0) { a[n - 3] = n + 1 - 4; a[0] = 2; a[n - 2] = 1; a[2] = 4; a[n - 1] = n - 1; a[1] = n; 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; int n; int mas[100005]; int main() { cin >> n; if (n % 4 >= 2) { cout << "-1\n"; return 0; } for (int i = 0; i < n; ++i) mas[i] = i; for (int l = 0, r = n - 1; l < r; l += 2, r -= 2) { mas[l] = l + 1; mas[l + 1] = r; mas[r] = r - 1; mas[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 n, p[1010000]; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { puts("-1"); return 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 + ...
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 Practice3.CF286; import java.util.Iterator; import java.util.Scanner; import java.util.TreeSet; public class CF286A { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); if (n % 4 > 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
import java.util.*; import java.util.regex.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.lang.Integer.*; import static java.lang.Double.*; import static java.util.Collections.*; import java.io.*; public class _287_C_Lucky_Permutation { public void solve() { int n = ni(); ...
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.*; import java.io.*; public class LuckyPermutation { public static InputReader in; public static PrintWriter out; public static final int MOD = (int) (1e9 + 7); public static void main(String[] args) { in = new InputReader(System.in); out = new PrintWriter(System.out)...
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 A { public static void main(String args[]) { Scanner s = new Scanner(System.in); int n = s.nextInt(); if (n % 4 <= 1) { int arr[] = new int[n + 1]; int c = n / 4, i = 1; while (i <= c) { arr[2 * i - 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; int n; int p[100010]; bool used[100010]; int main() { scanf("%d", &n); memset(p, 0, sizeof(p)); memset(used, false, sizeof(used)); if (n == 1) { printf("1\n"); return 0; } if (n % 2 == 0) { if (n % 4 != 0) { printf("-1\n"); return 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.BufferedReader; import java.io.FileNotFoundException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; import java.util.TreeSet; /** * * * @author pttrung */ public class C { // public static ...
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> #pragma comment(linker, "/STACK:16777216") using namespace std; const int MAXN = 100005; int n, a[MAXN]; void Inp() { scanf("%d", &n); } void Outp() {} void Run() { if (n % 4 == 2 || n % 4 == 3) { printf("-1"); exit(0); } for (int i = 0; i < n / 4; ++i) { a[i * 2] = i * 2 + 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.Scanner; public class LuckyPermutation { public static void main(String[] args) { Scanner s = new Scanner(System.in); int num = s.nextInt(); int[]array = new int[num]; if(num ==1){ System.out.println(1); }else{ if (num% 4== 2 || num...
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; while (scanf("%d", &n) == 1) { if ((n / 2) & 1) printf("-1\n"); else { if (n & 1) { int t = n; for (int i = 1; i <= n; i++) { if (i == n / 2 + 1) { printf("%d", i); t -= 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 main() { int n; while (scanf("%d", &n) != EOF) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } for (int i = 0; i < n; ++i) { if (i) printf(" "); if (n % 2) { if (i == (n - 1) / 2) printf("%d", (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 n, p[5000000], i; int main() { cin >> n; if (n % 4 >= 2) { cout << -1 << endl; return 0; } for (i = 1; i <= n / 2; i += 2) { p[i] = i + 1; p[i + 1] = n - i + 1; p[n - i + 1] = n - i; p[n - i] = i; } if (n % 2) p[n / 2 + 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.io.*; import java.util.*; public class Template implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); o...
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 N = 100005; int n; int a[N]; int main() { scanf("%d", &n); if (n % 4 >= 2) { printf("-1\n"); return 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 % 4) 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 res[100010]; int main() { int n; cin >> n; if (n % 4 == 1) { for (int i = 0; i < n / 2 - 1; i += 2) { res[i] = i + 2; res[i + 1] = n - i; } res[n / 2] = n / 2 + 1; for (int i = n / 2 + 1; i < n - 1; i += 2) { res[i] = n - 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.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.*; public class A implements Runnable { private void solve() throws Exception { int n = nextInt(); int[] res = solve(n); // if (n < 20) { // ...
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 CF_286A { public static void main(String[] args) throws IOException { new CF_286A().solve(); } void solve() throws IOException{ InputStream in = System.in; PrintStream out = System.out; // in = new FileInputStr...
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 long maxn = 60000; const long maxm = 15000000; const long oo = 100000000; const long mod = 1000000007; const double le = 1e-10; long i, j, k, n, m; long a[1000000]; int main() { scanf("%ld", &n); if (n % 4 == 3 || n % 4 == 2) { puts("-1"); return 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 main() { int n, tam; cin >> n; vector<int> v; if (((n % 4) == 2) || ((n % 4) == 3)) { cout << -1 << endl; return 0; } else if (n % 4 == 0) { tam = (int)v.size(); v.push_back(2); v.push_back(4); v.push_back(1); v.push_back(3); 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; const int mx = 1e5 + 10; int p[mx]; int main() { int n; cin >> n; if (n % 4 > 1) { puts("-1"); return 0; } int l = 1, r = n; while (l < r) { p[l] = l + 1; p[l + 1] = r; p[r] = r - 1; p[r - 1] = l; l += 2; r -= 2; } if (l == 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
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class LuckyPermutation implements Closeable { private InputReader in = new InputReader(System.in)...
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.PrintWriter; //PrintWriter public class R176_Div2_C //Name: Lucky Permutation { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); solve(in, out); out.close(); in.close(); } publ...
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 ans[200000], was[200000]; int link[200000]; int main() { int n; scanf("%d", &n); if (n % 2 == 1) { ans[n / 2 + 1] = n / 2 + 1; was[n / 2 + 1] = 1; } for (int i = 1; i <= n; i++) link[i] = n - i + 1; int x = 1; for (int i = 1; i <= n; i++) { 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
#include <bits/stdc++.h> using namespace std; bool good(vector<int> p) { for (int i = 0; i < p.size(); ++i) if (p[p[i]] != p.size() - i - 1) return false; return true; } void print(vector<int> p) { for (int i = 0; i < p.size(); ++i) cout << p[i] + 1 << " "; cout << endl; } void solve() { int n; cin >> 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; int n, i, j, p[100011]; set<int> a; set<int>::iterator b; int main() { scanf("%d", &n); if (n == 1) { printf("1\n"); return 0; } if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } for (i = 1; i <= n; ++i) a.insert(i); for (j = 1; j <= ...
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 from collections import deque n = int(input()) if n % 4 == 2 or n % 4 == 3: print('-1') sys.exit() arr = [None] * (n + 1) qt = deque([i for i in range(1, n + 1)]) mark = set() while qt: while qt and qt[0] in mark: qt.popleft() if not qt: break a = qt.popleft() while q...
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.util.*; import java.io.*; import java.math.*; public class Main { static class Reader { private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;} public int read() {if (nu...
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 n, i, a[100005], t1, t2; int main() { scanf("%d", &n); if (n % 4 > 1) { printf("-1\n"); return 0; }; t1 = n - 1; t2 = -1; while (t1 > (n + 1) / 2) { a[t1] = (t2 += 2); t1 -= 2; }; if (n % 4 == 1) { a[(n + 1) / 2] = (n + 1) / 2; t2++; }; for (t1 = ...
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 F, class T> T convert(F a, int p = -1) { stringstream ss; if (p >= 0) ss << fixed << setprecision(p); ss << a; T r; ss >> r; return r; } template <class T> T gcd(T a, T b) { T r; while (b != 0) { r = a % b; a = b; b = r; } ret...
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
#!/usr/bin/env python # coding=utf-8 n = input() if n % 4 == 2 or n % 4 == 3: print -1 exit(0) ans = [0 for i in xrange(n)] cnt = 0 if n % 2 == 1: ans[(n - 1) / 2] = (n + 1) / 2 cnt += 1 p = 1 q = n while cnt < n: tmpp = p + 2 tmpq = q - 2 ans[p - 1] = p + 1 ans[p] = q ans[q - 2] = ...
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; const int N = 100500; int A[N]; int main() { int n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } for (int i = 0; i < n; i++) A[i] = i; for (int i = 0; i < n / 2; i += 2) { A[i] = i + 1; A[i + 1] = n - 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 main() { int n; cin >> n; if (n == 1) { cout << "1" << endl; return 0; } if (((n / 2) * 2) % 4 == 0) { int p[n]; int temp; if (n % 2 != 0) p[n / 2] = (n + 1) / 2; for (int i = 0; i < n / 4; i++) { temp = i + n / 2 + (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> const int maxn = 110000; int a[maxn]; int n; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } for (int i = 1; i <= n / 4; i++) { a[2 * i - 1] = 2 * i; a[2 * i] = n - 2 * i + 2; a[n - 2 * i + 2] = n - 2 * i + 1; a[n - 2 * 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> const long long INF = 2009000999; const float cp = 2 * acos(0.0); const float eps = 1e-18; using namespace std; int main() { long long n, p[1010000]; cin >> n; if (n % 4 == 2 || n % 4 == 3) { puts("-1"); return 0; } if (n % 4 == 0) { for (int i = 1; i <= n / 2; 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
n=input() a=[0]*(n+1) b=[0]*(n+1) if n==1: print 1 elif n>3 and (n%4==0 or (n-1)%4==0): if n%2==1: a[(n+1)/2]=(n+1)/2 b[(n+1)/2]=(n+1)/2 j=1 while j<n/2: a[j]=j+1 k=j+1 pre=j while a[k]!=j: a[k]=n+1-pre pre=k k=a[k] ...
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 ans[100000]; int main() { int n; scanf("%d", &n); if (n / 2 % 2) puts("-1"); else { bool flag = 0; if (n & 1) { --n; flag = 1; } for (int i = 0; i < n / 2; i += 2) ans[i] = i + 2; for (int i = n / 2; i < n; i += 2) ans[i] = 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 static java.lang.Math.*; import static java.math.BigInteger.*; import static java.util.Arrays.*; import static java.util.Collections.*; import java.io.*; public class A { final static boolean autoflush = false; public A () { int N = sc.nextInt(); sc = null; int [] res = new int [N]; switch(N%4) { ...
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.Comparator; import java.io.BufferedReader; import java.io.OutputStream; import java.io.PrintWriter; import java.util.Collection; import java.util.List; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.ArrayList; import java.util.StringTokenizer; im...
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 used[123456]; int main() { int n; cin >> n; vector<pair<int, int> > v1, v2; vector<int> ans; int a = 2, b = n; while (a < b) { used[a] = used[b] = 1; v1.push_back(make_pair(a, b)); a += 2; b -= 2; } a = 1, b = n - 1; while (a < 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
#include <bits/stdc++.h> using namespace std; int a[100007]; int n; int main() { int i, j; while (~scanf("%d", &n)) { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); continue; } for (i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[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
#include <bits/stdc++.h> const double PI = acos(-1.0); using namespace std; int p[100010]; int main() { int n, i; int a, b; while (cin >> n) { if (n % 4 == 0 || n % 4 == 1) { for (i = 1; i <= n; i++) p[i] = i; a = 1; b = n; for (i = 1; i < n / 2; i += 2) { p[i] = a + 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.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.StringTokenizer; public class Main { public static void main(String[] args) throws Throwable { Scanner sc = new ...
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 p[100000 + 11]; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; if (n % 4 >= 2) { cout << -1; return 0; } if (n == 1) { cout << 1; return 0; } p[n - 1] = 1; int fill = 1; int prev = n - 1; while (fill < 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; int main() { int a[100010]; int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1" << endl; return 0; } if (n % 4 == 1) a[(n + 1) / 2] = (n + 1) / 2; int i = 1; int end = n; while (i < end) { a[i] = end - 1; a[end - 1] = (n - 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; int main() { int n, m; scanf("%d", &n); m = n; int A[n]; if ((n - 2) % 4 == 0 || (n - 3) % 4 == 0) { printf("-1\n"); return 0; } int i = 2; int p = 0; while (n > 0) { if (n == 1) { A[p] = p + 1; n -= 1; } else { A[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 = 1e5 + 5; const int M = 1e5 + 5; int main() { ios_base::sync_with_stdio(false); int n, i, p[N]; cin >> n; if (n % 2 == 0) { if (n % 4 != 0) { cout << -1 << endl; return 0; } else { int foo = n / 4; for (i = 1; i <= 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 n; int nums[100001]; int main() { cin >> n; if (n % 4 == 0 || n % 4 == 1) { for (int i = 1; i <= n / 2; i += 2) { nums[i] = i + 1; nums[i + 1] = n - i + 1; nums[n - i + 1] = n - i; nums[n - i] = i; } if (n % 4 == 1) nums[n / 2 + 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; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } int ary[n + 1]; for (int i = 1; i <= n / 2; i += 2) { ary[i] = i + 1; ary[i + 1] = n - i + 1; ary[n - i + 1] = n - i; ary[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
#include <bits/stdc++.h> using namespace std; const int N = 200011; const int MOD = 1e9 + 7; long long int powmod(long long int a, long long int b) { if (b == 0) return 1; long long int x = powmod(a, b / 2); long long int y = (x * x) % MOD; if (b % 2) return (a * y) % MOD; return y % MOD; } int main() { int...
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 = 1e5 + 5; int a[maxn]; int book[maxn]; set<int> num; int main() { int n, i; cin >> n; if (n == 1) return 0 * printf("1\n"); if (n % 4 > 1) return 0 * printf("-1\n"); for (i = 1; i <= n; i++) num.insert(i); int m = n; if (n & 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.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.StringTokenizer; public class Solver { BufferedReader br; PrintWriter pw; St...
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.StringTokenizer; /** * 286A * O(n) time * O(n) space * * @author artyom */ public class _286A implements Runnable { private BufferedReader in; private StringTokenizer tok; private Object solve() throws IOException { int n = nextInt(), r = n % 4; 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
#include <bits/stdc++.h> using namespace std; const int N = 101000; int P[N]; int n; int main() { scanf("%d", &n); if ((n % 4) > 1) { printf("-1\n"); } else { int dl = (n - (n & 1)); bool dol = true; int naDol = 2, gora = dl; for (int i = 0; i < (dl / 2); ++i) { if (dol) { 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; int a[100010]; int main() { int n; scanf("%d", &n); if (n == 1) puts("1"); else if (n % 4 > 1) puts("-1"); else { int i = 1, j = n; for (; j - i > 0; i += 2, j -= 2) { a[i] = i + 1; a[i + 1] = j; a[j] = j - 1; a[j - 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 M[100001]; int main() { int n; cin >> n; if (n == 1) { cout << 1 << endl; return 0; } if (n % 4 == 2) { cout << -1 << endl; return 0; } if (n % 2 == 0) { int j = n; for (int i = n / 2; i > 0; i -= 2) { M[i] = j; j -= 2; ...
CPP