QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550309#9251. Graph Changingucup-team896#AC ✓327ms4000kbC++238.1kb2024-09-07 11:26:352024-09-07 11:26:35

Judging History

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

  • [2024-09-07 11:26:35]
  • 评测
  • 测评结果:AC
  • 用时:327ms
  • 内存:4000kb
  • [2024-09-07 11:26:35]
  • 提交

answer

/*  _              _     _                                             _       __      __      __   
   / \     _   _  | |_  | |__     ___    _ __   _    ___   _ __ ___   | | __  / /_    / /_    / /_  
  / _ \   | | | | | __| | '_ \   / _ \  | '__| (_)  / __| | '_ ` _ \  | |/ / | '_ \  | '_ \  | '_ \ 
 / ___ \  | |_| | | |_  | | | | | (_) | | |     _  | (__  | | | | | | |   <  | (_) | | (_) | | (_) |
/_/   \_\  \__,_|  \__| |_| |_|  \___/  |_|    (_)  \___| |_| |_| |_| |_|\_\  \___/   \___/   \___/ 
[Created Time:       2024-09-07 10:52:54]
[Last Modified Time: 2024-09-07 11:25:44] */
#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
#ifdef LOCAL
#include"debug.h"
#else
#define D(...) ((void)0)
#endif
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
/*namespace FastIO
{
// ------------------------------
// #define DISABLE_MMAP
// ------------------------------
#if ( defined(LOCAL) || defined(_WIN32) ) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifdef LOCAL
	inline char gc() { return getchar(); }
	inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
	inline constexpr int _READ_SIZE = 1 << 18;
	inline static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr, *_read_ptr_end = nullptr;
	inline char gc()
	{
		if ( __builtin_expect(_read_ptr == _read_ptr_end, false) )
		{
			_read_ptr = _read_buffer, _read_ptr_end = _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
			if ( __builtin_expect(_read_ptr == _read_ptr_end, false) ) return EOF;
		}
		return *_read_ptr++;
	}
#else
#include<sys/mman.h>
	inline static const char *_read_ptr = (const char *)mmap(nullptr, 0x7fffffff, 1, 2, 0, 0);
	inline char gc() { return *_read_ptr++; }
#endif
	inline constexpr int _WRITE_SIZE = 1 << 18;
	inline static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
	inline void pc(char c)
	{
		*_write_ptr++ = c;
		if ( __builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false) )
			fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout), _write_ptr = _write_buffer;
	}
	inline struct _auto_flush
	{
		inline ~_auto_flush() { fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout); }
	}	_auto_flush;
#endif
#define println println_ // don't use C++23 std::println
	template < class T > inline constexpr bool _is_signed = numeric_limits < T >::is_signed;
	template < class T > inline constexpr bool _is_unsigned = numeric_limits < T >::is_integer && !_is_signed < T >;
#if __SIZEOF_LONG__ == 64
	template <> inline constexpr bool _is_signed < __int128 > = true;
	template <> inline constexpr bool _is_unsigned < __uint128_t > = true;
#endif
	inline void read(char &c) { do c = gc(); while ( !isgraph(c) ); }
	inline void read_cstr(char *s)
	{
		char c = gc(); while ( !isgraph(c) ) c = gc();
		while ( isgraph(c) ) *s++ = c, c = gc(); *s = 0;
	}
	inline void read(string &s)
	{
		char c = gc(); s.clear(); while ( !isgraph(c) ) c = gc();
		while ( isgraph(c) ) s.push_back(c), c = gc();
	}
	template < class T, enable_if_t < _is_signed < T >, int > = 0 >
	inline void read(T &x)
	{
		char c = gc(); bool f = true; x = 0;
		while ( !isdigit(c) ) { if ( c == 45 ) f = false; c = gc(); }
		if ( f ) while ( isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
		else     while ( isdigit(c) ) x = x * 10 - ( c & 15 ), c = gc();
	}
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
	inline void read(T &x)
	{
		char c = gc(); while ( !isdigit(c) ) c = gc();
		x = 0; while ( isdigit(c) ) x = x * 10 + ( c & 15 ), c = gc();
	}
	inline void write(char c) { pc(c); }
	inline void write_cstr(const char *s) { while ( *s ) pc(*s++); }
	inline void write(const string &s) { for ( char c : s ) pc(c); }
	template < class T, enable_if_t < _is_signed < T >, int > = 0 >
	inline void write(T x)
	{
		char buffer[numeric_limits < T >::digits10 + 1]; int digits = 0;
		if ( x >= 0 )  do buffer[digits++] =  ( x % 10 ) | 48, x /= 10; while ( x );
		else { pc(45); do buffer[digits++] = -( x % 10 ) | 48, x /= 10; while ( x ); }
		while ( digits ) pc(buffer[--digits]);
	}
	template < class T, enable_if_t < _is_unsigned < T >, int > = 0 >
	inline void write(T x)
	{
		char buffer[numeric_limits < T >::digits10]; int digits = 0;
		do buffer[digits++] = ( x % 10 ) | 48, x /= 10; while ( x );
		while ( digits ) pc(buffer[--digits]);
	}
	template < int N > struct _tuple_io_helper
	{
		template < class ...T > static inline void _read(tuple < T... > &x) { _tuple_io_helper < N - 1 >::_read(x), read(get<N - 1>(x)); }
		template < class ...T > static inline void _write(const tuple < T... > &x) { _tuple_io_helper < N - 1 >::_write(x), pc(32), write(get<N - 1>(x)); }
	};
	template <> struct _tuple_io_helper < 1 >
	{
		template < class ...T > static inline void _read(tuple < T... > &x) { read(get<0>(x)); }
		template < class ...T > static inline void _write(const tuple < T... > &x) { write(get<0>(x)); }
	};
	template < class ...T > inline void read(tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_read(x); }
	template < class ...T > inline void write(const tuple < T... > &x) { _tuple_io_helper < sizeof...(T) >::_write(x); }
	template < class T1, class T2 > inline void read(pair < T1, T2 > &x) { read(x.first), read(x.second); }
	template < class T1, class T2 > inline void write(const pair < T1, T2 > &x) { write(x.first), pc(32), write(x.second); }
	template < class T1, class ...T2 > inline void read(T1 &x, T2 &...y) { read(x), read(y...); }
	template < class ...T > inline void read_cstr(char *x, T *...y) { read_cstr(x), read_cstr(y...); }
	template < class T1, class ...T2 > inline void write(const T1 &x, const T2 &...y) { write(x), write(y...); }
	template < class ...T > inline void write_cstr(const char *x, const T *...y) { write_cstr(x), write_cstr(y...); }
	template < class T > inline void print(const T &x) { write(x); }
	inline void print_cstr(const char *x) { write_cstr(x); }
	template < class T1, class ...T2 > inline void print(const T1 &x, const T2 &...y) { write(x), pc(32), print(y...); }
	template < class ...T > inline void print_cstr(const char *x, const T *...y) { write_cstr(x), pc(32), print_cstr(y...); }
	inline void println() { pc(10); } inline void println_cstr() { pc(10); }
	template < class ...T > inline void println(const T &...x) { print(x...), pc(10); }
	template < class ...T > inline void println_cstr(const T *...x) { print_cstr(x...), pc(10); }
}	using FastIO::read, FastIO::read_cstr, FastIO::write, FastIO::write_cstr, FastIO::println, FastIO::println_cstr;*/
constexpr int N = 10, inf = numeric_limits < int >::max() >> 1;
int dis[11][11][11][11][11], t, n, k, x, y;
inline void init()
{
	For(n, 2, N) For(k, 1, n - 1)
	{
		For(i, 1, n) For(j, 1, n) dis[n][k][0][i][j] = abs(i - j) == 1 ? 1 : inf;
		For(t, 0, N)
		{
			if ( t ) For(i, 1, n) For(j, 1, n)
				dis[n][k][t][i][j] = dis[n][k][t - 1][i][j] != inf && dis[n][k][t - 1][i][j] >= k ? 1 : inf;
			For(l, 1, n) For(i, 1, n) For(j, 1, n)
				dis[n][k][t][i][j] = min(dis[n][k][t][i][j], dis[n][k][t][i][l] + dis[n][k][t][l][j]);
		}
	}
}
inline void work()
{
	cin >> t >> n >> k >> x >> y; // read(t, n, k, x, y);
#define println(_) cout << (_) << '\n'
	if ( x > y ) swap(x, y);
	if ( !t ) { println(y - x); return; }
	if ( k >= n ) { println(-1); return; }
	if ( n <= N )
	{
		t = min(t, N - ( t & 1 ));
		println(dis[n][k][t][x][y] == inf ? -1 : dis[n][k][t][x][y]); return;
	}
	if ( k == 1 ) { println(1); return; }
	if ( k == 2 ) { println(~t & 1 ? y - x : y - x == 1 ? 2 : 1); return; }
	if ( t > 1 ) { println(-1); return; }
	if ( y - x >= k ) { println(1); return; }
	if ( x - 1 < k && n - x < k ) { println(-1); return; }
	if ( y - 1 < k && n - y < k ) { println(-1); return; }
	if ( x - 1 >= k && y - 1 >= k ) { println(2); return; }
	if ( n - x >= k && n - y >= k ) { println(2); return; }
	println(3);
}
int main() { int t; init(), /*read(t)*/cin.tie(nullptr) -> sync_with_stdio(false), cin >> t; For(tt, 1, t) work(); return 0; }
// 想上GM捏 想上GM捏 想上GM捏 想上GM捏 想上GM捏
// 伊娜可爱捏 伊娜贴贴捏

