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(raw_input())
ans = {}
start = 1
end = n
while end - start + 1 >= 4:
ans[start] = start + 1
ans[start + 1] = end
ans[end] = end - 1
ans[end - 1] = start
start += 2
end -= 2
if (end - start + 1) <= 1:
if end - start + 1 == 1:
ans[end] = end
for i in range(1, n + 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 | 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 {
static StringTokenizer st;
static BufferedReader in;
static 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 | #include <bits/stdc++.h>
using namespace std;
const double eps(1e-8);
int p[110000];
void did(int a, int b, int n) {
for (int i = (1); i <= (4); ++i) {
p[a] = b;
int tmp = b;
b = n - a + 1;
a = tmp;
}
}
bool solve(int n) {
if (n % 4 == 2 || n % 4 == 3) return false;
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 perm[100010];
int main(void) {
int n;
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3) {
printf("-1\n");
} else {
for (int i = 1; i <= n / 2; i++) {
if (i % 2 == 1) {
perm[i] = n - i;
int iter = i;
for (int j = 0; j < 3; 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 | #include <bits/stdc++.h>
using namespace std;
template <class T>
bool func(T a, T b) {
return a < b;
}
int main(int argc, const char *argv[]) {
long long *a, b, i, j, n, k;
cin >> n;
if (n % 4 > 1)
cout << "-1";
else {
b = n / 4;
a = new long long[n + 1];
for (k = 1; k <= b; k++) {
j = 2... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.*;
import java.util.*;
public class Main{
static PrintWriter out=new PrintWriter(System.out);
static void output(int l,int r){
if(l<r){
out.print(1+l+" "+r+" ");
output(2+l,r-2);
out.print(l+" "+(r-1)+" ");
}else if(l==r) out.print(l+" ");
}
public static void main(String[]args){
Scann... | 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;
#pragma comment(linker, "/STACK:102400000,102400000")
template <class T>
T _max(T x, T y) {
return x > y ? x : y;
}
template <class T>
T _min(T x, T y) {
return x < y ? x : y;
}
template <class T>
T _abs(T x) {
return (x < 0) ? -x : x;
}
template <class T>
T _mod(T x,... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const int MAXN = 100000 + 9;
template <class T>
inline T f_min(T a, T b) {
return a < b ? a : b;
}
template <class T>
inline T f_max(T a, T b) {
return a > b ? a : b;
}
template <class T>
inline T f_abs(T a) {
return a > 0 ? a : -a;
}
tem... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[100010];
int n;
void work(int l, int r) {
if (l > r) return;
if (l == r) {
a[l] = l;
return;
}
a[l] = l + 1;
a[l + 1] = r;
a[r - 1] = l;
a[r] = r - 1;
work(l + 2, r - 2);
}
int main() {
cin >> n;
if (n == 1) {
puts("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;
int a[100010], n;
int main() {
while (scanf("%d", &n) != EOF) {
if (n % 4 > 1)
puts("-1");
else {
int stpos = 1, edpos = n - 1;
int stval = 2, edval = 1;
for (int i = 0; i < n / 4; i++) {
a[stpos] = stval;
a[edpos] = edval;
... | 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.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import ja... | 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.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
*... | 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.lang.*;
import java.math.BigInteger;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Main
{
static StringTokenizer st=new StringTokenizer("");
static BufferedReader br;
////////////////////////... | 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 C176
{
public static void main(String[] args)
{
new C176();
}
public C176()
{
Scanner in = new Scanner(System.in);
int n = Integer.parseInt(in.nextLine());
if(n % 4 != 1 && n % 4 != 0)
System.out.println("-1");
else
{
int[] arr = new int... | 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 CFB {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
private static final long MOD = 1000L * 1000L * 1000L + 7;
private static final int[] dx = {0, -1, 0, 1};
private static final int[] dy = {1, 0, -1, 0};
private... | 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.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
public class C {
static PrintWriter out;
static StreamTokenizer st;
static BufferedReader bf;
public static void main(String[]... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int p[100005];
bool m[100005];
int cnt;
int n;
void rec(int k) {
if (m[k]) return;
m[k] = true;
p[p[k]] = (n - (k) + 1);
cnt++;
rec(p[k]);
}
int main() {
scanf(" %d", &n);
for (int i = 1; i <= n; i++)
if ((n - (i) + 1) == i) p[i] = i, m[i] = true, cnt++;
... | 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 Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
sc.close();
if (n % 4 == 2 || n % 4 == 3)
System.out.println(-1);
else {
int[] num = ... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int P = 1e9 + 7, INF = 0x3f3f3f3f;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long qpow(long long a, long long n) {
long long r = 1 % P;
for (a %= P; n; a = a * a % P, n >>= 1)
if (n & 1) r = r * a % P;
return r;
}
long lo... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | '''
Created on
@author: linhz
'''
import sys
usedNum=0
n=int(input())
p=[0 for i in range(n+1)]
usedNum=0
if n%4==3 or n%4==2:
print(-1)
else:
i=1
j=n
a=1
b=n
while j>i:
p[i]=a+1
p[i+1]=b
p[j]=b-1
p[j-1]=a
i+=2
j-=2
a+=2
b-=2
i... | 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 int OO = (int)2e9;
const double eps = 1e-9;
int arr[100005];
int main() {
std::ios_base::sync_with_stdio(false);
int i, n;
cin >> n;
if (!((n & 3) && ((n - 1) & 3))) {
if (n & 1) arr[n / 2 + 1] = n / 2 + 1;
for (i = 1; i < n / 2; i += 2) {
arr[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.util.*;
public class A {
void solve() throws IOException {
int n = nextInt();
if (n % 4 == 2 || n % 4 == 3) {
out.println("-1");
return;
}
int[] res = new int[n];
int down = 1;
int up = n;
for (int i = 0; up - down + 1 >= 4; i += 2) {
res[i] = down + 1;
res[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 main() {
int n;
cin >> n;
if (n % 4 == 3 || n % 4 == 2) {
cout << "-1";
}
if (n % 4 == 0) {
for (int i = 0; i < n / 2; i += 2) {
cout << (i + 2) << " ";
cout << n - i << " ";
}
for (int i = 1; i < n / 2; i += 2) {
cout << n / ... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
int v[100005];
int main() {
cin >> n;
if (n % 4 == 2 || n % 4 == 3) {
cout << -1;
return 0;
}
for (int i = 2; i <= n / 2; i += 2) v[i - 1] = i, v[i] = n + 2 - i;
if (n % 2) v[n / 2 + 1] = n / 2 + 1;
for (int i = n / 2 - 1, j = 1; i >= 1; i -= 2, 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 | n = int(raw_input())
if n % 4 > 1:
print -1
exit()
a = [i for i in xrange(n)]
for i in xrange(0, n / 2, 2):
a[i] = i + 1
a[i + 1] = n - i - 1
a[n - i - 1] = n - i - 2
a[n - i - 2] = i
print ' '.join([str(i + 1) for i in 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.util.Scanner;
public class C {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n = sc.nextInt();
if ((n - 1) % 4 == 1 || (n - 1) % 4 == 2) {
System.out.println("-1");
return;
}
if (n % 2 == 0) {
for (int i = 0; i < n/2; i += 2) {
System.out.print(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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
public class TC
{
static int N;
static void print( int[] a )
{
for( int i=1; i<=N; i++ )
System.out.print( a[i] + " ");
System.out.println();
}
... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.util.*;
public class Main {
public static long calc(long k, long n) {
long l = 2, r = k + 1, mid, tmp;
while ( l < r ) {
mid = (l + r) / 2;
tmp = (k - mid + 1) * (k + mid) / 2 - (k - mid);
if ( tmp <= n ) r = mid;
else l = mid + 1;
}
return l;
}
public static void main(String[]... | 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 solve() {
int n;
if (scanf("%d", &n) == EOF) return false;
if (n % 4 > 1) {
printf("-1\n");
return true;
}
vector<int> ans(n);
for (int i = 0; i < n / 4; ++i) {
ans[i * 2] = i * 2 + 1;
ans[i * 2 + 1] = n - i * 2 - 1;
ans[n - i * 2 - 1] =... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.InputStreamReader;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution ... | 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 main() {
int n;
scanf("%d", &n);
if (n % 4 > 1) {
printf("-1\n");
return 0;
}
int p[N];
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 % ... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
Outpu... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int arr[maxn];
int main() {
int n;
cin >> n;
if ((n >> 1) & 1) return 0 * printf("-1\n");
for (int i = 0; i < n + 1; i++) arr[i] = i;
for (int i = 1; i <= n; i += 2) {
if (n & 1 && i == n / 2 + 1) i++;
swap(arr[i], arr[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==2 or n%4==3:
from sys import exit
print(-1);exit()
res,i=[0]*n,0
for i in range(0,n//2,2):
res[i],res[i+1]=i+2,n-i
res[n-i-1],res[n-i-2]=n-i-1,i+1
i+=2
if n%4==1:res[n//2]=n//2+1
print(*res) | 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 static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import java.io.*;
public class A {
final static boolean autoflush = false;
public A () {
int N = sc.nextInt();
sc = null;
int [] res = new int [N];
switch(N%4) {
... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.util.Scanner;
public class c_176 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if ((n - 1) % 4 == 1 || (n - 1) % 4 == 2) {
System.out.println(-1);
return;
}
for (int i = 2; i <= n / 2; i += 2) {
System.out.print(i + " " + ((n + 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 Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.writ... | 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 num[100005] = {0};
int flag[100005] = {0};
int main() {
int n;
scanf("%d", &n);
if (n == 1)
printf("1\n");
else if (n >= 4) {
int kflag;
if (n % 2 == 1) num[(n + 1) / 2] = (n + 1) / 2;
while (1) {
int flags = 0;
kflag = 0;
for (... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.util.*;
import java.lang.*;
public class Main
{
public static void main (String[] args) throws java.lang.Exception
{
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
if((n%4==2)||(n%4==3)){
System.out.println(-1);
}
else{
... | 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 vis[100006];
int a[100005];
int ans[100005];
int main() {
ios_base::sync_with_stdio(false);
int i, j, k, x, n, t;
cin >> n;
if (n % 4 != 1 && n % 4 != 0) {
cout << -1 << endl;
return 0;
}
for (i = 1; i <= (n + 1) / 2; i += 2) {
if (i == (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>
int arr[100010];
int main() {
int n, counts, index, to, i, j, a, b;
scanf("%d", &n);
if (n == 1) {
printf("1\n");
return 0;
}
if (n == 2) {
printf("-1\n");
return 0;
}
if ((n % 4) > 1) {
printf("-1\n");
return 0;
}
a = 1;
b = 2;
for (i = 0; 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;
long long pow(long long b, long long e, long long m) {
long long t = 1;
for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0;
return t;
}
template <class T>
inline bool chkmin(T &a, T b) {
return a > b ? a = b, true : false;
}
template <class T>
inline bool 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 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws IOException {
(new Main()).solve();
}
public Main() {
}
MyReader in = new MyReader();
PrintWriter out = new PrintWriter(System.out);
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 | #include <bits/stdc++.h>
using namespace std;
int m, k;
int n;
int p[100100];
int main() {
scanf("%d", &n);
if (n == 1) {
printf("1\n");
return 0;
}
if (n == 2 || n == 3) {
printf("-1\n");
return 0;
}
int a = 1;
set<int> per;
for (int i = 2; i <= n; i++) per.insert(i);
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 | import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
import java.util.ArrayList;
public class Main {
static int d[][];
static int N;
static boolean used[];
static class point
{
int x = 0... | 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.*;
import java.math.*;
import java.awt.geom.*;
import static java.lang.Math.*;
public class Solution implements Runnable {
public void solve() throws Exception {
int n = sc.nextInt();
if (n % 4 == 2 || n % 4 == 3) {
out.println(-1);
} else {
... | 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 | #br = open('c.in')
n = int(raw_input())
if n == 1:
print 1
exit()
a = [0 for i in range(n + 1)]
i, c, a[i], s, l = 1, 0, 2, 2, 1
while c < n - 2:
t = a[i]
s = n - i + 1
if a[t] != 0:
t += 2
s += 2
if s == l:
l += 2
a[t] = s
i = t
c += 1
a = [l if x == 0 else x for x in a]
can = 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;
long long power(long long a, long long n, long long lelo) {
if (n == 0) return 1;
if (n == 1) return a;
if (n == 2) return (a * a) % lelo;
if (n % 2)
return (a * power(a, n - 1, lelo)) % lelo;
else
return power(power(a, n / 2, lelo), 2, lelo) % lelo;
}
voi... | 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[100015];
int N;
int main() {
cin >> N;
int s = 1, e = N;
bool fail = false;
int left = N;
while (true) {
if (left == 0) {
break;
} else if (left == 1) {
arr[s] = s;
break;
} else if (left >= 4) {
arr[s] = s + 1;
ar... | 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//2)&1:
print(-1)
else:
ans=[0]*(n+1)
for i in range(1,(n//2)+1,2):
ans[i]=i+1
ans[i+1]=n-i+1
ans[n-i+1]=n-i
ans[n-i]=i
if n%2:
ans[(n//2)+1]=(n//2)+1
print(*ans[1:])
| PYTHON3 |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
struct Node {
int k, x;
};
int p[100010];
int N;
bool doit(int s) {
int i;
for (i = 1; i <= N; i++)
if (p[i] == 0) {
static Node q[100010];
int head = 1, tail = 2;
q[1].k = s, q[1].x = i;
p[s] = i;
bool flag = true;
while (head ... | 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 math import *
n = int(input())
if n == 1:
print(1)
elif n % 4 in [2, 3]:
print(-1)
else:
ans = [0] * n
for i in range(n // 2):
if i & 1:
ans[i] = n - 2 * (i // 2)
else:
ans[i] = 2 + i
for i in range(1, (n // 2), 2):
ans[ans[i] - 1] = n - i
... | 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 int NMAX = 100005;
int A[NMAX];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
bool ok = true;
if (n % 2 == 1) {
if ((n - 1) % 4 == 0) {
for (int i = 1; i <= n / 2; i += 2) {
A[i] = i + 1;
A[i + 1] = n - i + 1;
A... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 4 == 0 || n % 4 == 1) {
int arr[n];
int j = 0;
for (int i = 0; i < n / 4; i++) {
arr[j] = j + 2;
arr[j + 1] = n - j;
arr[n - j - 1] = n - j - 1;
arr[n - j - 2] = j + 1;
j += 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>
int num[100100];
int n;
int main() {
scanf("%d", &n);
if (n % 4 != 0 && n % 4 != 1) {
puts("-1");
return 0;
}
if (n % 2 == 1) num[n / 2] = n / 2 + 1;
for (int i = 0, j = 0; j < n - n % 2; i += 2, j += 4) {
num[i] = 2 + i;
num[i + 1] = n - i;
num[n - 1 - i] = 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 n, ans[100010];
int main() {
while (scanf("%d", &n) == 1) {
int i;
if ((n & 3) == 2 || (n & 3) == 3) {
puts("-1");
continue;
}
for (i = 1; i <= n / 2; i += 2) {
ans[i] = i + 1, ans[n - i + 1] = n - i;
ans[i + 1] = n - i + 1, ans... | 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.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.Writer;
import java.math.BigInteger;
import java.io.InputStream;
/**
*... | 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[100005];
int main() {
int n;
cin >> n;
if (n % 4 == 1) {
v[50001] = 1;
int st = 50000;
int dr = 50002;
for (int i = 1, n1 = 1; i < n; i += 4, n1 += 4) {
v[st] = n1 + 4;
st--;
v[st] = 2;
st--;
v[dr] = 1;
dr++;
... | 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() {
long long int i, j, k, n, m, t, a[100001];
cin >> n;
if ((n % 4 != 0) && (n - 1) % 4 != 0) {
cout << "-1";
return 0;
}
if (n % 4 == 0) {
for (i = 1, j = n; i <= n / 2; i += 2, j -= 2) {
a[i] = i + 1;
a[j - 1] = i;
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 n, l, r, i, j, k;
int a[100005];
int main() {
scanf("%d", &n);
if ((n % 4 == 0) || ((n - 1) % 4 == 0)) {
l = 1;
r = n;
for (k = 1; k <= n / 4; k++) {
a[l] = l + 1;
a[r] = r - 1;
a[l + 1] = r;
a[r - 1] = l;
l += 2;
r -=... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
public class R176qCLuckyPermutation {
static int ans[];
public static void main(String args[]) throws Exception {
InputReader in = new InputReader(System.in);
... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[100006];
int main() {
int n;
while (scanf("%d", &n) != EOF) {
if (n == 1)
puts("1");
else if (n == 2)
puts("-1");
else {
int delta = n;
for (int i = 1; i <= n && delta > 0; i++) {
if (i == 1)
a[1] = 2;
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.*;
import java.util.*;
import java.lang.*;
public class A286A{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
int t,l,r,max,min;
int arr[]= new int[n+1];
if(n%2==0){
l=n/2;
r=n/2 + 1;
max=n;
min=1;
while(min<max){
... | 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, p[1000007];
int main() {
scanf("%d", &n);
if (n == 1) {
puts("1");
return 0;
}
if (n % 4 == 2 || n % 4 == 3) {
puts("-1");
return 0;
}
if (n % 4 == 0) {
for (int i = 0; i < n / 2; i += 2) {
int a1 = i;
int a2 = i + 1;
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int* array;
int n;
cin >> n;
if (n == 1)
cout << 1 << endl;
else if (n == 2 || n == 3 || ((n % 2 != 0) && ((n / 2) % 2 != 0)) ||
((n % 2 == 0) && ((n / 2) % 2 != 0)))
cout << -1 << endl;
else {
array = new int[n];
if (n & ... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const long long int mx = 1e6 + 10, inf = 1e9 + 10;
int n, a[mx], g, h;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
if (n % 4 > 1) {
cout << -1;
return 0;
}
g = 2;
h = n - 2;
a[n / 2] = n / 2 + 1;
for (long long 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;
int a[100005];
int main() {
int n;
int i;
cin >> n;
if (n % 4 == 3 || n % 4 == 2) {
cout << -1;
return 0;
}
for (i = 1; i <= n / 2; i = 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)... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import sys
def main() :
n = [ int( x ) for x in sys.stdin.readline().strip().split() ][ 0 ]
if n % 4 == 2 or n % 4 == 3 :
print -1
return
res = []
k = 1
while k + 1 <= n / 2 :
res.append( n - k )
res.append( k )
k += 2
k -= 2
if n % 2 == 1 :
r... | PYTHON |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
int mas[(int)1e5 + 10];
int main() {
int n;
scanf("%d", &n);
int m = n;
int q = 0;
int w = 0;
while (n >= 4) {
mas[q] = 2 + w;
mas[q + 1] = n + w;
mas[m - 1 - q] = n - 1 + w;
mas[m - 2 - q] = 1 + w;
q += 2;
w += 2;
n -= 4;
}
if (n == 1) {
mas[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;
const int maxn = 100111;
int p[maxn];
bool vist[maxn];
int n;
void dfs(int cur) {
vist[cur] = 1;
if (p[p[cur]]) {
return;
}
p[p[cur]] = n - cur + 1;
dfs(p[cur]);
}
int main() {
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3)
puts("-1");
else {
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 mark[100002], p[100002];
int main() {
int t, n;
while (scanf("%d", &n) != EOF) {
int next = 2;
mark[0] = 0;
for (int i = 1; i <= n; i++) {
mark[i] = 0;
p[i] = 0;
}
int f = 0;
for (int i = 1; i <= n; i++) {
if (p[i] != 0) con... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.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 A {
static StringTokenizer st;
static BufferedReader in;
public sta... | 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.math.*;
import static java.lang.Math.*;
import java.security.SecureRandom;
import static java.util.Arrays.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import sun.misc.Regexp;
import java.awt.geom.*;
import sun.net.www.content.text.plain;
public cla... | 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.*;
public class Task286A {
public static void main(String... args) throws NumberFormatException,
IOException {
Solution.main(System.in, System.out);
}
static class Scanner {
private final BufferedReader br;
private String[] cache;
private int ca... | 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 perm[100010 + 1];
using namespace std;
int main() {
int n;
cin >> n;
int s = 1;
int e = n;
while (e - s > 0) {
perm[s] = s + 1;
perm[s + 1] = e;
perm[e] = e - 1;
perm[e - 1] = s;
s += 2;
e -= 2;
}
if (s == e) perm[s] = s;
if ((n % 4) > 1)
cout << ... | 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;
vector<int> arr(n + 1);
for (int cnt = 1; cnt <= n; cnt++) {
if (cnt * 2 == 1 + n)
arr[cnt] = cnt;
else if (cnt <= n / 2) {
if (cnt % 2)
arr[cnt] = cnt + 1;
else
arr[cnt] = n - cnt + 2;
} el... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | /*
* To change this 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 LuckyPermutation {
/**
... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using... | 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 mas[100000];
int main() {
int N;
scanf("%d", &N);
if (N % 4 > 1)
printf("-1\n");
else {
int start = 0;
int finish = N - 1;
while (finish - start > 0) {
mas[start] = start + 1;
mas[start + 1] = finish;
mas[finish] = finish - 1;
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 4 == 1 || n % 4 == 0) {
int *result = new int[n + 1];
if (n % 2 == 1) {
result[(n + 1) / 2] = n / 2 + 1;
}
for (int i = 1; i < (n + 1) / 2; i += 2) {
result[i] = i + 1;
result[i + 1] = n + 1 - i;
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
int ans[100002];
int main() {
int i, N, l, r;
scanf("%d", &N);
if (!(N % 4 <= 1)) {
printf("-1\n");
return 0;
}
l = 2;
r = N;
for (i = 1; i <= N / 2; i += 2) {
ans[i] = l;
ans[i + 1] = r;
ans[N + 1 - i] = r - 1;
ans[N - i] = l - 1;
l += 2;
r -= 2;
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int t, n, m, i, j, l = 0, k, c = 0, v = 0, x, r = 0, used[1000001] = {0},
a[1000001], b[1000001];
char s[1000001], s2[1000001];
int main() {
scanf("%d", &n);
if (n % 4 == 2 || n % 4 == 3) {
printf("-1");
return 0;
... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
public class A implements Runnable {
public void solve() throws IOException {
int n = in.nextInt();
if ( n % 4 == 2 || n % 4 == 3 ) {
out.println( -1 );
return;
}
for ( int i = 1;... | JAVA |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
vector<int> a;
int main() {
cin >> n;
if (n % 4 == 2 || n % 4 == 3) {
cout << -1 << endl;
return 0;
}
a.resize(n + 1);
if (n % 4 == 1) a[(n + 1) / 2] = (n + 1) / 2;
int l = 1, r = n;
while (r - l >= 3) {
a[l] = l + 1;
a[l + 1] = r;
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 | import java.io.*;
import java.util.*;
public class C
{
static int n = 1;
public static void main(String [] args) throws IOException
{
Scanner in = new Scanner(System.in);
int n = in.nextInt();
PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
if(!(n%4 == 0 || n%4 == 1))
{
System... | 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, ar[100005], mark[100005];
void sifir() {
for (int i = 2, j = N; i <= N / 2; i += 2, j -= 2) printf("%d %d ", i, j);
for (int i = N / 2 - 1, j = N / 2 + 1; i > 0; i -= 2, j += 2)
printf("%d %d ", i, j);
}
void bir() {
int orta = N / 2 + 1;
for (int 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, c, idx, a[100001];
int main() {
scanf("%d", &n);
if (n % 4 > 1) return printf("-1\n"), 0;
c = 2, idx = 0;
for (int i = 0; i < n / 4; ++i) {
a[idx] = c;
idx += 2, c += 2;
}
c = n, idx = 1;
for (int i = 0; i < n / 4; ++i) {
a[idx] = c;
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;
int que[100010];
int main() {
int n, i;
scanf("%d", &n);
if (!(n % 4 == 1 || n % 4 == 0)) {
printf("-1\n");
return 0;
}
for (i = 1; i <= n / 2; i += 2) que[i] = i + 1;
for (i = 2; i <= n / 2; i += 2) que[i] = n + 2 - i;
for (i = n / 2 + 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 | n = input()
ans = [0 for i in xrange(n + 1)]
s = 1
e = n
while e - s + 1 >= 4:
ans[s] = s + 1
ans[s + 1] = e
ans[e] = e - 1
ans[e - 1] = s
s += 2
e -= 2
if e - s + 1 <= 1:
if(e - s + 1 == 1):
ans[e] = e
for i in range(1, n + 1):
print ans[i],
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;
const int N = 1e5 + 7;
int n, p[N];
void solve(int n) {
if ((n & 1) && (n - 1) % 4) {
puts("-1");
return;
}
if (!(n & 1) && n % 4) {
puts("-1");
return;
}
if (n & 1) p[(n + 1) >> 1] = (n + 1) >> 1;
for (int i = (1); i < ((n >> 1) + 1); ++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 arr[1000000];
int main() {
int n;
while (scanf("%d", &n) != -1) {
if (n == 1) {
printf("1\n");
continue;
}
if ((n & 1) && (n - 1) % 4) {
printf("-1\n");
continue;
}
if (!(n & 1) && n % 4) {
printf("-1\n");
cont... | 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;
const long long INF = 1000000000000000;
const long long m = 1000000007;
int a[MAXN];
long long binpow(long long v, long long st) {
long long ans = 1, a = v;
for (; st; st >>= 1) {
if (st & 1) ans *= a;
a *= a;
}
return ans;
}
int ma... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[100005];
int n;
int main() {
while (cin >> n) {
if (n % 4 == 2 || n % 4 == 3) {
puts("-1");
continue;
}
if (n % 4) a[n / 2 + 1] = n / 2 + 1;
for (int i = 1; i <= n / 2; i += 2) {
a[i] = i + 1;
a[i + 1] = n + 1 - i;
a[n -... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | import java.io.*;
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner cin=new Scanner(System.in);
int n=cin.nextInt(),i=0,Q[];
PrintWriter out=new PrintWriter(System.out);
if(2>(3&n)){
Q=new int[n--];
for(Q[n>>1]=2+n>>1;i<n;n-=2){
Q[i++]=n;Q[i]=i;
Q[n-1]=1+n;Q[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;
const int MAX = 1e5 + 5;
int ans[MAX];
int main() {
int n;
scanf("%d", &n);
if (n % 4 >= 2) return 0 * printf("-1\n");
int a = 2, b = n, idx = 1;
for (int i = 1; i <= n / 4; ++i) {
ans[idx] = a;
ans[idx + 1] = b;
ans[n - idx + 1] = b - 1;
ans[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>
#pragma comment(linker, "/stack:64000000")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000 * 1000 * 1000;
const double EPS = 1e-9;
const long double PI = acos(-1.0);
int main() {
int n;
cin >> n;
vector<int> a(n + 1);
if (n % 4 == 2 || n % 4 == 3) {
cout << -1 ... | CPP |
287_C. Lucky Permutation | A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 β€ pi β€ n).
A lucky permutation is such permutation p, that any integer i (1 β€ i β€ n) meets this condition ppi = n - i + 1.
You have integer n. Find some lucky permutation p of size n.
Input
T... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
string tostr(long long x) {
stringstream ss;
ss << x;
return ss.str();
}
long long toint(string &s) {
stringstream ss;
ss << s;
long long x;
ss >> x;
return x;
}
void print(vector<int> p) {
for (int i = 0; i < p.size(); i++) {
cout << 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 N;
vector<int> v;
void dog(int a, int b, int c, int d) {
v[a - 1] = b;
v[b - 1] = d;
v[d - 1] = c;
v[c - 1] = a;
}
int main() {
cin >> N;
v.resize(N);
if (N % 4 > 1) {
cout << -1 << endl;
return 0;
}
if (N & 1) {
int spc = N / 2 + 1;
v[... | 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 imod = 1e9 + 7;
const long long lmod = 1e18 + 7;
const int iinf = INT_MAX;
const long long linf = LONG_MAX;
const double pi = 2 * acos(0.0);
const double eps = 1e-7;
int n;
int a[(int)1e6 + 134];
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(0);
co... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.