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 |
|---|---|---|---|---|---|
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 |
import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH;
import java.awt.geom.*;
import java.util.*;
import java.io.*;
import java.math.*;
import java.util.regex.*;
public class Main {
static InputReader in;
public static void main(String[] args) throws IOException{
... | JAVA |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.TreeSet;
import java.io.InputStream;
/**
* Built using CHelpe... | JAVA |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAX_V = 100000;
vector<int> adjlist[MAX_V + 5];
int N, x, y, component, sz, deg[MAX_V + 5], A[MAX_V + 5];
bool visit[MAX_V + 5];
void dfs(int u) {
visit[u] = 1;
for (int i = 0; i < (int)adjlist[u].size(); i++) {
int v = adjlist[u][i];
if (!visit[v]) df... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
vector<int> a[100020];
int edgeu[100020 * 2], edgev[100020 * 2];
bool chose[100020];
vector<int> apart[100020];
int cnt[100020], ans[100020];
bool vis[100020];
int n, m = 0;
void Read() {
int i, u, v;
scanf("%d", &n);
for (i = 1; i <= n * 2; i++) {
scanf("%d%d", &... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int i, j, n, k, c, x, y, c1, c2, c3, z;
bool u[100009];
vector<int> a[100009];
int ans[100009];
bool res;
bool cmp(int a, int b) { return a < b; }
void search() {
int i, j, k;
bool p1, p2;
for (i = 0; i < 100009; i++) {
if (a[i].size() != 0) {
c1 = i;
... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
int ans[100100];
vector<int> g[100100];
int vis[100100];
bool judge1(int cur, int val) {
if (cur <= 2) return true;
int i, j;
int pre = cur - 2;
int k = ans[pre];
for (i = 0; i < 4; i++) {
if (g[k][i] == val) {
return true;
}
}
return fals... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[500500], n, x, y, used[500500];
vector<int> g[500500];
set<pair<int, int> > s;
int main() {
scanf("%d", &n);
for (int i = 0; i < n + n; i++) {
scanf("%d%d", &x, &y);
--x;
--y;
g[x].push_back(y);
g[y].push_back(x);
s.insert(make_pair(x, y));... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Solution {
BufferedReader in;
PrintWriter out;
StringTokenizer st;
String nextToken() throws Exception {
while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(in.readLine());
return st.nextToken();
}
int nextInt... | JAVA |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
vector<int> road[100011];
bool vis[100011];
bool find(int p, int a, int b, int c, int d) {
for (int i = 0; i < 4; i++)
if (road[p][i] != a && road[p][i] != b && road[p][i] != c &&
road[p][i] != d)
return 0;
return 1;
}
int now[100011] = {0};
int main()... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
set<int> G[maxn];
bool v[maxn];
int cnt[maxn];
vector<int> ans;
void dfs(int now, int p) {
v[now] = true;
ans.emplace_back(now);
for (int u : G[now])
if (!v[u]) {
if (p && G[p].count(u) == 0) continue;
int cnt = 0;
for ... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, head[N], pre[N << 2], nxt[N << 2], e, deg[N], ans[N];
bool vis[N];
set<pair<int, int> > st;
void init() {
memset(head, -1, sizeof(head));
e = 0;
}
void add(int u, int v) { pre[e] = v, nxt[e] = head[u], head[u] = e++; }
bool judge() {
int i... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int adj[111111][4];
int edge[222222][2];
int n;
void build() {
memset(adj, 0, sizeof(adj));
for (int i = 0; i < n + n; i++) {
for (int j = 0; j <= 1; j++) {
int f = edge[i][j];
int t = edge[i][1 - j];
if (adj[f][0] == 0)
adj[f][0] = t;
... | CPP |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | import static java.util.Arrays.*;
import java.io.*;
import java.lang.reflect.*;
public class C {
final int MOD = (int)1e9 + 7;
final double eps = 1e-12;
final int INF = (int)1e9;
int [][] L;
int N;
public C () {
N = sc.nextInt();
L = new int [N+1][4];
int [] C = new int [N+1];
if (N == 5)
ex... | JAVA |
263_C. Circle of Numbers | One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c ar... | 2 | 9 | import java.util.*;
public class NumbersCircleSolver {
private int n;
private List<List<Integer>> a;
public static void main(String[] args) {
NumbersCircleSolver solver = new NumbersCircleSolver();
solver.readData();
List<Integer> result = solver.solve();
if (result.isEm... | 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 / 2) % 2 > 0) {
cout << -1;
return 0;
}
for (int i = 1; i <= n / 4; i++) {
cout << i * 2 << ' ' << n - (i - 1) * 2 << ' ';
}
if (n % 2 != 0) cout << (n + 1) / 2 << ' ';
for (int i = n / 4; i >= 1; i--) {
c... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
int N, res;
int ar[MAXN];
int main() {
cin >> N;
if (N % 4 > 1) {
cout << -1 << endl;
return 0;
}
for (int i = 1, k = 0; k + 4 <= N; i += 2, k += 4) {
ar[i] = i + 1;
ar[i + 1] = N - i + 1;
ar[N - i + 1] = N - i;
ar[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_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n;
cin >> n;
int temp = n / 2;
if (temp % 2 != 0) {
cout << -1 << endl;
return 0;
}
int arr[100010];
if (n % 2 == 1) {
arr[(n / 2) + 1] = n / 2 + 1;
}
for (int 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;
int g[100100];
int main() {
int n;
scanf("%d", &n);
if (((n & 1) && (n - 1) % 4 != 0) || ((n & 1) == 0 && n % 4 != 0))
printf("-1\n");
else {
int ini = n / 2;
for (int i = 1; i < n + 1; ++i) g[i] = -1;
if (n & 1) g[n / 2 + 1] = ini + 1;
for (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;
int N, P[200001];
int main() {
cin >> N;
if (N & 1) {
if (N % 4 == 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;
}
P[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() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
if (n % 4 == 2 || n % 4 == 3)
cout << "-1";
else {
int a[n + 1];
a[n / 2 + 1] = n / 2 + 1;
for (int i = 1; i < n / 2; i += 2) {
a[i] = i + 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[111111];
int main(void) {
int n;
int a = 2, b;
cin >> n;
if (n % 4 > 1) {
cout << -1 << endl;
return 0;
}
b = n;
for (int i = 0; i < n / 2; i++) {
if (i % 2 == 0) {
A[i] = a;
a += 2;
} else {
A[i] = b;
b -= 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.awt.*;
import java.awt.geom.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;
import com.sun.org.apache.bcel.internal.generic.LLOAD;
/*
br = new BufferedReader(new FileReader("input.txt"));
pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
br = 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 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Deque;
import java.util.LinkedList;
import java.util.StringTokenizer;
public class Main {
private void solve() throws 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 | import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Locale;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.RandomAccess;
import java.util.AbstractList;
import java.io.Writer;
import java.util.List;
import java.io.IOException;
import java.math.BigDecimal;
import ... | 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=input()
if n==1:
print 1
if n==2 or n==3:
print -1
from collections import deque
q=deque()
if n>=4:
v=n/4
l1=[]
l2=[]
v2=n%4
for i in range(1,2*(v)+1,2):
q.appendleft(n-i)
q.appendleft(i)
l2.append(i+1)
l2.append(n-i+1)
# print l2,q
if v2==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 | n = int(raw_input())
if n % 4 == 2 or n % 4 == 3 :
print -1
exit()
p = [0] * (n + 1)
if(n % 2 == 1):
p[(n + 1) / 2] = (n + 1) / 2;
for i in range(1, n/2, 2):
p[i] = i + 1
p[n - i + 1] = n - i
p[n - i] = i
p[i + 1] = n + 1 - i
for i in range(1, n):
print p[i],
print p[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 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException... | 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 vis[1000 * 100 + 100];
bool vis2[1000 * 100 + 100];
int val[1000 * 100 + 100];
int main() {
int n;
cin >> n;
if (n % 4 > 1) {
cout << -1 << endl;
return 0;
}
if (n == 1) {
cout << 1 << endl;
return 0;
}
int v = 2;
for (int i = 1; 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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int i, t, j, tmp, n, m, k, cnt, fl, ind;
cin >> n;
if (n % 4 != 0 and n % 4 != 1) {
printf("-1\n");
return 0;
}
vector<int> ar(n);
ar[n / 2] = n / 2 + 1;
i = 0;
j = n - 1;
while (i < j) {
ar[i] = i + 2;
ar[i + 1] = j + 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 i, j, k, x, y, z, n, m;
bool found;
int a[100001];
int main() {
cin >> n;
if (n % 4 == 2 || n % 4 == 3) {
cout << -1 << endl;
return 0;
}
if (n % 2 == 1) {
for (i = 1; i < n / 2 + 1; i += 2) a[i] = i + 1;
for (i = n / 2 + 3; i <= n; i += 2) a[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.*;
import java.math.*;
import java.util.*;
public class SolutionA {
public static void main(String[] args){
new SolutionA().run();
}
int n;
int a[];
void solve(){
n = in.nextInt();
if( n % 4 == 3 || n % 4 == 2){
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 a[100005];
int main() {
int n;
cin >> n;
if (n == 1) {
cout << 1 << endl;
return 0;
}
if (n <= 3) {
cout << -1 << endl;
return 0;
}
if (n % 2 == 0) {
if (n % 4 != 0) {
cout << -1 << endl;
return 0;
}
for (int 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;
void solve() {
int n;
scanf("%d", &n);
if (n % 4 > 1)
printf("-1\n");
else {
for (int i = 1; i <= n >> 1; i++) {
if (i % 2)
printf("%d ", i + 1);
else
printf("%d ", n - i + 2);
}
int m = n >> 1;
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 a[100100];
int main() {
int n;
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3) {
printf("-1\n");
return 0;
}
if (n % 2) a[n / 2 + 1] = n / 2 + 1;
int num1 = 2;
int num2 = n;
for (int i = 1; i <= n / 2; i += 2) {
a[i] = num1;
a[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;
const int N = 111111;
int rec[N];
int main() {
int n;
while (cin >> n) {
if ((n & 3) >= 2) {
puts("-1");
continue;
}
int hf = n >> 1;
for (int i = 1; i <= hf; i++, i++) {
rec[i] = i + 1;
rec[n - i] = i;
}
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 | #include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
return b == 0 ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
int n, v[100010];
int p[100010];
bool flag, z = 0;
void dfs(int id, int s, int ci) {
if (ci == 5) {
flag = 1;
retur... | 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 ans[100010];
bool vst[100010];
void dfs(int pos) {
if (!vst[ans[pos]]) {
vst[ans[pos]] = 1;
ans[ans[pos]] = n - pos + 1;
dfs(ans[pos]);
} else
return;
}
int main() {
while (scanf("%d", &n) != EOF) {
memset(ans, 0, sizeof(ans));
memse... | 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 p287C {
/**
* @param args
*/
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int N = cin.nextInt();
int[] ans = new int[N + 1];
if (N % 4 > 1) {
System.out.println("-1");
} else {
if (N % 2 == 1)
ans[N / 2 + 1] = N / 2 + 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 perm[100001];
int main() {
ios_base::sync_with_stdio(false);
cout.precision(30);
int n;
cin >> n;
if (n % 4 == 2 || n % 4 == 3) {
cout << -1 << endl;
return 0;
}
if (n % 4 == 1) perm[(n + 1) / 2] = (n + 1) / 2;
for (int i = 1; i <= n / 2; i += 2)... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
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 / 2; i += 2) {
printf("%d %d ", i + 1, N - i + 1);
}
if (N % 4 == 1) printf("%d ", (N + 1) / 2);
for (int i = (N + 3) / 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>
using namespace std;
int p[100010];
int N;
int main() {
cin >> N;
int pre;
for (int i = 0; i < N / 4; i++) p[2 * i + 1] = 2 * i + 2;
if (N % 4 == 1) p[N / 2 + 1] = N / 2 + 1;
if (N % 4 != 0 && N % 4 != 1) {
cout << -1 << endl;
return 0;
}
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 | #include <bits/stdc++.h>
int clock0 = clock();
using namespace std;
template <class _T>
inline _T sqr(const _T &first) {
return first * first;
}
template <class _T>
inline string tostr(const _T &a) {
ostringstream os("");
os << a;
return os.str();
}
const long double PI = 3.1415926535897932384626433832795L;
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 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;
final static int MOD = (int) 1e9 + 7;
final static double eps = 1e-9;
final static int INF = (int) 1e9;
public ... | 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, k, a[100100];
int main() {
scanf("%d", &n);
if (n % 4 > 1) {
puts("-1");
return 0;
}
for (i = k = 0; k + 4 <= n; i += 2, k += 4) {
a[i + 1] = i + 2;
a[i + 2] = n - i;
a[n - i] = n - i - 1;
a[n - i - 1] = i + 1;
}
if (k + 1 == n) a[i + 1] = 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 | /**
* Created with IntelliJ IDEA.
* User: yuantian
* Date: 3/24/13
* Time: 12:26 AM
* Copyright (c) 2013 All Right Reserved, http://github.com/tyuan73
*/
import java.util.*;
public class LuckyPermutation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int 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 main() {
ios_base::sync_with_stdio(false);
cin.tie();
cout.tie();
int n, i, ara[100009], cnt;
unordered_map<int, bool> q;
cin >> n;
for (i = 1, cnt = 1; i <= n / 2; i++) {
if (cnt++ % 2) {
if (q[i + 1]) cout << "-1" << '\n', exit(0);
ara[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 double PI = 3.141592653589793238463;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; ++i) {
cin >> p[i];
}
if (n % 4 == 3 || n % 4 == 2) {
cout << -1 << endl;
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 | n = input()
if n%4 in [2, 3]:
print -1
else:
ans = [0 for i in range(n)]
for i in range(0, n/2, 2):
ans[i] = i + 2
ans[i + 1] = n - i
ans[n - i - 1] = n - i - 1
ans[n - i - 2] = i + 1
if n%4 == 1:
ans[n/2] = n/2 + 1
print ' '.join([str(x) for x in ans]) | 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.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
public class C176 {
public static void main(String[] args) {
Scanner in = new Scanner(new BufferedInputStream(System.in));
PrintWriter out = new PrintWriter(new BufferedOut... | 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 a[100000 + 1];
int main() {
int n;
scanf("%d", &n);
if (n % 4 < 2) {
for (int i = 1; i <= n / 2; i += 2) {
a[i] = i + 1;
a[i + 1] = n + 1 - i;
a[n + 1 - i] = n - i;
a[n - i] = i;
}
if (n % 4 == 1) a[n / 2 + 1] = n / 2 + 1;
for (int i = 1; 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 | #include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
long double sqr(long double a) { return a * a; }
const long long int inf = 1000000000000000LL;
long double mpow(long double a, long long int b) {
if (b == 0) return 1.0;
if (b % 2 == 0) {
long double c = mpow(a, b / 2);
return c *... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | n = input()
if n % 4 < 2:
v = [(n + 1) /2] * n
for i in xrange(n / 4):
a = i * 2
v[a],v[a + 1], v[-a-2], v[-a-1] = a + 2, n - a, a + 1, n - a - 1
print ' '.join(map(str, v))
else :
print -1
| PYTHON |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[1 << 17];
int N;
int go(int i) {
a[i] = i + 1;
while (a[a[i]] == 0) {
a[a[i]] = N - i + 1;
i = a[i];
}
return i + a[a[i]] == N + 1;
}
int main() {
scanf("%d", &N);
int good = 1;
for (int i = 1; i <= N; ++i)
if (!a[i]) {
if (i * 2 == 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 arr[100010];
int main() {
int n;
cin >> n;
if (n % 4 == 2 || n % 4 == 3) {
cout << "-1";
return 0;
}
if (n % 4 == 1) {
arr[(n + 1) / 2] = (n + 1) / 2;
}
int rep = n / 4;
int start = 1;
for (int i = 1; i <= rep; i++) {
int tmp1 = 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;
struct node {};
int a[100100];
int main() {
int n, i;
scanf("%d", &n);
if (n % 4 > 1) {
puts("-1");
} else if (n == 1) {
puts("1");
} else {
for (i = 1; i <= n / 2; i += 2) {
a[i] = i + 1;
a[i + 1] = n - i + 1;
a[n - i + 1] = n - i;
... | 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.PrintWriter;
import java.util.Scanner;
public class A {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int n = in.nextInt();
if(n%4==1 || n%4==0){
int a [] = new int[n+1];
for(int i = 1 ; 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 | #include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
x = 0;
char ch = getchar();
int fh = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') fh = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
x *= fh;
}
template <typename... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
void debugarr(int* arr, int n) {
cout << "[";
for (int i = 0; i < n; i++) cout << arr[i] << " ";
cout << "]" << endl;
}
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;
int main() {
int n;
cin >> n;
if (n % 4 == 2 || n % 4 == 3)
cout << "-1" << endl;
else {
int result[200000] = {0};
if (n % 4 == 0) {
for (int i = 0; i < n / 4; i++) {
result[2 * i] = 2 * i + 2;
result[2 * i + 1] = 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()
if n%4<2:
v=[(n+1)/2]*n
for i in range(n/4):
a=i*2
v[a],v[a+1],v[-a-2],v[-a-1]=a+2,n-a,a+1,n-a-1
print ' '.join(map(str,v))
else:
print -1
| PYTHON |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
template <class T>
inline T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
inline T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
void debug(T a, T b) {
for (; a != b; ++a) cerr << *a << ' ';
cerr << endl;
}
template <class... | 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 luckyp {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
if (n % 4 == 2 || n % 4 == 3) {
System.out.println(-1);
return;
}
int[] perm = new int[n+1];
boolean[] used = new boolean[n+1];
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.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
if (n == 1)
System.out.println("1");
else if (n % 4 >= 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;
int n;
int a[100001];
int main() {
cin >> n;
if (n % 4 < 2) {
int m = n / 4;
for (int i = 0; i < (m); i++) {
a[2 * i] = 2 * i + 2;
a[2 * i + 1] = n - 2 * i;
a[n - 1 - 2 * i] = n - 1 - 2 * i;
a[n - 1 - 2 * i - 1] = 2 * i + 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 n, a[200006];
set<int> s;
int main() {
scanf("%d", &n);
if (n == 2 || n == 3) {
printf("-1\n");
return 0;
}
bool f = 1;
int cur = n;
int s = n + 1;
for (int i = n / 2; i >= 1; i--) {
if (f) {
a[i] = cur;
a[n - i + 1] = s - cur;
... | 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())
L=[0]*(n+1)
X=[False]*(n+1)
if(n%4!=0 and n%4!=1):
print(-1)
else:
for i in range(1,n+1):
if(X[i]):
continue
X[i]=True
X[n-i+1]=True
for j in range(i+1,n+1):
if(X[j]):
continue
X[j]=True
X[n-j+1]=T... | 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 inf = (long long)1e9 + 7;
const int N = (int)1e5 + 4;
const int M = 1005;
const int K = 25;
int a[N];
int main() {
int n;
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3) {
printf("-1");
return 0;
}
if (n % 4 == 1) {
a[n / 2] = 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 | import java.io.*;
import java.util.*;
public class My {
public static void main(String[] args) {
new My().go();
}
void go() {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
if (n % 4 == 0 || n % 4 == 1) {
int rn = n / 4;
int[] val = 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
public class ProblemA {
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
PrintWrite... | 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 = input()
if ( (n>>1)&1 ):
print -1;
else:
a = [0 for i in range(n+1)]
for i in range(1, n/2, 2):
a[i]=i+1; a[i+1]=n-i+1; a[n-i+1]=n-i; a[n-i]=i;
if n&1:
a[n>>1|1] = n>>1|1
a.pop(0)
print ' '.join(map(str, a) )
| 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.*;
public class TestClass{
public static void main(String args[]) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] arr = new int[n+1];
if(n%4 > 1) System.out.println(-1);
else{
int loops = n/4;
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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
/**
* Created with IntelliJ IDEA.
* User: ira
* Date: 3/23/13
* Time: 1:40 PM
*/
public class R {
public static void main(String[] args) throws IOException {
BufferedReader re... | 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.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class C {
private static StringTokenizer tokenizer;
private static BufferedReader bf... | 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 nm = 100005;
const int mm = 100005;
int n, k, m, t;
int a[nm];
bool check[nm];
void DO() {
int i, u = 1, j = n, c1 = 2, c2;
int z = n / 4, y;
for (y = 1; y <= z; y++) {
i = u;
a[i] = c1;
c1 += 2;
a[a[i]] = n - i + 1;
i = a[i];
a[a[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.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
public class A{
Scanner sc=new Scanner(System.in);
int INF=1<<28;
double EPS=1e-9;
void test(int n){
int[] is=new int[n];
for(... | 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, V[100010], CrtPos;
bool Used[100010];
int main() {
int i;
scanf("%i", &N);
if (N == 1) {
printf("1\n");
return 0;
}
CrtPos = 1;
V[1] = 2;
bool Move = 1;
while (Move) {
Move = 0;
while (!Used[V[CrtPos]]) {
Used[V[CrtPos]] = 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;
long long n, m, k, q, l, r, x, y;
const long long N = 2e5 + 5;
vector<long long> arr(N);
string s, t;
long long ans = 0;
void solve() {
cin >> n;
map<long long, long long> mp, ans;
for (long long i = 1; i <= n; i++) mp[i] = n - i + 1, ans[i] = mp[i];
if (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;
const double pi = acos(-1.0);
const int intmax = 0x3f3f3f3f;
const long long lldmax = 0x3f3f3f3f3f3f3f3fll;
double eps = 1e-6;
template <class T>
inline void checkmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
inline void checkmax(T &a, T b) {
if (b > a) 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 main() {
ios::sync_with_stdio(0);
long long int n, i;
cin >> n;
if (n == 1) {
cout << 1;
return 0;
}
if (n % 4 == 2 || n % 4 == 3) {
cout << -1;
return 0;
}
long long int a[n];
if (n % 2 == 0) {
for (i = 1; i <= n / 2; i += 2) {
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.PrintWriter;
import java.util.Scanner;
public class Problem3 implements Runnable {
public int n;
public int [] p;
public boolean [] used;
public boolean isGood() {
for (int i = 0; i < n; i++) {
if (p[p[i] - 1] != n - (i + 1) + 1) {
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 | import java.util.*;
import java.io.*;
public class Main {
BufferedReader in;
StringTokenizer str = null;
PrintWriter out;
private String next() throws Exception{
if (str == null || !str.hasMoreElements())
str = new StringTokenizer(in.readLine());
return str.nextToken();
}
private int nextInt() throws... | 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[100005];
int place[100005];
int main() {
int n;
cin >> n;
if (n % 4 >= 2)
cout << -1 << endl;
else {
for (int i = 0; i < n / 2; i += 2) {
a[i] = i + 2;
a[i + 1] = n + 2 - a[i];
}
for (int i = n - 1; i > n / 2; i -= 2) {
a[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.*;
public class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
if ((n / 2) % 2 == 1)
{
System.out.println(-1);
return;
}
int[] ans = new int[n + 5];
if (n % 2 == 1)
{
ans[(n + 1) / 2] = (n + 1) / 2;
}
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>
int main() {
int n, i;
scanf("%d", &n);
if (n % 4 == 0) {
for (i = 1; i <= n / 2; i += 2) {
printf("%d %d ", i + 1, n + 1 - i);
}
for (i = n / 2 + 2; i < n; i += 2) {
printf("%d %d ", n + 1 - i, i - 1);
}
printf("%d %d\n", n + 1 - i, i - 1);
} else if (n ... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
static const int INF = 500000000;
template <class T>
void debug(T a, T b) {
for (; a != b; ++a) cerr << *a << ' ';
cerr << endl;
}
int n;
int ar[100005];
int main() {
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3) {
puts("-1");
return 0;
}
for (int 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.*;
import java.lang.*;
public class templ {
public static int a[]=new int[1000000];
int binarySearch(long arr[], int l, int r, long x)
{
if (r >= l)
{
int mid = l + (r - l)/2;
if (arr[mid] == x)
return mid;
... | 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 a[100010];
int main() {
int n;
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3)
printf("-1");
else {
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 - i] = i;
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n).
A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
int c[100001];
void init() {
scanf("%d", &n);
memset(c, 0, sizeof(c));
}
void work() {
if (n == 1) {
printf("1");
return;
}
if ((n / 2) & 1) {
printf("-1");
return;
}
for (int i = 1; i <= n / 2; i += 2) {
c[i] = i + 1;
c[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(input())
if n % 4 > 1:
print(-1)
exit()
a = [i for i in range(0, n+1)]
for i in range(1, n//2+1, 2):
p, q, r, s = i, i+1, n-i,n-i+1
a[p], a[q], a[r], a[s] = a[q], a[s], a[p], a[r]
def check(arr):
for i in range(1, n+1):
k = arr[i]
if arr[arr[k]] != n-k+1:
retur... | 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;
cin >> n;
if (n % 4 == 2 || n % 4 == 3) {
cout << -1;
return 0;
}
int a[n + 1];
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 - 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 = int(input())
if n % 4 > 1: print(-1)
else:
k = n // 2
t = [0] * n
for i in range(0, k, 2):
t[i] = str(i + 2)
for i in range(1, k, 2):
t[i] = str(n - i + 1)
if n & 1:
k += 1
t[k - 1] = str(k)
for i in range(k, n, 2):
t[i] = str(n - i - 1)
for i in r... | 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;
template <class T, class U>
bool cmp_second(const pair<T, U> &a, const pair<T, U> &b) {
return a.second < b.second;
}
pair<int, int> operator+(const pair<int, int> &a, const pair<int, int> &b) {
return make_pair(a.first + b.first, a.second + b.second);
}
pair<int, 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;
int n;
bool ans = true;
int a[105000], p[105000];
bool u[105000];
queue<int> q;
void dfs(int pos) {
u[p[pos]] = true;
int to = a[pos];
if (!u[to]) {
p[p[pos]] = to;
dfs(p[pos]);
}
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) a[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.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class LuckyPermutation {
/*
index , val
i, f(i)
f(i),n-i+1
n-i+1,n-f(i)+1
n-f(i)+1,i
if n-i+1 = i -> 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 = 100000 + 9;
int a[MAXN];
int main() {
int n, i;
scanf("%d", &n);
if (n % 4 > 1) {
puts("-1");
return 0;
}
if (n % 4) {
a[n / 2 + 1] = n / 2 + 1;
}
for (i = 1; i * 2 < n; i += 2) {
a[n - i] = i;
a[i] = i + 1;
a[i + 1] = n - 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 | n = input()
a = [i + 1 for i in range(n)]
if n % 4 > 1:
print -1
else:
for i in range(0,n / 2, 2):
a[n - i - 1] = n - i - 1
a[n - i - 2] = i + 1
a[i] = i + 2
a[i + 1] = n - i
print " ".join(map(str,a)) | 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 maxn = 100000 + 100;
int p[maxn];
int main() {
int n;
scanf("%d", &n);
int i, j;
if (n == 1) {
printf("1\n");
return 0;
}
if (n % 2 == 0) {
if (n % 4) {
printf("-1\n");
return 0;
}
int l, r;
l = 0;
r = 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 main() {
int n;
cin >> n;
if (n == 1) {
cout << "1\n";
return 0;
} else if (n % 4 == 2 || n % 4 == 3) {
cout << "-1\n";
return 0;
}
int arr[n + 1], k = 2;
if (n % 2 == 1) {
arr[(n + 1) / 2] = (n + 1) / 2;
}
int i = 1;
while (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 | '''
from itertools import permutations
def main():
for num in xrange(1, 12):
print num
per = range(1, num+1)
for it in permutations(per, num):
if judge(it) == True:
print it
def judge(tup):
n = len(tup)
for i in xrange(n):
if not tup[ tup[i]-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;
__inline bool nextInt(int &val) {
char ch;
int sgn = 1;
while ((ch = getchar()) != EOF) {
if (ch == '-') sgn = -1;
if (ch >= '0' && ch <= '9') break;
}
if (ch == EOF) return false;
val = (int)(ch - '0');
while (true) {
ch = getchar();
if (ch >=... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.