详细

Test #1:

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

input:

5
1 5 3 2 4
1 10 4 2 4
2 10 5 2 4
1 3 2 1 3
1 3 2 1 2

output:

3
2
-1
1
-1

result:

ok 5 lines

Test #2:

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

input:

30
1 2 1 1 2
1 2 2 1 2
1 2 3 1 2
1 2 4 1 2
1 2 5 1 2
1 2 6 1 2
2 2 1 1 2
2 2 2 1 2
2 2 3 1 2
2 2 4 1 2
2 2 5 1 2
2 2 6 1 2
3 2 1 1 2
3 2 2 1 2
3 2 3 1 2
3 2 4 1 2
3 2 5 1 2
3 2 6 1 2
4 2 1 1 2
4 2 2 1 2
4 2 3 1 2
4 2 4 1 2
4 2 5 1 2
4 2 6 1 2
5 2 1 1 2
5 2 2 1 2
5 2 3 1 2
5 2 4 1 2
5 2 5 1 2
5 2 6 1 2

output:

1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1

result:

ok 30 lines

Test #3:

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

input:

90
1 3 1 1 2
1 3 1 1 3
1 3 1 2 3
1 3 2 1 2
1 3 2 1 3
1 3 2 2 3
1 3 3 1 2
1 3 3 1 3
1 3 3 2 3
1 3 4 1 2
1 3 4 1 3
1 3 4 2 3
1 3 5 1 2
1 3 5 1 3
1 3 5 2 3
1 3 6 1 2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1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
1
1
1
2
2
1
1
1
1
1
2
2
1
1
1
1
2
2
1
1
1
2
2
1
1
2
2
1
2
2
2
2
2
2
1
1
1
1
1
2
2
2
1
1
1
1
2
2
3
1
1
1
2
3
3
1
1
2
2
2
1
2
2
2
2
2
2
2
2
2
-1
1
1...

