QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#700066#9538. Closest Derangementucup-team008#AC ✓87ms84532kbC++2314.3kb2024-11-02 11:49:232024-11-02 11:49:43

Judging History

你现在查看的是最新测评结果

  • [2024-11-02 11:49:43]
  • 评测
  • 测评结果:AC
  • 用时:87ms
  • 内存:84532kb
  • [2024-11-02 11:49:23]
  • 提交

answer

// {{{ y0105w49 template 24K21
// hi mom
#ifndef NULL
#ifdef __GNUC__
#ifndef __clang__
// #include <bits/stdc++.h>
#include <bits/extc++.h>
#include <tr2/dynamic_bitset>
#define EXTS
#else
#ifdef ARST
#include <bits/clang++.h>
#else
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
// #include <cuchar>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif
#if __cplusplus >= 201703L
#include <any>
#include <charconv>
// #include <execution>
#include <filesystem>
#include <optional>
// #include <memory_resource>
#include <string_view>
#include <variant>
#endif
#if __cplusplus >= 202002L
#include <barrier>
#include <bit>
#include <compare>
#include <concepts>
#if __cpp_impl_coroutine
# include <coroutine>
#endif
#include <latch>
#include <numbers>
#include <ranges>
#include <span>
// #include <stop_token>
#include <semaphore>
// #include <source_location>
// #include <syncstream>
#include <version>
#endif
#if __cplusplus > 202002L
// #include <expected>
// #include <spanstream>
#if __has_include(<stacktrace>)
# include <stacktrace>
#endif
#include <stdatomic.h>
#endif
#endif
#endif
#else
#error "unsupported"
#endif
#endif
using namespace std;
#ifdef ARST
#define JO 1
#define OJ 0
#else
#define JO 0
#define OJ 1
#endif
#define STR(x) #x
#define GCCDIAG(s) _Pragma(STR(GCC diagnostic s)) static_assert(true)
#define Wsave GCCDIAG(push)
#define Wpop GCCDIAG(pop)
#define Wsupp(w) GCCDIAG(ignored "-W" w)
#define Wpush(w) Wsave; Wsupp(w)
#define typeof __typeof__
namespace gbd_ns {
	template<typename C> struct is_iterable {
		template<class T> static long check(...);
		template<class T> static char check(int,typename T::const_iterator = C().end());
		enum {
			value = sizeof(check<C>(0)) == sizeof(char),
			neg_value = sizeof(check<C>(0)) != sizeof(char)
		};
	};
	template<class T> struct _gbd3C;
	template<class T> ostream &_gbd3(ostream &os,const T &x) { return _gbd3C<T>::call(os,x); }
	template<> ostream &_gbd3(ostream &os,const string &x) { return os<<'"'<<x<<'"'; }
	template<> ostream &_gbd3(ostream &os,char *const &x) { return os<<'"'<<x<<'"'; }
	template<class T> ostream &_gbd3_5(ostream &os,const T &x) { return _gbd3(os,x); }
	template<class A,class B> ostream &_gbd4(ostream &os,const pair<A,B> &p) {
		_gbd3(os<<'(',p.first);
		_gbd3(os<<',',p.second);
		return os<<')';
	}
	template<class T,size_t N> struct _gbd4_tupleC {
		static void call(ostream &os,const T &t) {
			_gbd4_tupleC<T,N-1>::call(os,t);
			os<<','<<get<N-1>(t);
		}
	};
	template<class T> struct _gbd4_tupleC<T,1> {
		static void call(ostream &os,const T &t) { os<<get<0>(t); }
	};
	template<typename... Types> ostream &_gbd4(ostream &os,const tuple<Types...> &t) {
		os<<'(';
		_gbd4_tupleC<tuple<Types...>,sizeof...(Types)>::call(os,t);
		return os<<')';
	}
	template<> ostream &_gbd4(ostream &os,const tuple<> &t) { (void)t; return os<<"()"; }
	template<class T> ostream &_gbd4(ostream &os,const T &x) {
		return os<<x;
	}
	template<class T> struct _gbd3C {
		template<class U=T> static ostream &call(ostream &os,enable_if_t<is_iterable<U>::value,const T> &V) {
			os<<"{";
			bool ff=0;
			for(const auto &E:V) _gbd3_5<decltype(E)>(ff?os<<",":os,E), ff=1;
			return os<<"}";
		}
		template<class U=T> static ostream &call(ostream &os,enable_if_t<is_iterable<U>::neg_value,const T> &x) {
			return _gbd4(os,x);
		}
	};
	template<class T,typename... Args> ostream &_gbd2(ostream &os,bool,vector<string>::iterator nm,const T &x,Args&&... args);
	ostream &_gbd2(ostream &os,bool,vector<string>::iterator) { return os; }
	template<typename... Args> ostream &_gbd2(ostream &os,bool fi,vector<string>::iterator nm,const char *x,Args&&... args) {
		return _gbd2(os<<(fi?"":"  ")<<x,0,nm+1,args...);
	}
	template<class T,typename... Args> ostream &_gbd2(ostream &os,bool fi,vector<string>::iterator nm,const T &x,Args&&... args) {
		return _gbd2(_gbd3<T>(os<<(fi?"":"  ")<<*nm<<"=",x),0,nm+1,args...);
	}
	vector<string> split(string s) {
		vector<string> Z;
		string z="";
		s+=',';
		int dep=0;
		for(char c:s) {
			if(c==',' && !dep) Z.push_back(z),z="";
			else z+=c;
			if(c=='(' || c=='{' || c=='[') ++dep;
			if(c==')' || c=='}' || c==']') --dep;
		}
		return Z;
	}
	template<typename... Args> ostream &_gbd1(ostream &os,const string &nm,Args&&... args) {
		return _gbd2(os,1,split(nm).begin(),args...);
	}
	template<typename... Args> string _gbd1(const string &nm,Args&&... args) {
		ostringstream oss;
		_gbd2(oss,1,split(nm).begin(),args...);
		return oss.str();
	}
}
bool DBG=1,EMACS=0;
#define dbg(...) (JO&&DBG?gbd_ns::_gbd1(cerr<<"\033[38;5;5m"<<__FILE__<<":"<<__LINE__<<(EMACS?":note: ":": "),#__VA_ARGS__,__VA_ARGS__)<<"\033[0m"<<endl:cerr)
#define dbgt(...) dbg(fmt_time(),__VA_ARGS__)
#define fmt(...) gbd_ns::_gbd1(#__VA_ARGS__,__VA_ARGS__)
template<class Fun> struct _y_combinator_result {
	Fun _fun;
	template<class T> explicit _y_combinator_result(T &&fun) : _fun(forward<T>(fun)) {}
	template<typename... Args> decltype(auto) operator()(Args&&... args) {
		return _fun(ref(*this),forward<Args>(args)...);
	}
};
template<class Fun> [[nodiscard]] decltype(auto) fix(Fun &&fun) {
	return _y_combinator_result<decay_t<Fun>>(forward<Fun>(fun));
}
#define nop void()
#define sz(x) (int((x).size()))
#define all(v) (v).begin(),(v).end()
#define forenum(i,...) for(int i:{-1}) for(__VA_ARGS__) if(++i,0) assert(0); else
#define forenumll(i,...) for(long long i:{-1}) for(__VA_ARGS__) if(++i,0) assert(0); else
#define forbs(k,i,bs) for(ptrdiff_t k=0,i=(bs)._Find_first();i<(ptrdiff_t)(bs).size();i=(bs)._Find_next(i),++k)
#define fordbs(k,i,bs) for(ptrdiff_t k=0,i=(bs).find_first();i<(ptrdiff_t)(bs).size();i=(bs).find_next(i),++k)
#define get(x,i) get<i>(x)
template<class T> T &smin(T &x,const T &y) { return y<x?x=y:x; }
template<class T> T &smax(T &x,const T &y) { return y>x?x=y:x; }
template<class T> bool inb(const T &x,const T &l,const T &r) { return l<=x&&x<=r; }
template<class T> bool cinb(const T &x,const T &l,const T &r) { return l<=r?l<=x&&x<=r:l<=x||x<=r; }
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
template<template<class> class C,class T> T popv(C<T> &v) { T z=v.back(); v.pop_back(); return z; }
template<template<class> class C,class T> T popq(C<T> &v) { T z=v.top(); v.pop(); return z; }
template<template<class> class C,class T> T pops(C<T> &v) { T z=*v.begin(); v.erase(v.begin()); return z; }
template<template<class,class> class C,class K,class V> pair<K,V> popm(C<K,V> &v) { pair<K,V> z=*v.begin(); v.erase(v.begin()); return z; }
template<template<class> class C,class T> void erase1(C<T> &v,const T &x) { v.erase(v.find(x)); }
template<template<class> class C,class T> int lbi(C<T> &v,const T &x) { return int(lower_bound(all(v),x)-v.begin()); }
template<template<class> class C,class T> int findi(C<T> &v,const T &x) { auto it=lower_bound(all(v),x); return it!=v.end()&&*it==x?int(it-v.begin()):-1; }
template<class V> int sortu(V &v) { sort(all(v)); int z=int(unique(all(v))-v.begin()); v.resize(z); return z; }
template<typename T,typename... Args> T tee(T (*f)(Args... args),Args&&... args) { T z=f(forward<Args>(args)...); cout<<z<<endl; return z; }
template<typename... Args> void tee(void (*f)(Args... args),Args&&... args) { f(forward<Args>(args)...); }
#ifdef EXTS
template<class S,class T> using omap=__gnu_pbds::tree<S,T,less<S>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
template<class T> using oset=omap<T,__gnu_pbds::null_type>;
template<class T> using rope=__gnu_cxx::rope<T>;
using dbitset=tr2::dynamic_bitset<>;
#endif
constexpr int e0=1, e1=10, e2=100, e3=1000;
constexpr int e4=10*e3, e5=100*e3, e6=1000*e3;
constexpr int e7=10*e6, e8=100*e6, e9=1000*e6;
constexpr long long e10=10LL*e9, e11=100LL*e9, e12=1000LL*e9;
constexpr long long e13=10*e12, e14=100*e12, e15=1000*e12;
constexpr long long e16=10*e15, e17=100*e15, e18=1000*e15;
constexpr __int128_t e21=__int128_t(e3)*e18, e24=__int128_t(e6)*e18, e27=__int128_t(e9)*e18;
constexpr __int128_t e30=e3*e27, e33=e6*e27, e36=e9*e27;
using ulll=__uint128_t;
using lll=__int128_t;
using ull=unsigned long long;
using ll=long long;
using uint=unsigned int;
using ushort=unsigned short;
using uchar=char;
using ld=long double;
#ifdef EXTS
using lld=__float128;
#endif
long long START_TIME=chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now().time_since_epoch()).count();
inline long long now_U_03BC_s() { return chrono::duration_cast<chrono::microseconds>(chrono::steady_clock::now().time_since_epoch()).count()-START_TIME; }
const char *fmt_time(long long U_03BC_s=now_U_03BC_s()) { static char dur[20]; sprintf(dur,"%llu.%03llus",U_03BC_s/e6,(U_03BC_s%e6)/e3); return dur; }
#define timed(cb) do { dbg("timed "#cb" ..."); unsigned long long start=now_U_03BC_s(); cb; dbg("timed "#cb" took",fmt_time(now_U_03BC_s()-start)); } while(0)
int arg1; bool inp; vector<string> args;
unsigned seed=unsigned(JO&&getenv("sd")?atoi(getenv("sd")):OJ?START_TIME:START_TIME%e5);
mt19937 igen(seed<<1),gen(seed<<1|1);
#define irand(...) (assert(!inp),_rand(igen,__VA_ARGS__))
#define rand(...) _rand(gen,__VA_ARGS__)
template<class T> enable_if_t<numeric_limits<T>::is_integer,T> _rand(mt19937 &g,T l,T r) { return uniform_int_distribution<T>(l,r)(g); }
template<class T> enable_if_t<numeric_limits<T>::is_integer,T> _rand(mt19937 &g,T n) { return _rand(g,T(1),n); }
[[deprecated]] int _rand(mt19937 &g) { return _rand(g,0,numeric_limits<int>::max()); }
template<class T> enable_if_t<numeric_limits<T>::is_iec559,T> _rand(mt19937 &g,T l,T r) { return uniform_real_distribution<T>(l,r)(g); }
bool _rand(mt19937 &g,double p) { return bernoulli_distribution(p)(g); }
template<class T> T _rand(mt19937 &g,initializer_list<T> il) { return *(il.begin()+_rand(g,0,(int)il.size()-1)); }
template<class T> T _rand(mt19937 &g,double p,T a,T b) { return _rand(g,p)?a:b; }
template<class T> T _rand(mt19937 &g,initializer_list<T> il,initializer_list<double> wt) { assert(il.size()==wt.size()); return *(il.begin()+discrete_distribution<int>(wt)(g)); }
#define random_shuffle(...) static_assert(false,"random_shuffle deprecated, use shuffle")
#define ine(x,e) (inp?cin>>(x),nop:((x)=(e),nop))
#define inr(x,...) ine(x,irand(__VA_ARGS__))
#define endl '\n'
string garb;
void exit0() { DBG=1; dbgt("gg (early)",seed); exit(0); }
#ifndef MAIN
#define MAIN _main
#endif
void MAIN();
int32_t main([[maybe_unused]]int argc,[[maybe_unused]]char *argv[]) {
	ios_base::sync_with_stdio(0); cin.tie(0); cin.exceptions(ios_base::failbit | ios_base::badbit);
	arg1=0,args={argv,argv+argc};
	if(sz(args)>1) {
		if(args[1][0]=='i') freopen((string(__FILE__).substr(0,string(__FILE__).find('.'))+"."+args[1].substr(1)+".in").c_str(),"r",stdin);
		else if(args[1][0]=='I') freopen(args[1].substr(1).c_str(),"r",stdin);
		else arg1=stoi(args[1]);
	}
	inp=!arg1;
	if(JO && getenv("EMACS")) EMACS=1;
	dbgt(arg1,seed,args);
	#ifdef QUIET
	DBG=0;
	#endif
	MAIN();
	DBG=1;
	dbgt("gg;wp",seed);
	return 0;
}
constexpr int inf=e9+99;
constexpr ll linf=1LL*e9*e9+99;
#if __cplusplus >= 202002L
constexpr long double U_03C4__ld=2*numbers::pi_v<long double>;
#else
const long double U_03C4__ld=2*acosl(-1);
#endif
#define U_03C4_ ((flt)U_03C4__ld)
constexpr long double U_03B5__ld=1e-8l;
#define U_03B5_ ((flt)U_03B5__ld)
// }}}
using flt=double; //CARE
constexpr int P=e9+7;//998'244'353;

