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
n = int(input()) mod = n % 4 if mod == 2 or mod == 3: print(-1) else: ans = [-1 for i in range(n)] i = 0 while i < n // 2: ans[i] = n - i - 1 ans[i+1] = i + 1 ans[n-1-i] = i + 2 ans[n-2-i] = n - i i += 2 if mod == 1: ans[n//2] = n//2 + 1 print(' '.join(map(str, 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; const long long maxx = 1ll << 32; const int maxn = 100005; int n, k = 0, m, l, r, x, y, t; int a[maxn]; long long c[maxn]; int dp[maxn]; int vis[maxn]; int gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } struct lee { int num; int x, y; } lo[maxn]; s...
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 C { Scanner sc = new Scanner(System.in); void doIt() { int n = sc.nextInt(); if(n % 4 >= 2) System.out.println(-1); else { int [] ans = new int[n]; if(n % 4 == 1) ans[n / 2] = (n + 1) / 2; for(int i = 0; i < n / 2; i += 2 ){ ans[i] = i+2; ans[i+1] = n-i; an...
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 v[100010]; int main() { int n; while (cin >> n) { memset(v, 0, sizeof(v)); if (n % 4 == 2 || n % 4 == 3) { cout << -1 << endl; continue; } if (n == 1) { cout << 1 << endl; continue; } int m = n / 4; m <<= 1; 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
n=int(input()) if(n%4>1): print(-1) else: ans=[0]*(n+1) i,j,a,b=1,n,1,n while(i<j and a<=n and b>=1): ans[i],ans[j]=a+1,b-1 ans[i+1],ans[j-1]=b,a i+=2 j-=2 a+=2 b-=2 if(i==j): ans[i]=a for i in range(1,n+1): print(ans[i],end=' ') ...
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; void _ad(int &p) { static int i = 0; p = i++; } int n; int perm[100001] = {0}; bool checkit(vector<int> &a) { for (int i = 0; i < a.size(); i++) { if (a[a[i] - 1] != a.size() - i) return false; } return true; } void past(int l, int r, int mn, int mx) { perm[...
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.ArrayList; import java.util.Locale; import java.util.StringTokenizer; public class A { private void solve() throws IOException { int n = nextInt(); if (n % 4 == 2 || 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; const int Maxn = 101000; int a[Maxn]; int n; int main() { scanf("%d", &n); if ((n / 2) % 2 == 1) { printf("-1\n"); return 0; } for (int i1 = 1, i2 = 2, i3 = n - 1, i4 = n; i2 < i3;) { a[i1] = i2; a[i2] = i4; a[i4] = i3; a[i3] = i1; i1 += ...
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, a[100005], i; void Solve(int left, int right) { if (left > right) return; if (right - left < 3) { if (left == right) a[left] = right; if (left + 1 == right) a[left] = left, a[right] = right; if (left + 2 == right) a[left] = right, a[left + 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 max_n = 1e5 + 15; int n, p[max_n]; int main() { cin >> n; if ((n & 3) > 1) { cout << -1; return 0; } if (n == 1) { cout << 1; return 0; } for (int i = 0; i + i + 1 < n; i += 2) { p[i] = i + 2; p[n - i - 1] = n + 1 - p[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
#include <bits/stdc++.h> using namespace std; long p[100001]; bool visit[100001]; long n; bool DFS(int i); int main(void) { ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; if (n > 1) { memset(p, -1, sizeof(p)); memset(visit, false, sizeof(visit)); bool key = true; for (int i = 1; i <= 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 java.io.OutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.Writer; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @auth...
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 a[N]; 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 += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i] = i; 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> int ans[100000]; int main() { int a; scanf("%d", &a); if (a % 4 == 2 || a % 4 == 3) { printf("-1\n"); return 0; } if (a % 4 == 0) { for (int i = 0; i < a / 4; i++) { ans[i * 2] = i * 2 + 2; ans[i * 2 + 1] = a - i * 2; ans[a - 1 - i * 2] = a - 1 - 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 a, b, c, d, n, m, i, j, ans, l, r, lcnt = 1, rcnt; int ar[100005]; int main() { scanf("%d\n", &n); if (n % 4 > 1) { printf("-1\n"); return 0; } lcnt = 1, rcnt = n; l = 1, r = n; for (i = 0; i <= n - 4; i += 4) { ar[l++] = lcnt + 1; ar[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
#include <bits/stdc++.h> int n; int f[100002]; void DP() { int i, x, y; for (i = 1; 2 * i <= n; i += 2) { x = i; y = i + 1; f[x] = y; f[y] = n - x + 1; f[n - x + 1] = n - y + 1; f[n - y + 1] = x; } if (n % 4) f[(n + 1) / 2] = (n + 1) / 2; for (i = 1; i < n; i++) printf("%d ", f[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 java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; import java.util.StringTokenizer; public class Main{ public static void main(String[] args) { Scanner r = new Scanner(System.in); PrintWrit...
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() { long long int n, i; cin >> n; if (n % 4 != 1 && n % 4 != 0) { cout << "-1"; return 0; } long long int a[n]; for (i = 0; i < n / 4; i++) { a[2 * i] = 2 * i + 2; a[2 * i + 1] = n - 2 * i; a[n - 2 * i - 1] = n - 2 * i - 1; 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.*; import java.io.*; public class a { static long mod = 1000000007; public static void main(String[] args) throws IOException { input.init(System.in); PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = input.nextInt(); int[] res = new int[n+1]; if(n%4 == 2 || 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; int DEBUG = 0; int main(int argc, char **argv) { DEBUG = (argc >= 2) ? atoi(argv[1]) : 0; int n; scanf("%d", &n); if (n == 1) { cout << 1 << endl; return 0; } if ((n % 4) == 0 || (n % 4) == 1) { int k = n / 4; for (int i = 1; i <= k; 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[100010]; int main(int argc, const char *argv[]) { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } for (int i = 1; i <= (n - 1) / 2; i += 2) { P[i] = i + 1; for (int j = i; P[P[j]] == 0; j = P[j]) { P[P[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 itertools #def isok(l, n): # for i in range(1, n+1): # if l[l[i-1]-1] != n - i + 1: # return False # return True n = int(raw_input()) #ok = 0 #for l in itertools.permutations([i for i in range(1, n+1)]): # if isok(l, n): # ok = 1 # print ' '.join(str(i) for i in l) # ...
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 outpu[100001]; set<int> se; set<int>::iterator it; int n; int main() { cin >> n; bool k = 0; if ((n - 1) % 4 == 0) { k = 1; outpu[n / 2 + 1] = n / 2 + 1; } if (n % 4 == 0 || n % 4 == 1) { for (int i = 1; i <= n; i++) if (k == 0 || (k == 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.IOException; import java.util.InputMismatchException; public class LuckyPermutation { public static void main(String[] args) { FasterScanner sc = new FasterScanner(); int N = sc.nextInt(); if (N % 4 == 2 || N % 4 == 3) { 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
from collections import Counter from itertools import cycle, product as prod, permutations as perm, combinations as comb, combinations_with_replacement as combr from sys import stdin, stdout read_ints = lambda: map(int, raw_input().split()) read_floats = lambda: map(float, raw_input().split()) def main(): n = inpu...
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; long long INV2 = 500000004; long long INV6 = 166666668; long long power(long long a, long long b, long long c) { long long x = 1, y = a; while (b > 0) { if (b & 1) x = (x * y) % c; y = (y * y) % c; b /= 2; } return x % c; } int dx[] = {0, -1, 0, 1}; 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; inline bool iseq(double x, double y) { if (fabs(x - y) < 1e-8) return true; return false; } template <typename T> inline T hpt(T x1, T y1, T x2, T y2) { return hypot(x1 - x2, y1 - y2); } template <typename T> inline T gcd(T a, T b) { if (!b) return a; 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
#include <bits/stdc++.h> int a[100001]; int main() { int i, n; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) puts("-1"); else { for (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 + 1] = 2 * 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 n, num[100005]; int main() { cin >> n; if (!(n % 4 == 0 || n % 4 == 1)) { cout << -1 << endl; return 0; } int st = 1, en = n, cnt = 0; while (1) { if (cnt * 4 == n) break; if (cnt * 4 + 1 == n) { num[st] = st; break; } num[s...
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) else: a = [n+1>>1]*n for i in range(n//4): j = i*2 a[j], a[j+1], a[-2-j], a[-1-j] = j+2, n-j, j+1, n-1-j 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
import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.InputMismatchException; import java.util.LinkedList; public class B { static int N; static PrintWriter out; public static void main(String[] args) { MScanner sc =...
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; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } if (n % 4) { for (int i = 0; i < n / 2; ++i) { if (i) printf(" "); if (i & 1) printf("%d", n - i + 1); else printf("%d", i + 2); } 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.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.HashSet; import java.util.StringTokenizer; import static java.lang.Math.*; import static java.lang.Integer.*; import static java.lang.Long.*; import static java.lang.Character.*; @Supp...
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.util.Arrays.deepToString; import java.io.*; import java.math.*; import java.util.*; public class A { static void solve() { int n = nextInt(); int pairs = n / 2; if (pairs % 2 == 1) { writer.println(-1); return; } int[] p = new int[n + 1]; if (n % 2 == 1) { p[n / 2 + 1] = n / ...
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 dx[] = {0, 1, 0, -1, -1, -1, 1, 1}; int dy[] = {1, 0, -1, 0, 1, -1, 1, -1}; int res[100010]; bool vis[100010]; int main() { ios::sync_with_stdio(false); int n; cin >> n; if (n == 1) cout << 1; else { int co = 1; if (n & 1) vis[n / 2 + 1] = res[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.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; 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; const int N = 100010; int n, p[N]; void Read_in() { scanf("%d", &n); return; } void Put_out() { if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return; } for (int i = 1; i <= n; i++) { printf("%d", p[i]); if (i != n) printf(" "); 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
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 2; int a[maxn]; int n; int main() { ios_base::sync_with_stdio(0); cin >> n; int t = n % 4; for (int i = 1; i <= n; i++) a[i] = i; if (t == 1 or !t) { int pt1 = 1; int pt2 = n; while (pt1 < pt2) { swap(a[pt1], a[pt1 + 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 n; int a[1000020]; int main() { cin >> n; if (n == 1) { puts("1"); } else if (n % 4 == 2 || n % 4 == 3) { puts("-1"); } else { for (int i = 0; i < n / 2; i++) if (i % 2 == 0) { a[i] = i + 1; a[i + 1] = n - 1 - i; 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.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class CodeA { static class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public String nextL...
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.OutputStream; import java.io.IOException; import java.io.PrintWriter; import java.util.InputMismatchException; import java.util.LinkedList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * @author George Marcus */ public class Main { public static void...
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); cout.tie(0); int n; cin >> n; if (n == 1) return cout << "1", 0; if (n % 4 > 1) return cout << "-1", 0; vector<int> ats, le, ri, add(n + 5); int mx, l, r; if (n % 4 == 0) { ats = {2, 4, 1, 3}; 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; template <typename T> inline T abs(T t) { return t < 0 ? -t : t; } const long long modn = 1000000007; inline long long mod(long long x) { return x % modn; } int main() { int n, i, p[100005]; scanf("%d", &n); if (n == 1) { puts("1"); return 0; } 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; int f[100500]; int main() { int n; while (~scanf("%d", &n)) { if (n == 1) { printf("1\n"); continue; } else if (n <= 3) { printf("-1\n"); continue; } f[1] = 2; if (n % 2 == 0) { int x = n - 2; for (int i = 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
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; int flag[111111]; int main() { int n; cin >> n; if (n % 4 == 3 || n % 4 == 2) { cout << -1 << endl; return 0; } int m = n / 4; for (int i = 1, j = 1; i <= m; i++, j = j + 2) { flag[j] = j + 1; flag[j + 1] = n - j + 1; flag[n - j + 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
#include <bits/stdc++.h> using namespace std; int res[110000]; int main() { int n; while (cin >> n) { if (n / 2 % 2) { cout << -1 << endl; continue; } 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...
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[1111111]; int main() { int n; int cnt = 1; scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1\n"); return 0; } if (n == 1) { printf("1\n"); return 0; } int tmp = n / 2; for (int i = 1; i <= tmp; i += 2) { 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
N = int(raw_input()) if N%4 >= 2: print -1 else: perm = [0 for i in xrange(N)] for i in xrange(0,N/2,2): perm[i] = i+1 perm[i+1] = N-i-1 perm[-i-1] = N-perm[i]-1 perm[-i-2] = i if N%2 == 1: perm[N/2] = N/2 for p in perm: print p+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
import java.util.Locale; import java.util.Scanner; public class HappyPermutationSolver { private int n; public static void main(String[] args) { HappyPermutationSolver solver = new HappyPermutationSolver(); solver.readData(); int[] solution = solver.solve(); solver.print(solu...
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; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1"; return 0; } int p[n + 1]; for (int 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 % 4 == 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() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long n; cin >> n; if (n % 4 >= 2) { puts("-1"); return 0; } vector<long long> p(n); long long k = 1; for (long long i = 0; i < n / 2; i += 2) { p[n - i - 2] = k; 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
import java.util.Scanner; public class Prob286A { public static void main(String[] Args) { Scanner scan = new Scanner(System.in); int x = scan.nextInt(); if (x % 4 < 2) { int[] arr = new int[x]; int min = 1; int max = x; if (x % 2 == 1) arr[x / 2] = x / 2 + 1; int count = x / 4; while...
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.Scanner; public class A { int N; int ans[]; private A() { } private void read() { Scanner sc = new Scanner(System.in); N = sc.nextInt(); } private void init() { } private void solve() { ans = new int[N]; for (int i=0; i<N/2; 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.*; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); // get n int n = in.nextInt(); // check parity of (n / 2) if ((n / 2) % 2 == 1) { System.out.println(-1); return; } int[] ary = new int[n + 5]; // check parity of n if (n ...
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 Main { public static void main(String[] args) { new Main().run(); } void run() { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); if (n % 4 > 1) { 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; int ax[100010]; int main(void) { int n; scanf("%d", &n); if (!(n % 4 == 0 || n % 4 == 1)) { printf("-1\n"); return 0; } for (int i = 1; i <= n / 2; i += 2) { ax[i] = i + 1; ax[i + 1] = n - i + 1; ax[n - i] = i; ax[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; vector<long long> v[301], vv, v1; long long a, b, c[1234567], c1[1234][1234], e, i, j, n, x, y, l, r, k; string s, s1; long long used[301]; long long ans; bool ok[123]; int main() { cin >> n; if (n / 2 % 2 == 1) { cout << -1; exit(0); } a = 2; 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> using namespace std; const int maxn = 1e5 + 5; int p[maxn]; int n; int main() { while (~scanf("%d", &n)) { if (n == 1) { printf("1\n"); continue; } if (n <= 3) { printf("-1\n"); continue; } memset(p, 0, sizeof(p)); ; if (n & 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
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n % 4 && (n - 1) % 4) { cout << -1 << endl; return 0; } int ara[n + 1], i; for (i = 1; i <= n / 2; i += 2) { ara[i] = i + 1; } for (i = 2; i <= n / 2; i += 2) { ara[i] = n - i + 2; } for (i = n; 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 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> const bool debug = false; using namespace std; long long powmod(long long a, long long b, long long MOD) { long long res = 1; a %= MOD; for (; b; b >>= 1) { if (b & 1) res = res * a % MOD; a = a * a % MOD; } return res; } void buginfo(const char* f, ...) { if (!debug) return...
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> inline void checkmin(T& a, const T& b) { if (a > b) a = b; }; template <class T> inline void checkmax(T& a, const T& b) { if (a < b) a = b; }; int main() { for (int n; cin >> n;) { vector<int> ans(n + 1); if (n % 4 == 2 || n % 4 == 3) { ...
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.*; import java.math.*; import java.awt.geom.*; import static java.lang.Math.*; public class Solution implements Runnable { int n; int p []; boolean used[]; int count = 0; void doIt (int k) { if (count > 0) return; if (k == n + 1) { boolean good = true; for (int 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> using namespace std; namespace Flandre_Scarlet { int n; void Input() { cin >> n; } int a[155555]; void Soviet() { memset(a, 0, sizeof(a)); if (n % 4 == 0) { for (int i = 1; i <= n; ++i) { if (!a[i]) { 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 f[100010]; int N; bool dfs(int l, int r, int k) { if (r - l + 1 >= 4) { f[l] = 2 + k * 2; f[l + 1] = N - k * 2; f[r] = N - 1 - k * 2; f[r - 1] = 1 + k * 2; return dfs(l + 2, r - 2, k + 1); } else if (r - l + 1 == 1) { f[r] = r; return tru...
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; return 0; } if (n % 4 == 3 || n % 4 == 2) { cout << -1 << endl; return 0; } int a[n + 1]; int i = 1, j = n, l = 1, r = n; while (i < j) { a[i] = l + 1; a[j] = r - 1; a[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 a[100002]; int main() { int n; cin >> n; if (n % 4 > 1) return cout << -1, 0; if (n % 4 == 1) a[(n - 1) / 2 + 1] = (n - 1) / 2 + 1; int e = n / 2; for (int i = 1; i < e; 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
#include <bits/stdc++.h> using namespace std; int a[100005], n, p, x, k; bool test() { for (int i = 1; i <= n; i++) if (a[a[i]] != n - i + 1) return 0; return 1; } int main() { scanf("%d", &n); k = ceil(n / 2.0); int x = 1, p = 2; while (x <= k) { a[x] = p; p += 2; x += 2; } x = n; 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
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; if (n % 4 > 1) { cout << "-1\n"; return 0; } for (int i = 1; i <= n / 2; i++) { if (i % 2) cout << i + 1 << ' '; else cout << (n - i + 2) << ' '; } int m = n / 2; if (n % 4 == 1) { cout << m + 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.math.BigInteger; import java.util.*; public class A { private static final int mod = (int)1e9+7; boolean ok (final int[] xs) { for(int i = 0; i < xs.length; i++) { if(xs[xs[i]] != xs.length - 1 - i) { return false; } ...
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:666000000") using namespace std; const int inf = (1 << 30) - 1; const long double eps = 1e-9; const long double pi = fabs(atan2(0.0, -1.0)); void ML() { int *ass; for (;;) { ass = new int[2500000]; for (int i = 0; i < 2500000; i++) ass[i] = rand(); ...
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.*; import java.util.*; public class Solution { public void run() { try { int n = reader.nextInt(); if (n % 4 >= 2) { writer.println(-1); } else { int[] p = 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> using namespace std; int seq[111111]; int main(void) { int n = 0; scanf("%d", &n); if (n % 4 > 1) puts("-1"); else { for (int i = 0; i < n / 4; i++) { int t = i * 2 + 1; int l = n + 1 - t; seq[t] = t + 1; seq[t + 1] = l; seq[l] = l - 1; seq[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
#include <bits/stdc++.h> using namespace std; int n; int a[100010]; int main() { cin >> n; if (n % 4 > 1) { cout << -1; 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 % 2 == 1) a[n / 2 + 1] = 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 arr[100009] = {0}; bool vis[100009] = {0}; set<int> st; bool f = 1; int n = 0; cin >> n; if (n == 1) { cout << n; return 0; } if (n <= 3) { cout << -1; return 0; } for (int i = 1; i <= n; i++) st.insert(i); while (st....
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; FILE *f, *g; int v[100100]; int i, j, q; int n; int main() { scanf("%d", &n); if (n % 4 == 2 || n % 4 == 3) { printf("-1"); return 0; } for (i = 1, j = n; i <= (n / 4) * 2; i += 2, j -= 2) { v[i] = i + 1; v[i + 1] = j; v[j - 1] = i; v[j] = 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
//package codeforces; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.Closeable; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; 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> using namespace std; int n; int a[100005]; int used[10005]; bool check(int i) { if (a[i] == -1) return true; if (a[a[i] - 1] == -1) { a[a[i] - 1] = n - i; used[n - i] = true; } else return a[a[i] - 1] == n - i; return check(a[i] - 1); } bool checkans() { for (int i = 0; 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; set<int> st; int ans[100007]; int main() { int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << "-1" << endl; return 0; } for (int i = 1; i <= n; i++) st.insert(i); if (n % 4 == 1) { int idx = (n + 1) / 2; st.erase(idx); ans[idx] = idx; ...
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 double PI = 3.1415926535; int n; int main() { cin >> n; if (n % 4 > 1) cout << -1; else { int x = n / 4; for (int i = 0; i < x; ++i) printf("%d %d ", 2 + i * 2, n - i * 2); if (n % 4 == 1) printf("%d ", n / 2 + 1); for (int i = x - 1; 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
#include <bits/stdc++.h> using namespace std; int main() { int n; int p[100005], parent[100005]; scanf("%d", &n); if (n % 4 > 1) { printf("-1\n"); return 0; } memset(parent, 0, sizeof(parent)); for (int i = 1; i <= n / 2; i += 2) { p[i] = 1 + i; p[i + 1] = n - i + 1; p[n - i + 1] = 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() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; if (n % 4 > 1) { cout << "-1\n"; return 0; } int p[n]; if (n % 4 == 1) { p[n / 2] = (n + 1) / 2; } for (int i = 0, j = n - 2; i < n / 2; i += 2, j -= 2) { if (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 Contest176 { public static void main(String[] args) throws IOException { new Contest176().run(); } public void solve() throws IOException { int n = nextInt(); int rem = n % 4; if(rem == 2 || rem == 3) { out.pri...
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
#!/usr/bin/python import sys def read_obj(cls): return cls(sys.stdin.readline().strip()) def read_obj_list(cls): return map(cls, sys.stdin.readline().strip().split()) def solve(): n = read_obj(int) if n % 4 in [2, 3]: print -1 return res = [0 for i in xrange(n + 1)] for i in ...
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 INF = 1 << 30; const double EPS = 1e-7; const int MAX = 100005; int p[MAX]; int main() { ios::sync_with_stdio(false); int n; cin >> n; if (n % 4 > 1) cout << -1 << endl; else { for (int i = 1; i <= n / 2; i += 2) { p[i] = i + 1; 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 main() { int n; scanf("%d", &n); if (n % 4 == 0 || n % 4 == 1) { if (n % 4 == 0) { for (int i = 1; i <= n / 2; i += 2) { printf("%d ", i + 1); printf("%d ", (n - i + 1)); } for (int i = n / 2 + 1; i <= n; i += 2) { pri...
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.*; import java.util.*; import java.util.stream.*; import java.lang.management.*; import static java.lang.Math.*; @SuppressWarnings("unchecked") public class P0286A { public void run() throws Exception { int n = nextInt(), n_2 = n / 2; if (n == 1) { 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 int dr[]{-1, -1, 0, 1, 1, 1, 0, -1}; const int dc[]{0, 1, 1, 1, 0, -1, -1, -1}; void run() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } deque<int> solve(int n, int add) { if (n == 0) return {}; if (n == 1) return {1 + add}; deque<int> q ...
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() { 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 - 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 java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.NoSuchElementException; public class A { public static void main(String[] args) { FS r = new FS(); int N = r.nextInt(); int[] ans = new int[N]; if(N%4==2||N%4==3) { 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
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ //package codeforces; import java.util.*; import java.io.*; /** * * @author Arysson */ public class Main { /** * @param ...
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; /** * Created with IntelliJ IDEA. * User: horikawa * Date: 3/23/13 * Time: 2:05 AM * To change this template use File | Settings | File Templates. */ public class C { public static void main (String[] argv) { Scanner in = new Scanner(System.in); int n = in.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
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
#include <bits/stdc++.h> const double eps = 1e-6; const double PI = acos(-1.0); const int inf = ~0u >> 2; using namespace std; const int N = 100010; int p[N]; int main() { int n, i; while (~scanf("%d", &n)) { if (n == 1) { puts("1"); continue; } if (n < 4) { puts("-1"); continue;...
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 + 20; int n, p[N], ans1, ans2, ans3, ans4, k1, k2, k3, k4, m; int main() { cin >> n; if (n % 4 != 0 && (n - 1) % 4 != 0) { cout << -1; return 0; } if (n % 4 == 0) { m = n / 4; k1 = 1; k2 = 2; k3 = n - 1; k4 = n; ans1...
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==2 or n == 3 or 0 == (n-2)%4 or (n - 3)%4 == 0): print -1 else: if (n%2==0): for i in range(1, n/2+1): if (i%2==0): print i-1 else: print n - i for i in range(n/2 + (2 if (n%2==1) else 1), n+1): if (i%2==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 main() { ifstream fin("input.txt", ios::in); ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); cout << setprecision(10); cout << fixed; int n; cin >> n; if (n % 4 == 2 || n % 4 == 3) return cout << -1, 0; if (n == 1) return cout << 1, 0; 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; vector<int> vec; void cal(int l, int r) { if (r < l) return; if (l == r) { vec.push_back(l); return; } vec.push_back(l + 1); vec.push_back(r); cal(l + 2, r - 2); vec.push_back(l); vec.push_back(r - 1); } int main() { int n; cin >> n; 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; int a[100001]; int main() { int i, n; cin >> n; if (n % 4 == 2 || n % 4 == 3) { cout << -1; return 0; } if (n % 2 == 1) a[(n + 1) / 2] = (n + 1) / 2; for (int i = 1; i <= n / 2; i += 2) { a[i] = i + 1; a[i + 1] = n - i + 1; a[n - i] = i; ...
CPP