result:

ok 1080 lines

Test #10:

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

input:

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

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
2
2
1
1
1
1
1
2
2
1
1
1
1
2
2
1
1
1
2
2
1
1
2
2
1
2
2
2
2
2
2
1
1
1
1
1
1
2
2
2
1
1
1
...

result:

ok 1350 lines

Test #11:

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

input:

1650
1 11 1 1 2
1 11 1 1 3
1 11 1 1 4
1 11 1 1 5
1 11 1 1 6
1 11 1 1 7
1 11 1 1 8
1 11 1 1 9
1 11 1 1 10
1 11 1 1 11
1 11 1 2 3
1 11 1 2 4
1 11 1 2 5
1 11 1 2 6
1 11 1 2 7
1 11 1 2 8
1 11 1 2 9
1 11 1 2 10
1 11 1 2 11
1 11 1 3 4
1 11 1 3 5
1 11 1 3 6
1 11 1 3 7
1 11 1 3 8
1 11 1 3 9
1 11 1 3 10
1 11...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
1
2
2
1
1
1
1
1
1
2
2
1
1
1
1
1
2
2
1
1
1
1
...

result:

ok 1650 lines

Test #12:

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

input:

1980
1 12 1 1 2
1 12 1 1 3
1 12 1 1 4
1 12 1 1 5
1 12 1 1 6
1 12 1 1 7
1 12 1 1 8
1 12 1 1 9
1 12 1 1 10
1 12 1 1 11
1 12 1 1 12
1 12 1 2 3
1 12 1 2 4
1 12 1 2 5
1 12 1 2 6
1 12 1 2 7
1 12 1 2 8
1 12 1 2 9
1 12 1 2 10
1 12 1 2 11
1 12 1 2 12
1 12 1 3 4
1 12 1 3 5
1 12 1 3 6
1 12 1 3 7
1 12 1 3 8
1 1...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
2
1
1
2
1
2
2
2
1
1
1
1
1
1
1
1
1
2
2
1
1
1
1
1
...