const int N=200<<10;
int n,a[N];
int z[N];

int q(int i,int I) {
	assert(I);
	assert(!(I&1));
	if(abs(I)>a[i]+1) return ((a[i]+1)^1)-1;
	if(abs(I)<a[i]-1) return a[i]^1;
	int d=a[i]-abs(I);
	assert(abs(d)<=1);
	if(I>0) {
		if(d<0) return a[i]+2;
		return a[i]-1;
	} else {
		if(d>0) return a[i]-2;
		return a[i]+1;
	}
}

void solve(int i,vector<int> I,int k) {
	assert(inb(k,1,sz(I)));
	if(i==n+1) return dbg(k,I),assert(sz(I)==1),assert(k==1);

	vector<pair<int,int>> poss;
	for(int II:I) poss.pb({q(i,II),II});
	sort(all(poss));
	z[i]=poss[k-1].fi;
	I.clear();
	for(auto [x,II]:poss) if(x==z[i]) I.pb(II);
	for(auto [x,II]:poss) if(x<z[i]) --k;
	solve(i+1,I,k);
}




auto solve() { /* CURSOR START */
	int k; ine(n,arg1), inr(k,n+3);
	if(inp) for(int i=1;i<=n;i++) cin>>a[i];
	else { for(int i=1;i<=n;i++) a[i]=i; shuffle(a+1,a+1+n,igen); }

	if(n%2==0) {
		if(k>1) return cout<<-1<<endl,nop;
		for(int i=1;i<=n;i++) cout<<((a[i]+1)^1)-1<<" \n"[i==n];
		return;
	}

	if(k>n-1) return cout<<-1<<endl,nop;
	vector<int> I;
	for(int i=2;i<n;i+=2) I.pb(i),I.pb(-i);
	assert(sz(I)==n-1);
	solve(1,I,k);
	for(int i=1;i<=n;i++) cout<<z[i]<<" \n"[i==n];
}



