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 |
|---|---|---|---|---|---|
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, t;
cin >> t;
while (t--) {
cin >> n;
int b[n + 1], a[2 * n + 1];
bool marked[2 * n + 1];
memset(a, -1, sizeof a);
memset(marked, true, sizeof marked);
bool yes = true;
fo... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t = int(input())
res = []
for i in range (t) :
n = input()
n = int(n)
b = input().split()
a=[0]*(2*n)
for j in range (n) :
b[j] = int(b[j])
for j in range (n) :
a[2*j]=b[j]
index=1
fuck = True
for j in range (1,2*n+1) :
if not j in a :
flag = True
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t=int(input())
for _ in range(t):
n=int(input())
B=[int(i) for i in input().split()]
BB=set(B)
Chk=True
Ans=[]
Used=[True]*(2*n)
for i in range(2*n):
if i+1 in BB:
Used[i]=False
for b in B:
Ans.append(b)
for i in range(b,2*n):
if Used[i]:
Ans.append(i+1)
Used[i]=F... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t=int(input())
for ii in range(t):
n=int(input())
flag=True
a=[int(i) for i in input().split()]
t=n*2
b=[0]*(t+1)
c=[]
for i in a:
if i==t:
flag=False
break
b[i]=1
if flag==False:
print(-1)
else:
for i in a:
c.append... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long b[n];
for (long long i = 0; i < n; i++) cin >> b[i];
bool c[2 * n + 1];
memset(c, true, 2 * n + 1);
long long a[2 * n];
memset(a, -1, 2 * n);
for (lo... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;
import java.text.*;
import java.math.*;
import java.util.*;
public class Main implements Runnable {
public int getMin(boolean isUsed[], int val, int n){
int min=-1;
for(int v=val;v<... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t=int(input())
while(t>0):
n=int(input())
C=list(map(int,input().split()))
A=[]
for i in range(0,n):
A.append(C[i])
for j in range(C[i]+1,1000):
if(j not in A and j not in C):
A.append(j)
break
D=[]
s=2*n
for i in range(0,s):
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | /* package codechef; // don't place package name! */
// for(i=0;i<n;i++)
// for(j=0;j<n;j++)
// int n=sc.nextInt();
// int a[]=new int[n];
// a[i]=sc.nextInt();
// ArrayList<Integer> ar=new ArrayList<Integer>();
// System.out.println();
// HashMap<String, Integer> map
// = new HashMap<>();
import java.ut... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | from sys import stdin
from math import sqrt, factorial, ceil
from collections import Counter, defaultdict
from heapq import heapify, heapreplace, heappush, heappop
from bisect import bisect_left
t=int(stdin.readline())
while t:
t-=1
n=int(stdin.readline())
b=list(map(int,stdin.readline().split()))
a=[0... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void faster() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
if (0) {
freopen(
"input"
"sum.in",
"r", stdin);
freopen(
"input"
"sum.out",
"w", stdout);
}
}
long long gcd(long long a, long long... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void compute() {
int n;
cin >> n;
vector<int> ft(n);
vector<int> res(2 * n);
for (int i = 0; i < n; ++i) {
cin >> ft[i];
ft[i]--;
}
set<int> st;
for (int i = 0; i < 2 * n; ++i) {
st.insert(i);
}
for (int i = 0; i < n; ++i) {
st.erase(st.f... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | public class p1315C {
public static void main(String[] args) {
var sc = new java.util.Scanner(System.in);
l: for(int t=sc.nextInt();t-->0;) {
var sb= new StringBuilder();
int n=sc.nextInt(), j, a[]=new int[n],idx[]=new int[2*n+1];
for(int i=0;i<n;i++) {
... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.*;
import java.util.*;
public class Abc {
static int m[];
public static void main(String[] args) throws Exception {
// Scanner sc = new Scanner(System.in);
FastReader sc = new FastReader();
int t=sc.nextInt();
while (t-->0){
int n=sc.nextInt();
... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.util.*;
import java.io.*;
public class Solution{
public static void main (String args[])throws IOException{
BufferedReader ob = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;
import java.lang.management.*;
import static java.lang.Math.*;
@SuppressWarnings("unchecked")
public class P1315C {
public void run() throws Exception {
for (int T = nextInt(); T > 0; T--) {
int n = nextInt(), a [] = new ... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 9;
const int M = 1e5 + 9;
inline int read() {
int op = 1, x = 0;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') op = -1;
c = getchar();
}
while (isdigit(c)) x = x * 10 + c - 48, c = getchar();
return x * op;
}
unordered_map<i... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | from bisect import bisect_left
t = int(input())
for _ in range(t):
n = int(input())
b = list(map(int, input().split()))
dif = [0] * (n - 1)
if 1 not in b:
print(-1)
elif max(b) >= (2 * n):
print(-1)
else:
ans = [0] * (2 * n)
base = list(range(1, (n*2)+1))
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.*;
import java.util.*;
public class RestoringPermutation {
private static StreamTokenizer st;
private static int nextInt()throws IOException{
st.nextToken();
return (int)st.nval;
}
public static void main(String[] args) throws IOException{
st = new StreamTokenizer(new BufferedReader(new InputSt... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | from sys import stdin
import math
from bisect import bisect_right
def inp():
return stdin.readline().strip()
def binSearch(a, d):
res = bisect_right(a, d)
if res >= len(a):
return(-1)
else:
return(a[res])
t = int(inp())
for _ in range(t):
n = int(inp())
b = [int(x) for x in inp().... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class C1315{
static int gcd(int a, int b)
{
if (a == 0)
return b;
if (b == 0)
return a;
int k;
for (k = 0; ((a | b) & 1) == 0; ++k)
{
a >>= 1;
... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import bisect
import sys
input=sys.stdin.readline
from collections import defaultdict as dd
t=int(input())
while t:
n=int(input())
l=list(map(int,input().split()))
rem=[]
for i in range(1,2*n+1):
if i not in l:
rem.append(i)
ans=[]
lol=0
for i in l:
ans.append(i)
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 |
import java.io.BufferedReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import java.io.InputStrea... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long int t, m, i, j, k, sum = 0;
long long int n;
cin >> n;
vector<pair<long long int, long long int>> a(n);
vector<long long int> viz(2 * n + 5, 0);
for (i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
viz[a[i].first] = ... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | //package learning;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class NitsLocal {
static ArrayList<String> s1;
static boolean[] prime;
static int n = (int)1e7;
static void sieve() {
Arrays.fill(prime , true);
pr... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import sys
input = lambda: sys.stdin.readline().rstrip()
def last_proverka(v):
for i in range(len(v)):
i += 1
if i not in v:
return -1
return True
def l_proverka(v, c):
for i in range(len(c)):
if v[i] == c[i]:
return False
return True
def x(m, sr):... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 |
import java.util.*;
public class temp{
public static void main(String[] args) {
Scanner scn = new Scanner(System.in);
int t = scn.nextInt();
StringBuilder sb = new StringBuilder();
for(int i=0;i<4;i++){
}
A: while (t-- > 0) {
int n = scn.nextInt();
int b[] = new int[n + 1];
for(int i=0;... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=tf-8
#
"""
"""
from operator import itemgetter
from collections import Counter
def solve(n, b):
numset = set(range(1,2*n))
sb = set(b)
if len(sb) != n or not(numset >= sb):
print(-1)
else:
used = [0]*(2*n+1)
for bb in b... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int Max = 1e5 + 10;
const int MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, x, mx = -1;
vector<int> v, ans;
map<int, int> mp, pay;
bool done = false;
cin >> n;
for (int i = 0; i < n;... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int powmod(int a, int b, int m) {
int res = 1;
while (b > 0) {
if (b & 1) {
res = (res * 1ll * a) % m;
}
a = (a * 1ll * a) % m;
b >>= 1;
}
return res;
}
int discrete_log(int a, int b, int m) {
b %= (m - 1);
int n = (int)sqrt(m + .0) + 1;
... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.lang.Math;
public class Test {
public static ... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, test;
cin >> test;
int tc = 0;
while (tc < test) {
cin >> n;
int arr[n], f[2 * n];
for (i = 0; i < n; cin >> arr[i], i++)
;
vector<int> mark;
mark.assign(2 * n + 1, 0);
for (i = 0; i < n; i++) {
f[2 * i] = a... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | from math import *
zzz = int(input())
for zz in range(zzz):
n = int(input())
b = [int(i) for i in input().split()]
a = [0] * (2 * n)
sl = set([i + 1 for i in range(2*n)])
ha = True
for i in range(n):
a[2*i] = b[i]
try:
sl.remove(b[i])
except:
ha =... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | for i in range(int(input())):
n = int(input())
s = list(map(int, input().split()))
elems = [0 for i in range(2 * n + 1)]
ans = []
for i in range(len(s)):
elems[s[i]] = 1
for i in range(len(s)):
ans.append(s[i])
ch = s[i] + 1
while ch <= 2 * n and elems[ch] != 0:
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<bool> used(2 * n + 1, 0);
vector<int> ind(2 * n + 1, -1);
vector<bool> ind_used(2 * n + 1, 0);
for (int i = 0; i < n; i++) {
int b;
cin >> b;
used[b] = 1;
... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import static java.lang.Integer.numberOfTrailingZeros;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Short.parseShort;
import static java.lang.Byte.parseByte;
import java.io.*;
import java.util.*;
public class Contest {
static int nextInt() throws IOExce... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.TreeSet;
publ... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
auto solve = []() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].first--;
}
vector<int> ans(n + n);... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | // package com.company;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.sql.SQLOutput;
import java.util.*;
public class Main {
public static void main(Str... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import sys
import math
def read_line():
return sys.stdin.readline()[:-1]
def read_int():
return int(sys.stdin.readline())
def read_int_line():
return [int(v) for v in sys.stdin.readline().split()]
t = read_int()
for i in range(t):
n = read_int()
b = read_int_line()
l = [i+1 for i in range(2*n)]
for i in b... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
int p[222], vis[222], x[111];
int main() {
int T;
scanf("%d", &T);
while (T--) {
memset(vis, 0, sizeof(vis));
int n, i, e;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
scanf("%d", &e);
x[i] = e;
vis[e] = 1;
}
int j, f = 0;
for (i = 1; i <= n; i... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | // @uthor -: puneet
// TimeStamp -: 23/02/20
import java.io.*;
import java.util.*;
public class R622Q1 implements Runnable {
private boolean testCases=true;
private boolean console=false;
public void solve() {
int n=in.ni();
ArrayList<Integer> list=new ArrayList<>();
TreeSet... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAX_N = 105;
long long t, n, a[MAX_N], b;
vector<int> ans;
set<int> second;
int main() {
cin >> t;
while (t--) {
cin >> n;
second.clear();
b = 1;
ans.resize(2 * n + 2);
fill(ans.begin(), ans.end(), 0);
for (int i = 1; i <= 2 * n; ++i) {... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 210;
bool vis[maxn];
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> v;
memset(vis, 0, sizeof(vis));
for (int i = 0; i < n; i++) {
long long x;
cin >> x;
v.push_back(x);
... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
import java.util.function.BinaryOperator;
public class Main {
private final static long mod = 1000000007;
private final static int MAXN = 1000001;
private static long power(long x, long y, long m) {
long temp;
if (y ==... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | from collections import defaultdict as dd, Counter, OrderedDict as od, deque
from itertools import combinations as comb, permutations as perm
from functools import reduce
from math import log, ceil, floor
from fractions import gcd
import os, sys
#sys.stdin = open("pc.txt", "r")
raw_input = sys.stdin.readline
int_inp... | PYTHON |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.util.*;
import java.io.*;
public class Task{
// taking inputs
static BufferedReader s;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long lo... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> b(2 * n + 1);
unordered_set<int> m;
for (int i = 1; i <= 2 * n; i += 2) {
cin >> b[i];
m.insert(b[i]);
}
int i;
for (i = 2; i <= 2 * n; i += 2) {
... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t = int(input())
for i in range(t):
n = int(input())
b = list(map(int, input().split()))
m = [1 for j in range(2 * n)]
for k in b:
m[k - 1] = 0
a = []
mega_bul = True
for el in b:
a.append(el)
ind = 0
bul = False
while ind < 2 * n:
if ind +... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 |
def solve(num, n):
res = [None] * (2 * n)
for i, x in enumerate(num):
res[i*2] = x
# use back tracking to fill in x
used = set(num)
for i in range(len(num)):
for x in range(num[i] +1, 2*n + 1):
if x not in used:
used.add(x)
res[2*i + 1] ... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import heapq as hq
t = int(input())
for _ in range(t):
n = int(input())
b = list(map(int, input().split()))
sb = sorted([(b[i]-1, i) for i in range(n)]) + [(2*n+1, -1)]
a = [0]*(2*n)
pos = []
ind = 0
for i in range(2*n):
if i < sb[ind][0]:
if len(pos) == 0:
a = ["-1"]
break
p = hq.heappop(pos)
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | /*input
5
1
1
2
4 1
3
4 1 3
4
2 3 4 5
5
1 5 7 2 8
*/
import java.math.*;
import java.io.*;
import java.util.*;
public class Main
{
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, ... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 |
def is_in_array(value, array):
l = 0
r = len(array) - 1
while l < r:
mid = (l + r) // 2
if array[mid] == value:
return True
elif array[mid] > value:
l = mid + 1
else:
r = mid - 1
return False
t = int(input())
for _ in range(t):
n ... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | //package codeforces.div2C;
import java.io.*;
import java.util.*;
//Think through the entire logic before jump into coding!
//If you are out of ideas, take a guess! It is better than doing nothing!
//Read both C and D, it is possible that D is easier than C for you!
//Be aware of integer overflow!
//If you find an a... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int tc;
cin >> tc;
while (tc--) {
long long int n;
cin >> n;
long long int arr[2 * n + 1];
long long int e = 0;
vector<long long int> v;
long long int ee = 0;
for (long long int i = 1; i < n + 1; i++) {
cin >> a... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import sys
# sys.setrecursionlimit(10**6)
from sys import stdin, stdout
import bisect #c++ upperbound
import math
import heapq
def modinv(n,p):
return pow(n,p-2,p)
def cin():
return map(int,sin().split())
def ain(): #takes array as input
return list(map(int,sin().split... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import sys
from collections import Counter
def solve(N, B):
counts = Counter(B)
if any(v > 1 for v in counts.values()):
return -1
# Want smallest permutation that is element-wise greater than B
C = []
for x in range(1, 2 * N + 1):
if x not in counts:
C.append(x)
# ... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | def printA(b,n):
a = []
if 1 not in b:
print("-1")
return
i = 0
while i != n:
curr = b[i]
if curr not in a:
a.append(curr)
nextE = curr+1
condN = True
while condN == True:
if nextE in b or nextE in a:
condN ... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | cases = int(input())
for t in range(cases):
n = int(input())
b = list(map(int,input().split()))
a = [0]*(2*n)
d = {i:True for i in range(1,2*n+1)}
for i in range(n):
p = i+1
pos = 2*p-1
a[pos-1] = b[i]
d[b[i]] = False
f = 0
for i in range(n):
p = i+1... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitS... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.util.Scanner;
public class R623_C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for (int r = 0; r < t; r++) {
int n = in.nextInt();
int[] b = new int[n + 1];
int[] a = new int[2*n + 1];
... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 |
import java.awt.Desktop;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;
import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t=int(input())
while(t):
t-=1
n=int(input())
a=list(map(int,input().split()))
b=[0]*(2*n)
f=set()
flag=0
a1=a[:]
for i in range(n):
if(a[i] not in f):
f.add(a[i])
b[(2*(i+1))-2]=a[i]
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | def foo():
size=int(input())
b=list(map(int,input().split()))
d={}
biggest=0
for i in b:
d[i]=True
answer=[]
saved=0
c=True
q=[]
c=True
for i in b:
j=1
while True:
if not d.get(i+j):
d[i+j]=True
break
else:
j+=1
answer.append(i)
answer.append(i+j)
if i+j>2*len(b):
c=False
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a == 0)
return b;
else
return gcd(b % a, a);
}
long long findGCD(vector<long long> arr, long long n) {
long long result = arr[0];
for (long long i = 1; i < n; i++) result = gcd(arr[i], result);
return result;
}... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | def res(n,l):
l1=[]
d={}
for j in range(1,2*n+1):
if j not in l:
l1.append(j)
for i in l:
for j in l1:
if j>i:
d[i]=j
l1.remove(j)
break
if len(l1)!=0:
return False
else:
return d
t=int(input())
for i in range(t):
n=int... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t=int(input())
M=[]
def fonction(n,L):
if max(L)>=2*n:
return -1
elif len(set(L))!=len(L):
return -1
else:
res=list()
D=list()
for k in L:
j=k
ra=[D[i][1] for i in range(len(D))]
while(( j in ra) or (j in L)) and (j<=2*n):
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int t, n, i, j;
int b[105];
int a[210];
bool dd[210];
long tong;
int sl;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
memset(dd, false, sizeof(dd));
tong = 0;
for (i = 1; i <= n; i++) {
... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t = int(input())
for _ in range(0,t):
n = int(input())
bb = [int(i) for i in input().split()]
le = [int(i) for i in range(1,2*n+1) if i not in bb]
aa = [0]*(2*n)
ii = 0
for i in range(0,n):
aa[ii] = bb[i]
ii += 2
ii = 1
k = True
for i in range(0,n):
k = [ss fo... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import os
import sys
from io import BytesIO, IOBase
from bisect import bisect
def solution(arr, n):
all_set = [i for i in range(1, (2 * n) + 1)]
for i, x in enumerate(arr):
all_set.remove(arr[i])
res = []
for i in range(n):
idx = bisect(all_set, arr[i])
if idx == len(all_set)... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | //package CodeForces;
import java.io.*;
import java.nio.file.Paths;
import java.util.Scanner;
public class Solution {
private static final boolean onlineJudge = "true".equals(System.getProperty("ONLINE_JUDGE"));
public static void main(String[] args) throws IOException {
FileInputStream fileStrea... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
long long MOD = 1000000007;
using namespace std;
bool sortbysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
return (a.second < b.second);
}
long long POW(long long a, long long b) {
if (b == 0) return 1;
if (b == 1) return a % MOD;
long lon... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
int dx[] = {+1, -1, 0, 0};
int dy[] = {0, 0, +1, -1};
vector<long long> vv;
const long long range = 1e7 + 123;
bitset<range> prime;
void sieve() {
prime[0] = 1;
prime[1] = 1;
for (long long i = 2; i <= range; i++) {... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | from collections import defaultdict as dfd
for _ in range(int(input())):
N = int(input())
A = list(map(int,input().split()))
C = dfd(int)
for i in range(1,(2*N)+1):
C[i] = 0
for i in range(len(A)):
C[A[i]] = 1
B = []
# print(C)
for i in range(len(A)):
B.append(A[i... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | x=int(input())
for i in range(x):
a=int(input())
l=list(map(int,input().split()))
i=0
j=1
while(i<len(l)):
while(1):
if l[i]+j not in l:
l.insert(i+1,l[i]+j)
j=1
i+=1
break
else:
j+=1
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | for _ in range(int(input())):
N = int(input())
A = list(map(int,input().split(" ")))
flag = 0
maxi = 2*N
Ans = []
mark = {}
for i in A:
mark[i] =1
for i in A:
#print(i,Ans)
Ans.append(i)
f=0;j=i+1
while j<=maxi:
if mark.get(j,-1) == -1:... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
int b[n];
map<int, int> mp;
for (int i = 0; i < n; i++) {
cin >> b[i];
mp[b[i]]++;
}
int a[2 * n];
for (int i = 0; i < n; i++) {
a[2 * i] = b[i];
a[(2 * i) + 1] = 0;
}
for (int i = 0; i < 2 * n; i = i + 2) ... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t = int(input())
for T in range(t):
n = int(input())
b = list(map(int,input().split()))
ans_arr = []
ans = 0
for i in range(len(b)):
# ans_arr.append(b[i])
# # print(ans_arr)
# for j in range(1,2*n):
# if b[i] + j not in b and b[i] + j not in ans_arr:
#... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int tab[205];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> V;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
tab[x] = 1;
V.push_back(x);
... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | if __name__ == '__main__':
for _ in range(int(input())):
length = int(input())
a = *map(int,input().split()),
rest = {*range(2*length+1)} -{*a}
answer = []
try:
for i in a:
temp = min(rest-{*range(i)})
rest-={temp}
a... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
for(int p=0;p<t;p++){
int n = s.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++)
arr[i]=... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | # -*- coding: utf-8 -*-
"""
Created on Sat Feb 29 05:27:25 2020
@author: hp
"""
t = int(input())
for i in range(t):
n = int(input())
lst = [int(j) for j in input().split()]
a=[0]*2*n
y = True
for j in range(n):
a[2*j] = lst[j]
for j in range(n):
x = a[2*j] + 1
z = True
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 |
import java.util.Scanner;
public class JavaApplication2 {
public static void main(String[] args) {
Scanner s=new Scanner(System.in);
int t=s.nextInt();
String ss="";
int counter=0;
for(int i=0;i<t;i++){
int n=s.nextInt();
boolean doo=true;
... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.util.*;
public class code_forces {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s= new Scanner(System.in);
int t= s.nextInt();
outer: while(t-->0) {
int n= s.nextInt();
int[] arr= new int[n];
for(int i=0; i<arr.length;i++) {
arr[i] = s.nex... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1e5 + 5;
int a[N], b[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
set<int> st;
for (int i = 1; i <= 2 * n; i++) st.insert(i);
for (int i ... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t = int(input())
for _ in range(t):
n = int(input())
b = list(map(int,input().split()))
l = [i for i in range(1,2*n+1) if i not in b]
a=[]
for i in b:
a.append(i)
for j in l:
if j>i:
a.append(j)
l.remove(j)
break
if len(... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import javax.management.DynamicMBean;
import javax.print.DocFlavor;
import javax.print.attribute.HashAttributeSet;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.attribute.FileAttribute;
import java.time.DayOfWeek;
import java.time.Lo... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.*;
import java.util.*;
public class Main {
private static void solver(InputReader sc, PrintWriter out) throws Exception {
int test = sc.nextInt();
for(int ii=0; ii<test; ii++){
int n = sc.nextInt();
Set<Integer> hs = new HashSet<>();
int arr[] = new int[n];
... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | """
from collections import Counter
t=int(input())
for i in range(t):
n = int(input())
nums = list(map(int, input().split()))
c = Counter(nums)
ans = 0
for i,j in c.items():
ans += j//i
c[i] = j%i
print(c)
print(ans)"""
"""
from functools import lru_cache
@lru_cache(maxsi... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 20;
const int inf = 0x3f3f3f3f;
const int modd = 1e9 + 7;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x =... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t=int(input())
for g in range(0,t):
n=int(input())
b=list(map(int,input().split()))
bnew=[]
bnew.extend(b)
bnew.sort()
a=[]
j=0
for i in range(1,2*n+1):
if(j<n and i==bnew[j]):
j=j+1
else:
a.append(i)
breaks=0
for i in range(0,n):
i... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import math
from sys import stdin as c
n=int(input())
a=[]
for i in range(n):
input()
a.append(list(map(int,c.readline().split(' '))))
def higher(ar,val):
u=len(ar)-1
if u==0:
return 0
if u==-1:
return -1
elif ar[u//2]>val:
return higher(ar[:u//2+1],val)
else:
u1=higher(ar[u//2+1:],val)
if u1>-1:
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | //package com.kraken.cf.cf623;
/*
* Author: Kraken
* Created on 2/25/2020 at 3:50 AM
*/
import java.io.*;
import java.util.*;
public class C {
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int[] b = new int[n],... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | t = int(input())
while t:
t -= 1
n = int(input())
vis = [False] * (2 * n)
ans = [-1] * (2 * n)
b = list(map(int, input().split()))
def check():
global vis
for i in b:
if vis[i - 1] is False:
vis[i - 1] = True
else:
return F... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | for p in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=[0]*(2*n)
for i in a:
b[i-1]+=1
m=0
c=[]
for i in range(n):
j=a[i]
while(j<(2*n)):
if b[j]==0:
b[j]+=1
c.append(j+1)
m+=1
break
else:
j+=1
if m!=n:
print(-1... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.util.*;
import java.io.*;
public class C623
{
public static void main(String [] args)
{
MyScanner sc = new MyScanner();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t = sc.nextInt();
while (t > 0) {
int n = sc.nextInt();
... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n, b[100] = {0};
bool used[201] = {false};
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &b[i]);
used[b[i]] = true;
}
bool ok = true;
int ans[200];
for (int i = 0; i < n; i++) {... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | import java.io.*;
import java.util.*;
public class tr2 {
static PrintWriter out;
static StringBuilder sb;
static long inf = (long) 1e10;
static ArrayList<Integer> primes;
static ArrayList<Integer>[] ad;
static int[] si;
static long mod = (long) 998244353;
static long num = (long) 1e9 + 7;
static long[][] memo... | JAVA |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | tests = int(input())
for _ in range(tests):
size = int(input())
full = set([i for i in range(1,2*size+1)])
restore = list(map(int,input().split()))
check = sorted(full - set(restore)); capture = []
for res in restore:
found = False
for ch in check:
if ch > res:
... | PYTHON3 |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
vector<long long> vin(long long n) {
vector<long long> a(n);
for (long long i = 0; i < n; i += 1) cin >> a[i];
return a;
}
long long intin() {
long long n;
cin >> n;
return n;
}
char charin() {
char a;
cin >> a;
return a;
}
string strin() {
string s;
c... | CPP |
1315_C. Restoring Permutation | You are given a sequence b_1, b_2, β¦, b_n. Find the lexicographically minimal permutation a_1, a_2, β¦, a_{2n} such that b_i = min(a_{2i-1}, a_{2i}), or determine that it is impossible.
Input
Each test contains one or more test cases. The first line contains the number of test cases t (1 β€ t β€ 100).
The first line of... | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n, b[105];
void solve() {
vector<int> a;
vector<int> us(205, 0);
cin >> n;
for (int i = 0; i < n; i++) {
cin >> b[i];
us[b[i]] = 1;
}
for (int i = 0; i < n; i++) {
a.push_back(b[i]);
int flag = 0;
for (int j = 1; j <= 2 * n; j++) {
... | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.