result:

ok 1980 lines

Test #13:

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

input:

2340
1 13 1 1 2
1 13 1 1 3
1 13 1 1 4
1 13 1 1 5
1 13 1 1 6
1 13 1 1 7
1 13 1 1 8
1 13 1 1 9
1 13 1 1 10
1 13 1 1 11
1 13 1 1 12
1 13 1 1 13
1 13 1 2 3
1 13 1 2 4
1 13 1 2 5
1 13 1 2 6
1 13 1 2 7
1 13 1 2 8
1 13 1 2 9
1 13 1 2 10
1 13 1 2 11
1 13 1 2 12
1 13 1 2 13
1 13 1 3 4
1 13 1 3 5
1 13 1 3 6
1...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
1
2
1
1
1
1
1
1
1
2
1
1
1
1
1
1
2
1
1
1
1
1
2
1
1
1
1
2
1
1
1
...

result:

ok 2340 lines

Test #14:

score: 0
Accepted
time: 324ms
memory: 3932kb

input:

1000000
247642294 961448649 733001129 279130562 530835402
732002655 505705299 645705556 487588093 488005936
423909487 956469930 42118321 776825480 857914491
573024322 173584499 411922860 68071790 127760171
195256403 617390756 240978977 289616458 604023215
302970816 281642201 617886109 245587163 2738...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 1000000 lines

Test #15:

score: 0
Accepted
time: 327ms
memory: 3996kb

input:

999999
818561732 105393047 308277328 55828222 95820891
626623416 914227808 963423453 365760112 463062746
685116026 447528560 848245265 304903588 410888549
190989264 573411702 351364570 477139815 538078040
165251011 443239658 880597903 283340857 321622039
580345373 729628729 253275172 260647549 56083...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 999999 lines

Test #16:

score: 0
Accepted
time: 318ms
memory: 3864kb

input:

999998
641304551 95615249 714496774 44706863 82597067
99120825 296948618 325272169 221497167 253219866
547135214 407423323 615477879 395311431 402237613
902423318 562586582 197117012 215866474 332581531
746228275 461110170 365490393 8270545 13567149
209099954 601749155 822593415 70976179 302958983
7...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 999998 lines

Test #17:

score: 0
Accepted
time: 317ms
memory: 3876kb

input:

999997
759014662 790870149 120716220 312341665 750583643
908054724 384702127 982088181 220708338 372080663
745590890 662285387 822901980 14637938 407944387
613857370 473613609 192612558 314642869 447537089
327205537 773947983 850382884 367385950 465660605
542887244 473869581 242168554 442534885 4616...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 999997 lines

Test #18:

score: 0
Accepted
time: 307ms
memory: 3920kb

input:

999996
286790189 76059652 676678771 27025196 72899785
380552134 140538090 638904193 140356967 140371077
944046566 622180150 180069186 386081350 473991190
325291423 167821189 333332295 37470414 135098524
834553872 8637942 335275375 984215 5958852
245270753 51022707 516519501 15376414 50059575
4736168...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
...

result:

ok 999996 lines

Test #19:

score: 0
Accepted
time: 275ms
memory: 3884kb

input:

1000000
5 961448649 14 279130562 530835402
0 505705299 11 487588093 488005936
5 956469930 6 776825480 857914491
5 173584499 5 68071790 127760171
5 617390756 2 289616458 604023215
2 281642201 14 245587163 273817065
5 411506287 9 42526705 317589066
3 547485462 9 271470684 437838096
5 996351074 6 74856...

output:

-1
417843
-1
-1
1
-1
-1
-1
-1
1
-1
1
6580696
422807208
153431515
-1
179429643
-1
84805156
-1
654790747
60452774
31347044
15066715
-1
18522683
-1
4346920
1
-1
-1
22973969
1
24950066
-1
-1
96093015
-1
1
-1
-1
-1
-1
-1
18083094
42298920
-1
1
-1
-1
-1
-1
1
-1
-1
90334756
24178093
126162761
-1
-1
-1
-1
1...