void _main() { int NTC=1;
	ine(NTC,5);
	for(int TC=1;TC<=NTC;TC++) {
		// cout<<"Case #"<<TC<<": ";
		tee(solve);
	}
	if(JO&&inp) assert((cin>>ws).eof());
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3748kb

input:

2
2 2
2 1
3 2
1 2 3

output:

-1
3 1 2

result:

ok 2 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

50
6 1
4 2 6 3 5 1
8 1
6 2 8 7 3 4 1 5
3 298728530
2 3 1
4 610615077
2 4 3 1
4 2
4 2 3 1
7 152065238
4 1 3 5 7 6 2
6 844435075
2 6 4 5 1 3
4 544008000
3 2 4 1
9 379783780
5 9 3 8 4 2 1 7 6
5 139426002
2 4 5 3 1
2 1
1 2
2 1
1 2
3 1
3 1 2
4 2
2 4 1 3
4 1
3 2 4 1
5 4
2 4 1 5 3
3 1
1 2 3
6 805720317
5 6...

output:

3 1 5 4 6 2
5 1 7 8 4 3 2 6
-1
-1
-1
-1
-1
-1
-1
-1
2 1
2 1
1 2 3
-1
4 1 3 2
3 5 2 4 1
2 3 1
-1
-1
-1
2 1
-1
-1
2 4 3 1
-1
-1
-1
-1
-1
5 3 7 8 6 4 1 2
1 3 2
-1
3 7 9 5 8 1 4 2 6
-1
1 2
-1
-1
-1
8 5 3 2 4 7 1 6
-1
-1
5 1 6 7 4 3 2
-1
5 2 4 1 6 3 7
1 2
-1
2 1
-1
4 1 3 2 5
-1

result:

ok 50 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3648kb

input:

100
7 3
6 4 3 5 1 2 7
7 2
7 6 5 1 3 4 2
3 579339385
3 1 2
3 244980876
1 2 3
2 1
2 1
6 184906010
1 4 2 6 5 3
6 908625780
3 2 6 4 5 1
4 223847761
2 3 1 4
7 4078777
1 3 4 2 6 5 7
5 955859204
1 3 5 4 2
5 3
4 5 3 2 1
7 6
1 7 4 3 6 2 5
6 2
4 2 3 1 6 5
2 1
1 2
7 6
5 4 6 7 2 1 3
2 2
2 1
3 2
2 3 1
6 38861221...

output:

7 3 5 4 2 1 6
6 5 7 2 4 3 1
-1
-1
1 2
-1
-1
-1
-1
-1
5 4 1 3 2
3 6 5 2 7 1 4
-1
2 1
7 3 5 6 1 2 4
-1
3 1 2
-1
5 2 4 3 1 6
-1
2 3 1
-1
-1
4 1 2 3
-1
-1
2 1 3
-1
-1
-1
-1
-1
1 2
-1
-1
-1
2 5 3 4 1
1 2 3
6 5 4 1 3 2
-1
5 7 4 3 1 2 6
2 4 1 5 3
-1
-1
2 4 3 6 1 5
-1
2 4 6 1 3 5
1 5 4 2 3
-1
-1
2 4 1 3
-1
...

result:

ok 100 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3600kb

input:

100
8 2
8 6 4 1 7 5 3 2
3 1
2 1 3
4 408738161
1 3 4 2
9 392326366
4 3 2 1 8 7 6 5 9
7 6
2 5 1 3 7 4 6
3 662976110
1 2 3
4 584704458
3 1 2 4
2 170402059
2 1
8 195525462
8 4 2 1 7 6 5 3
5 241372504
4 5 2 3 1
2 1
1 2
7 2
6 3 7 4 1 2 5
6 1
6 3 5 1 2 4
7 5
3 2 7 4 1 6 5
8 2
5 3 4 6 1 2 7 8
4 1
2 4 3 1
2 ...

output:

-1
1 3 2
-1
-1
3 4 2 1 6 5 7
-1
-1
-1
-1
-1
2 1
7 1 6 5 2 3 4
5 4 6 2 1 3
4 1 6 5 2 7 3
-1
1 3 4 2
-1
-1
2 1 3
-1
1 3 6 5 7 4 2
-1
-1
5 3 1 4 2
-1
-1
-1
-1
-1
3 5 2 4 6 1
3 1 2
-1
5 4 9 3 7 1 2 8 6
-1
-1
-1
-1
-1
-1
-1
2 1 3
2 1
-1
-1
1 6 5 2 4 3 7 8
-1
8 2 3 5 6 9 4 7 1
2 3 1
-1
-1
-1
-1
-1
3 6 4 5...

result:

ok 100 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

1000
4 2
2 1 4 3
3 1
3 2 1
7 110856137
6 5 1 7 4 2 3
7 253418683
2 6 7 4 3 1 5
2 2
1 2
7 763879058
7 5 3 1 6 4 2
8 518300421
1 8 4 2 3 5 7 6
3 241647870
2 1 3
4 400296427
2 1 4 3
3 477979797
1 3 2
6 2
4 1 3 6 5 2
8 2
3 7 5 4 2 8 1 6
8 1
3 2 1 5 7 8 6 4
3 2
2 3 1
9 3
1 6 7 2 5 4 3 8 9
5 1
3 2 5 1 4
4...

output:

-1
1 3 2
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
4 1 2 6 8 7 5 3
3 1 2
2 5 9 1 6 3 4 7 8
1 3 4 2 5
-1
-1
4 1 2 5 3
-1
3 8 2 1 5 9 7 6 4
-1
-1
4 3 2 7 1 5 6
-1
-1
-1
-1
-1
2 1 3 4 6 5
2 1
-1
-1
-1
2 1 3
-1
2 1
1 5 4 6 8 7 3 2
-1
-1
3 2 4 5 1
3 2 4 1
-1
3 1 2
3 2 1 4
-1
8 1 3 2 9 7 5 4 6
7 4 6 2 5 3 1
-1
-1
6 7...

result:

ok 1000 lines

Test #6:

score: 0
Accepted
time: 1ms
memory: 3880kb

input:

1000
6 2
6 4 2 3 1 5
9 7
6 5 3 9 1 7 2 8 4
8 290062773
5 2 6 7 8 3 4 1
6 764373478
6 2 1 5 4 3
2 2
2 1
4 280972480
1 4 2 3
3 931925743
2 3 1
5 698025972
2 5 3 1 4
3 260868128
3 2 1
4 15623583
3 4 2 1
5 2
2 5 1 4 3
7 5
3 1 5 4 2 6 7
10 2
1 5 4 3 8 2 9 7 10 6
7 3
5 2 4 6 7 1 3
10 1
5 9 2 8 7 1 4 6 10 ...

output:

-1
7 4 5 8 2 6 1 9 3
-1
-1
-1
-1
-1
-1
-1
-1
1 4 2 3 5
4 2 7 3 1 5 6
-1
4 1 5 7 6 3 2
6 10 1 7 8 2 3 5 9 4
4 5 1 2 3
-1
-1
4 2 6 1 9 7 3 5 8
-1
-1
-1
-1
-1
-1
-1
5 2 1 3 4 6
-1
-1
-1
9 5 2 4 7 3 1 6 8
-1
3 1 4 5 2
-1
5 7 1 6 2 4 8 9 3
-1
3 4 5 1 2
2 1 3
2 1 4 3 7 6 5
-1
-1
3 9 5 4 8 6 7 1 10 2
-1
8 ...

result:

ok 1000 lines

Test #7:

score: 0
Accepted
time: 61ms
memory: 8152kb

input:

100
3412 1
258 1465 305 1663 2883 340 3112 1078 1464 1315 1418 2018 141 2901 1121 1382 938 1208 3289 3016 2358 1270 1795 3335 1566 1284 2091 1582 3137 3276 2873 1838 2049 3274 438 266 2827 1337 440 1063 2895 2953 1433 84 253 1547 3360 3125 530 2708 2985 181 2559 3308 1660 1609 287 2737 1894 871 3048...

output:

257 1466 306 1664 2884 339 3111 1077 1463 1316 1417 2017 142 2902 1122 1381 937 1207 3290 3015 2357 1269 1796 3336 1565 1283 2092 1581 3138 3275 2874 1837 2050 3273 437 265 2828 1338 439 1064 2896 2954 1434 83 254 1548 3359 3126 529 2707 2986 182 2560 3307 1659 1610 288 2738 1893 872 3047 403 3361 8...

result:

ok 100 lines

Test #8:

score: 0
Accepted
time: 20ms
memory: 8420kb

input:

131
20 1
15 20 9 10 2 3 19 5 12 11 18 17 16 4 1 14 6 13 7 8
5 2
5 3 4 2 1
6 1
3 5 4 1 6 2
41 19
6 5 1 38 41 20 10 4 21 30 22 29 24 36 16 2 8 12 27 23 3 39 33 26 25 32 18 19 37 40 15 31 11 34 14 9 28 35 7 17 13
9 6
5 8 4 7 6 1 9 3 2
4 1
1 2 4 3
41 5
33 4 8 13 7 9 23 11 36 26 25 5 39 41 2 15 31 28 30 ...

output:

16 19 10 9 1 4 20 6 11 12 17 18 15 3 2 13 5 14 8 7
4 1 5 3 2
4 6 3 2 5 1
5 6 2 39 40 19 9 3 22 31 21 30 23 37 15 1 7 11 28 24 4 38 32 25 26 33 17 20 36 41 16 29 12 35 13 10 27 34 8 18 14
6 9 3 5 7 2 8 4 1
2 1 3 4
32 3 7 12 8 11 22 10 37 27 24 6 38 40 1 14 30 29 31 41 5 2 23 18 20 33 26 4 16 13 25 19...

result:

ok 131 lines

Test #9:

score: 0
Accepted
time: 0ms
memory: 3868kb

input:

1000
33 13
2 18 17 8 25 30 1 29 19 6 11 13 9 14 10 22 4 26 23 31 27 3 28 15 7 24 20 21 33 32 16 5 12
40 43
24 27 31 4 26 8 33 3 25 34 28 30 7 22 38 17 14 39 11 23 20 13 10 37 15 40 5 21 32 1 29 36 2 9 35 18 19 6 16 12
41 81
2 14 3 11 1 27 33 16 40 32 31 18 39 38 26 29 20 34 30 25 12 6 8 19 17 21 4 2...

output:

1 17 18 7 26 31 2 30 20 5 12 14 10 13 9 21 3 25 24 29 28 4 27 16 8 23 19 22 32 33 15 6 11
-1
-1
-1
19 9 7 6 12 5 13 15 8 3 18 14 1 4 11 10 17 16 2
-1
39 19 40 13 12 49 10 43 42 22 32 14 3 5 26 28 9 23 2 7 11 16 46 24 18 1 27 30 25 29 6 41 48 20 47 37 8 44 35 31 45 17 33 15 34 21 38 4 36
-1
-1
-1
20 ...

result:

ok 1000 lines

Test #10:

score: 0
Accepted
time: 5ms
memory: 3736kb

input:

1000
47 88
38 47 17 13 27 3 1 25 11 23 9 5 41 40 31 20 16 46 6 2 30 19 28 32 10 26 43 36 15 45 29 33 21 24 39 34 7 44 22 42 8 14 18 12 35 37 4
30 33
5 29 3 21 2 27 25 4 19 23 17 6 7 8 14 18 20 1 26 24 28 12 13 22 16 15 9 11 30 10
62 85
17 50 62 16 15 28 20 27 57 31 11 53 58 61 14 39 24 3 33 34 38 49...

output:

-1
-1
-1
2 17 65 8 80 6 81 15 26 16 83 59 68 91 33 40 61 78 74 12 92 75 70 64 7 21 24 23 38 62 29 45 84 34 20 39 85 9 86 30 41 57 56 27 13 52 79 88 82 72 55 47 42 89 90 11 5 31 73 1 77 51 67 76 19 60 18 25 32 93 35 4 49 28 48 69 87 22 46 43 71 66 37 63 50 10 54 53 58 36 44 3 14
-1
2 4 3 1
-1
-1
-1
-...

result:

ok 1000 lines

Test #11:

score: 0
Accepted
time: 43ms
memory: 3700kb

input:

10000
15 15
14 2 5 7 9 15 4 12 10 6 1 3 13 11 8
84 4
56 16 12 74 14 71 40 21 13 52 78 2 4 46 29 3 36 70 32 22 75 58 63 27 45 6 26 47 64 33 44 31 15 28 24 1 67 30 83 68 76 73 82 39 54 38 35 41 42 61 53 11 66 34 51 37 81 25 62 17 18 5 57 60 10 84 8 48 9 19 69 80 79 7 23 59 49 43 20 55 72 77 65 50
9 17...

output:

-1
-1
-1
-1
52 55 34 79 54 22 91 82 94 16 86 41 9 38 31 78 75 72 15 46 6 45 17 35 56 70 58 73 3 40 62 57 39 84 26 65 59 53 13 87 80 92 69 88 76 19 21 90 89 4 11 42 95 44 93 51 30 48 32 36 37 5 7 63 33 50 1 49 2 28 8 24 74 77 27 47 83 43 12 14 29 20 68 85 67 25 81 10 61 60 18 71 64 66 23
-1
67 80 22 ...

result:

ok 10000 lines

Test #12:

score: 0
Accepted
time: 52ms
memory: 4464kb

input:

1000
999 1602
532 982 788 569 395 942 891 814 393 246 562 806 668 631 296 787 663 782 641 448 971 98 170 14 361 249 46 133 484 402 41 608 885 825 790 724 614 304 411 644 779 567 290 931 449 47 242 121 708 433 16 358 536 933 784 773 180 851 80 459 896 254 956 604 970 540 215 541 537 639 669 939 943 3...

output:

-1
338 79 456 38 709 479 273 451 252 617 233 464 503 511 64 342 42 541 627 679 241 275 299 25 160 75 494 182 67 172 18 316 231 680 558 578 690 715 112 107 449 741 434 188 610 422 448 559 81 223 203 676 63 333 163 705 637 232 144 698 518 26 362 738 493 153 589 548 122 602 80 263 381 329 83 565 177 58...

result:

ok 1000 lines

Test #13:

score: 0
Accepted
time: 51ms
memory: 7548kb

input:

100
186 134
128 34 170 56 136 10 62 50 48 144 1 66 91 99 153 149 77 87 156 8 29 36 57 183 69 90 28 51 115 76 21 101 49 65 71 173 73 25 154 70 116 89 24 103 22 167 138 68 88 119 31 46 166 125 126 181 78 178 104 9 130 60 11 177 127 44 47 4 30 45 171 185 3 38 92 162 17 63 114 118 23 106 81 184 37 27 14...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1732 762 2848 1365 107 1567 1202 2362 970 573 1051 2142 1037 1479 1003 24 439 2026 2352 304 2689 2579 500 1658 1232 6 1402 2824 2841 967 1044 411 2343 1322 1254 3015 1135 780 3125 1937 2494 232 1175 1807 1454 2582 853 3104 1475 1843 2059 2005 383 2929 ...

result:

ok 100 lines

Test #14:

score: 0
Accepted
time: 67ms
memory: 39384kb

input:

10
32077 42391
17986 10802 3107 8912 23279 16553 26516 8313 5924 9342 3829 29290 420 18508 29472 24529 26449 5893 28485 983 8073 2722 21478 23941 22613 19864 12364 25856 27509 7951 21218 17202 13121 17591 11609 13300 15719 31876 26033 24795 25899 6433 15759 2051 29655 12031 17813 16091 28725 13894 1...

output:

-1
-1
14839 5132 2966 10074 468 13948 15989 2478 9665 9212 14639 13705 2031 13708 11921 1614 3620 20187 5082 6026 15300 2595 9727 11867 4001 10527 1418 3619 5085 3980 19407 3520 18446 11589 15261 2454 10763 9889 18895 19896 11432 2793 5 3503 19524 17879 7552 12847 12146 15744 15301 16217 18281 20746...

result:

ok 10 lines

Test #15:

score: 0
Accepted
time: 87ms
memory: 84532kb

input:

5
200000 357261
49805 123255 26648 123787 16881 172698 147556 44746 40569 173176 122155 103751 174194 42928 65635 130130 149126 189179 107060 107100 24399 154028 105771 158652 109927 78981 3086 159721 126652 130391 194285 50663 143730 191701 193671 180950 28088 11584 174201 191920 25968 31954 116771...

output:

-1
143838 18024 41263 111462 34584 179044 118745 153971 5814 99626 107956 133071 46127 136547 100260 54744 167298 121071 166176 199011 132209 109000 47621 171257 168076 199027 190697 127624 194291 169706 63927 104217 38796 198715 49650 136501 132599 122404 169308 8320 55450 132159 83408 184311 18244...

result:

ok 5 lines

Extra Test:

score: 0
Extra Test Passed