result:

ok 1000000 lines

Test #20:

score: 0
Accepted
time: 271ms
memory: 3876kb

input:

999999
0 105393047 8 55828222 95820891
2 914227808 13 365760112 463062746
3 447528560 10 304903588 410888549
1 573411702 5 477139815 538078040
5 443239658 13 283340857 321622039
5 729628729 7 260647549 560838179
3 215299701 10 34885046 213523791
2 859374122 1 544508624 795986441
4 864873312 7 416831...

output:

39992669
-1
-1
1
-1
-1
-1
1
-1
-1
-1
1
1
-1
-1
-1
-1
1
-1
-1
-1
1
10573113
-1
1
-1
-1
1
1
-1
-1
-1
68522961
-1
-1
-1
1
-1
-1
1
1
-1
-1
-1
1
17590651
-1
-1
-1
-1
11554641
-1
1
1
1
-1
-1
288548258
447374910
-1
1
1
19114954
-1
-1
1
1
-1
-1
-1
1
-1
121545976
1
-1
-1
-1
-1
1
-1
-1
-1
22273383
-1
99473454...

result:

ok 999999 lines

Test #21:

score: 0
Accepted
time: 271ms
memory: 3876kb

input:

999998
4 95615249 9 44706863 82597067
1 296948618 14 221497167 253219866
4 407423323 14 395311431 402237613
4 562586582 7 215866474 332581531
5 461110170 3 8270545 13567149
1 601749155 15 70976179 302958983
2 932067490 13 282852789 866650449
3 392745208 11 84796685 215041796
5 181898334 11 141866145...

output:

-1
1
-1
-1
-1
1
-1
-1
-1
350618868
-1
-1
-1
1
-1
-1
-1
1
-1
-1
71256593
1
122819155
20990479
274550506
-1
1
-1
-1
-1
1
-1
-1
-1
-1
118002775
-1
1
-1
-1
1
-1
-1
1
-1
-1
41577280
-1
-1
-1
-1
63382083
-1
-1
1
-1
1
-1
-1
640147
1
-1
254225645
86753831
103490873
54662526
1
-1
1
-1
-1
-1
1
-1
1
-1
1
-1
80...

result:

ok 999998 lines

Test #22:

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

input:

999997
0 790870149 10 312341665 750583643
4 384702127 1 220708338 372080663
2 662285387 10 14637938 407944387
0 473613609 3 314642869 447537089
4 773947983 9 367385950 465660605
5 473869581 14 442534885 461613235
0 726983133 1 417689049 679009425
5 221083595 5 123544654 169809378
0 872038508 7 57750...

output:

438241978
1
-1
132894220
-1
-1
261320376
-1
256026211
81434046
-1
483828385
1
-1
1
-1
-1
1
1
1
-1
-1
316297589
-1
-1
-1
-1
138841964
1
-1
1
149402190
28459733
-1
-1
-1
1
1
1
1
172487273
78450129
5779513
-1
1
-1
-1
-1
84682459
-1
-1
7655353
-1
-1
1
-1
-1
-1
-1
1
-1
-1
391436221
-1
-1
1
52970836
-1
-1...

result:

ok 999997 lines

Test #23:

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

input:

999996
0 76059652 6 27025196 72899785
4 140538090 3 140356967 140371077
0 622180150 1 386081350 473991190
3 167821189 5 37470414 135098524
3 8637942 15 984215 5958852
1 51022707 6 15376414 50059575
0 443750923 11 345920051 385212659
3 459487380 15 354903169 361806660
4 562178684 12 325063103 5252331...

output:

45874589
-1
87909840
-1
-1
1
39292608
-1
-1
1
-1
-1
-1
-1
20865528
-1
1
-1
1
-1
1
-1
1
-1
-1
-1
1
-1
67152271
-1
-1
77079066
1
-1
1
-1
40195106
-1
-1
1
169344308
10313868
1
1
50691532
1
-1
1
-1
1
-1
1
-1
-1
-1
1
-1
-1
1
-1
-1
-1
22802409
-1
1
1
-1
-1
-1
1
31178015
-1
-1
-1
1
-1
-1
14200880
1
-1
2356...

result:

ok 999996 lines

Test #24:

score: 0
Accepted
time: 172ms
memory: 3932kb

input:

1000000
5 6 9 2 5
0 6 6 1 5
5 6 1 3 4
5 5 10 4 5
5 8 7 2 3
2 8 9 3 4
5 7 9 1 6
3 9 9 7 9
5 8 1 1 4
5 2 6 1 2
2 2 3 1 2
5 7 7 5 7
0 10 7 2 3
0 8 1 2 6
0 6 3 1 6
5 10 4 6 7
0 4 6 3 4
4 8 5 5 6
0 5 2 3 5
3 3 8 2 3
0 3 6 2 3
0 5 10 2 4
0 9 4 6 9
0 2 2 1 2
5 9 5 3 7
0 2 7 1 2
4 4 7 1 3
0 10 1 1 2
5 2 1 1...

output:

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

result:

ok 1000000 lines

Test #25:

score: 0
Accepted
time: 181ms
memory: 3988kb

input:

999999
0 5 8 4 5
2 5 3 1 3
3 5 5 4 5
1 3 10 1 3
5 8 3 2 6
5 7 2 1 5
3 9 10 6 9
2 5 1 1 4
4 6 7 3 5
3 3 4 1 3
5 10 10 7 9
1 6 4 5 6
5 10 7 2 10
4 7 2 6 7
4 7 10 6 7
2 6 10 4 5
5 8 4 5 6
1 4 6 3 4
3 5 5 1 5
5 4 9 2 3
3 5 5 3 4
1 5 4 4 5
0 10 8 1 4
3 5 9 1 4
5 8 6 5 6
2 8 6 2 3
3 4 3 3 4
3 8 2 6 7
1 10...

output:

1
-1
-1
-1
-1
1
-1
1
-1
-1
-1
2
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
3
-1
-1
-1
-1
2
-1
1
-1
-1
1
-1
1
-1
1
-1
-1
2
-1
1
2
1
-1
1
3
-1
-1
-1
1
1
-1
2
-1
-1
-1
-1
2
-1
-1
2
2
-1
-1
-1
1
-1
-1
-1
-1
1
1
-1
-1
2
-1
-1
-1
-1
-1
-1
3
-1
1
-1
-1
-1
-1
-1
1
-1
-1
1
1
-1
1
1
-1
1
1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
-1
-1...

result:

ok 999999 lines

Test #26:

score: 0
Accepted
time: 183ms
memory: 3924kb

input:

999998
4 5 4 3 5
1 8 9 3 6
4 10 9 3 7
4 2 2 1 2
5 3 3 1 2
1 2 5 1 2
2 4 3 3 4
3 4 6 2 4
5 9 6 6 8
0 6 8 4 5
3 8 4 4 6
4 8 3 4 5
4 5 6 3 5
1 10 9 7 8
5 6 5 5 6
5 8 3 5 6
2 8 5 4 8
1 10 9 5 9
5 10 7 1 9
5 8 2 4 7
0 5 4 4 5
1 10 5 3 9
0 4 5 3 4
2 8 2 5 7
4 3 2 1 3
3 7 9 3 6
1 9 4 4 6
3 9 1 7 8
3 7 6 1 ...

output:

-1
-1
-1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
1
1
1
2
-1
-1
3
1
-1
1
2
1
-1
-1
-1
1
1
2
-1
-1
1
-1
-1
-1
-1
-1
4
-1
-1
-1
-1
3
-1
-1
1
-1
1
-1
-1
1
1
-1
2
2
1
1
2
-1
2
-1
-1
-1
1
-1
2
-1
-1
-1
1
-1
-1
-1
1
-1
-1
-1
-1
1
4
-1
-1
1
1
-1
2
-1
-1
1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
1
-1
-1
-1
1
...

result:

ok 999998 lines

Test #27:

score: 0
Accepted
time: 180ms
memory: 3988kb

input:

999997
0 9 10 1 3
4 7 1 6 7
2 2 10 1 2
0 3 8 1 3
4 3 4 2 3
5 6 4 5 6
0 6 1 2 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1
2
-1
1
-1
2
-1
-1
-1
-1
-1
-1
-1
1
1
-1
-1
-1
-1
-1
4
1
2
1
-1
1
2
2
-1
-1
-1
1
-1
-1
2
1
1
-1
1
1
-1
-1
1
-1
-1
-1
-1
-1
1
-1
1
-1
2
5
1
-1
-1
...

result:

ok 999996 lines

Extra Test:

score: 0
Extra Test Passed