QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#218704#5525. Increasing GridwoshiluoAC ✓10ms5572kbC++203.3kb2023-10-18 17:15:442023-10-18 17:15:44

Judging History

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

  • [2023-10-18 17:15:44]
  • 评测
  • 测评结果:AC
  • 用时:10ms
  • 内存:5572kb
  • [2023-10-18 17:15:44]
  • 提交

answer

/*
 * i.cpp 2023-10-18
 * Copyright (C) 2023 Woshiluo Luo <[email protected]>
 *
 * 「Two roads diverged in a wood,and I—
 * I took the one less traveled by,
 * And that has made all the difference.」
 *
 * Distributed under terms of the GNU GNU AGPLv3+ license.
 */

#include <cstdio>
#include <cstdlib>
#include <cstring>

#include <vector>
#include <algorithm>

typedef const int cint;
typedef long long ll;
typedef unsigned long long ull;

inline bool isdigit( const char cur ) { return cur >= '0' && cur <= '9'; }/*{{{*/
template <class T> 
T Max( T a, T b ) { return a > b? a: b; }
template <class T> 
T Min( T a, T b ) { return a < b? a: b; }
template <class T> 
void chk_Max( T &a, T b ) { if( b > a ) a = b; }
template <class T> 
void chk_Min( T &a, T b ) { if( b < a ) a = b; }
template <typename T>
T read() { 
	T sum = 0, fl = 1; 
	char ch = getchar();
	for (; isdigit(ch) == 0; ch = getchar())
		if (ch == '-') fl = -1;
	for (; isdigit(ch); ch = getchar()) sum = sum * 10 + ch - '0';
	return sum * fl;
}
template <class T> 
T pow( T a, int p ) {
	T res = 1;
	while( p ) {
		if( p & 1 ) 
			res = res * a;
		a = a * a;
		p >>= 1;
	}
	return res;
}/*}}}*/

const int mod = 998244353;

struct ModInt {/*{{{*/
	int cur;
	ModInt( ll _cur = 0 ) { cur = ( ( ( _cur % mod ) + mod ) % mod ); }

	inline ModInt operator+ ( const ModInt &b ) const { return ( cur + b.cur ) % mod; }
	inline ModInt operator- ( const ModInt &b ) const { return ( ( ( cur - b.cur ) % mod ) + mod ) % mod; }
	inline ModInt operator* ( const ModInt &b ) const { return ( 1LL * cur * b.cur ) % mod; }
	inline ModInt operator/ ( const ModInt &b ) const { return ( 1LL * cur * pow( b, mod - 2 ).cur ) % mod; }

	inline void operator+= ( const ModInt &b ) { (*this) = (*this) + b; }
	inline void operator-= ( const ModInt &b ) { (*this) = (*this) - b; }
	inline void operator*= ( const ModInt &b ) { (*this) = (*this) * b; }
	inline void operator/= ( const ModInt &b ) { (*this) = (*this) / b; }

	inline void output( const char end = '\n' ) { printf( "%d%c", cur, end ); }
};/*}}}*/

int work() {
	cint n = read<int>();
	cint m = read<int>();

	std::vector<std::vector<int>> a( n + 1, std::vector<int>( m + 3 ) );
	std::vector<std::vector<ModInt>> f( n + 5, std::vector<ModInt>( m + 5 ) );

	for( int i = 1; i <= n; i ++) { 
		for( int j = 1; j <= m; j ++ ) {
			a[i][j] = read<int>();
		}
	}

	f[0][ m + 1 ] = 1;
	for( int i = 1; i <= n; i ++ ) {
		int max_l = 0, min_r = m + 1;
		for( int j = 1; j <= m; j ++ ) {
			if( a[i][j] != -1 && ( a[i][j] < i + j - 1 || a[i][j] > i + j ) ) 
				return 0;
		}
		for( int j = 1; j <= m + 1; j ++ ) {
			if( a[i][j] == i + j ) 
				break;
			max_l = j;
		}
		for( int j = m; j >= 1; j -- ) {
			if( a[i][j] == i + j - 1 ) 
				break;
			min_r = j;
		}
		if( max_l + 1 < min_r ) {
			return 0;
		}

		ModInt sum = 0;
		for( int j = m + 1; j >= min_r; j -- ) {
			sum += f[ i - 1 ][j];
			if( max_l + 1 < j )
				continue;
			f[i][j] += sum;
		}
	}

	ModInt ans = 0;
	for( int j = 0; j <= m + 1; j ++ ) 
		ans += f[n][j];

	return ans.cur;
}

int main() {
#ifdef woshiluo
	freopen( "i.in", "r", stdin );
	freopen( "i.out", "w", stdout );
#endif

	int T = read<int>();
	while( T -- ) {
		printf( "%d\n", work() );
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4
2 3
1 2 -1
-1 4 5
4 4
-1 -1 -1 -1
-1 -1 -1 -1
-1 4 4 -1
-1 -1 -1 -1
4 4
-1 -1 -1 -1
-1 -1 -1 -1
-1 4 5 -1
-1 -1 -1 -1
3 5
1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1

output:

4
0
17
55

result:

ok 4 number(s): "4 0 17 55"

Test #2:

score: 0
Accepted
time: 4ms
memory: 4948kb

input:

1
2857 70
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

266977954

result:

ok 1 number(s): "266977954"

Test #3:

score: 0
Accepted
time: 4ms
memory: 4948kb

input:

1
3225 62
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

43003510

result:

ok 1 number(s): "43003510"

Test #4:

score: 0
Accepted
time: 4ms
memory: 4940kb

input:

1
34 5882
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

181277996

result:

ok 1 number(s): "181277996"

Test #5:

score: 0
Accepted
time: 4ms
memory: 5436kb

input:

1
6 33333
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

942557054

result:

ok 1 number(s): "942557054"

Test #6:

score: 0
Accepted
time: 4ms
memory: 4636kb

input:

1
470 425
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

321320838

result:

ok 1 number(s): "321320838"

Test #7:

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

input:

3
406 164
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

100583745
965682993
506401552

result:

ok 3 number(s): "100583745 965682993 506401552"

Test #8:

score: 0
Accepted
time: 4ms
memory: 4424kb

input:

3
617 108
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

155894158
696179809
26941117

result:

ok 3 number(s): "155894158 696179809 26941117"

Test #9:

score: 0
Accepted
time: 4ms
memory: 4212kb

input:

3
784 85
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

output:

737523059
603224993
597349569

result:

ok 3 number(s): "737523059 603224993 597349569"

Test #10:

score: 0
Accepted
time: 4ms
memory: 4080kb

input:

3
29 2298
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

396891105
947304368
510868160

result:

ok 3 number(s): "396891105 947304368 510868160"

Test #11:

score: 0
Accepted
time: 2ms
memory: 4120kb

input:

3
247 269
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

379112706
335134214
355847359

result:

ok 3 number(s): "379112706 335134214 355847359"

Test #12:

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

input:

10
204 98
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

61226798
40628357
439703518
849778142
656626189
169864409
849924485
969955039
428968320
858402932

result:

ok 10 numbers

Test #13:

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

input:

100
74 27
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

626032214
502739587
940612786
578571800
88511598
317568922
846512485
662780782
971010183
361731076
838456187
444876395
546444396
361731076
49679494
756067232
127657859
626032214
345074838
501501
612101462
304454789
317568922
304454789
546444396
683337149
679990133
794529481
2001
846512485
124419476
...

result:

ok 100 numbers

Test #14:

score: 0
Accepted
time: 6ms
memory: 3832kb

input:

1000
14 14
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -...

output:

40116600
1221759
5151
1221759
20160075
40116600
30045015
40116600
13884156
6724520
40116600
37442160
34597290
37442160
6724520
316251
3262623
316251
40116600
30045015
201
30421755
30045015
30045015
316251
52394
37442160
1221759
34597290
52394
3262623
316251
201
6724520
40116600
1221759
13884156
4011...

result:

ok 1000 numbers

Test #15:

score: 0
Accepted
time: 9ms
memory: 3708kb

input:

10000
20 1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
3 6
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1
4 5
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
4 5
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
-1 -1 -1 -1 -1
10 2
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1 -1
-1...

output:

21
84
126
126
66
84
21
21
84
126
21
66
21
21
21
21
66
21
84
66
84
66
66
66
126
21
126
84
84
84
84
21
126
126
66
21
21
84
126
21
84
84
21
21
66
66
21
66
84
21
84
66
21
126
84
21
84
66
66
126
66
66
21
21
126
66
66
126
66
84
126
66
126
66
21
21
84
126
66
21
66
21
21
84
126
126
66
21
66
126
21
84
66
84
...

result:

ok 10000 numbers

Test #16:

score: 0
Accepted
time: 4ms
memory: 4820kb

input:

1
2857 70
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

226015187

result:

ok 1 number(s): "226015187"

Test #17:

score: 0
Accepted
time: 2ms
memory: 4952kb

input:

1
3225 62
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

927015823

result:

ok 1 number(s): "927015823"

Test #18:

score: 0
Accepted
time: 2ms
memory: 4876kb

input:

1
34 5882
1 -1 3 -1 -1 6 7 8 9 -1 11 12 -1 14 15 -1 -1 18 -1 20 21 22 -1 -1 25 26 27 28 29 30 31 -1 -1 -1 -1 36 -1 38 -1 -1 -1 -1 43 44 -1 -1 -1 48 -1 50 51 -1 -1 54 -1 56 -1 -1 59 60 -1 62 63 64 65 -1 67 -1 -1 -1 -1 -1 73 74 75 -1 77 -1 79 80 81 -1 83 -1 85 86 87 88 89 -1 91 92 93 94 95 96 97 98 -1...

output:

990886230

result:

ok 1 number(s): "990886230"

Test #19:

score: 0
Accepted
time: 4ms
memory: 5456kb

input:

1
6 33333
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

422786771

result:

ok 1 number(s): "422786771"

Test #20:

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

input:

1
470 425
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

877984607

result:

ok 1 number(s): "877984607"

Test #21:

score: 0
Accepted
time: 4ms
memory: 4120kb

input:

3
406 164
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

326935456
584792895
464096788

result:

ok 3 number(s): "326935456 584792895 464096788"

Test #22:

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

input:

3
617 108
-1 -1 -1 4 -1 -1 7 -1 9 10 -1 12 13 14 15 -1 17 -1 19 -1 -1 -1 -1 24 25 -1 -1 -1 29 -1 31 32 -1 -1 35 -1 -1 -1 39 -1 -1 42 43 -1 -1 -1 47 48 49 -1 -1 52 -1 54 55 56 57 58 59 -1 61 62 -1 64 65 66 -1 -1 -1 70 71 -1 -1 74 -1 -1 -1 78 -1 -1 -1 -1 83 84 -1 86 -1 -1 -1 90 91 92 -1 94 95 -1 97 -1...

output:

364084446
692976084
535691147

result:

ok 3 number(s): "364084446 692976084 535691147"

Test #23:

score: 0
Accepted
time: 4ms
memory: 4208kb

input:

3
784 85
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

output:

408436895
106596377
329390492

result:

ok 3 number(s): "408436895 106596377 329390492"

Test #24:

score: 0
Accepted
time: 4ms
memory: 4112kb

input:

3
29 2298
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

488213402
857645806
987649594

result:

ok 3 number(s): "488213402 857645806 987649594"

Test #25:

score: 0
Accepted
time: 4ms
memory: 4136kb

input:

3
247 269
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

901504397
956940083
609589347

result:

ok 3 number(s): "901504397 956940083 609589347"

Test #26:

score: 0
Accepted
time: 6ms
memory: 5572kb

input:

10
204 98
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

423835890
772235276
655736616
170741944
25381097
793735997
16194064
4
192
522241336

result:

ok 10 numbers

Test #27:

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

input:

100
74 27
-1 -1 3 4 5 6 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 19 20 21 22 -1 -1 25 -1 27
-1 -1 -1 -1 -1 -1 -1 -1 10 -1 12 13 -1 -1 -1 17 18 19 -1 -1 22 -1 24 25 26 -1 -1
3 -1 5 -1 -1 8 -1 -1 -1 12 13 -1 -1 -1 -1 18 19 20 -1 22 -1 -1 -1 -1 27 -1 -1
-1 -1 -1 -1 -1 9 -1 11 12 13 14 15 -1 -1 18 -1 -1 21 -...

output:

694977529
296372109
961307647
302497360
294566522
410164164
135
868063660
752605382
664715962
117696471
221184
96768
76608
944234136
225917224
209375095
38367
108
158735542
552772149
308270859
623714867
276214491
630502747
509548188
778934141
265571436
343358036
830148880
47520
4992
23077887
8555835...

result:

ok 100 numbers

Test #28:

score: 0
Accepted
time: 7ms
memory: 3792kb

input:

1000
14 14
-1 -1 -1 4 -1 -1 -1 8 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 13 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 16 -1
-1 -1 -1 -1 -1 -1 -1 -1 13 -1 -1 -1 -1 -1
-1 7 8 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

4116125
64
2281400
27720
17133020
60
8
36
977980
238560
39694
6
1430
16
440
816
4504
1540962
25637976
451
11623030
1088
12
1714669
19955909
849387
24
12288
128
9381848
2857855
247800
120
66582
6054087
1082706
16
343710
54
24866478
49469
8
612
320
7368240
651287
24
640
240
24677926
1440
24506482
8073...

result:

ok 1000 numbers

Test #29:

score: 0
Accepted
time: 10ms
memory: 3804kb

input:

10000
20 1
-1
-1
-1
-1
6
7
-1
9
10
-1
-1
-1
-1
-1
-1
-1
-1
-1
20
-1
20 1
-1
-1
4
-1
-1
7
-1
9
10
-1
-1
-1
-1
15
16
17
18
-1
20
21
10 2
1 -1
2 -1
-1 -1
-1 6
-1 -1
6 8
7 9
8 -1
9 -1
-1 -1
1 20
1 2 -1 -1 5 6 -1 -1 9 -1 -1 -1 -1 -1 -1 17 -1 -1 -1 -1
2 10
1 -1 -1 4 5 -1 -1 9 -1 -1
-1 -1 4 5 -1 8 9 -1 11 ...

output:

5
3
8
7
6
1
14
2
56
60
21
4
1
9
5
7
12
3
1
3
24
6
5
3
5
76
17
19
15
11
12
17
14
12
1
70
2
7
6
5
8
7
25
4
3
7
8
17
24
5
45
20
20
6
9
11
13
3
9
6
6
1
5
63
48
15
7
16
7
10
5
12
8
12
3
2
24
1
28
9
75
4
1
4
60
71
1
2
7
4
15
9
7
12
9
2
72
4
11
4
8
3
9
20
2
4
10
60
12
51
81
3
9
36
2
1
18
24
7
3
2
20
2
1
8
...

result:

ok 10000 numbers

Test #30:

score: 0
Accepted
time: 4ms
memory: 4876kb

input:

1
2857 70
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0

result:

ok 1 number(s): "0"

Test #31:

score: 0
Accepted
time: 4ms
memory: 5124kb

input:

1
3225 62
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0

result:

ok 1 number(s): "0"

Test #32:

score: 0
Accepted
time: 4ms
memory: 4900kb

input:

1
34 5882
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0

result:

ok 1 number(s): "0"

Test #33:

score: 0
Accepted
time: 3ms
memory: 5420kb

input:

1
6 33333
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0

result:

ok 1 number(s): "0"

Test #34:

score: 0
Accepted
time: 4ms
memory: 4720kb

input:

1
470 425
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

890874805

result:

ok 1 number(s): "890874805"

Test #35:

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

input:

3
406 164
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0
0
692246464

result:

ok 3 number(s): "0 0 692246464"

Test #36:

score: 0
Accepted
time: 4ms
memory: 4096kb

input:

3
617 108
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

379270627
830168837
0

result:

ok 3 number(s): "379270627 830168837 0"

Test #37:

score: 0
Accepted
time: 4ms
memory: 4548kb

input:

3
784 85
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

output:

683914361
0
0

result:

ok 3 number(s): "683914361 0 0"

Test #38:

score: 0
Accepted
time: 4ms
memory: 4416kb

input:

3
29 2298
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 50 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0
0
0

result:

ok 3 number(s): "0 0 0"

Test #39:

score: 0
Accepted
time: 4ms
memory: 4092kb

input:

3
247 269
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0
163867028
314228181

result:

ok 3 number(s): "0 163867028 314228181"

Test #40:

score: 0
Accepted
time: 3ms
memory: 4036kb

input:

10
204 98
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

977871808
0
452851657
0
956810861
165517803
0
60504822
632702764
0

result:

ok 10 numbers

Test #41:

score: 0
Accepted
time: 2ms
memory: 3872kb

input:

100
74 27
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0
0
284542063
0
996507058
643504531
0
172034941
0
0
865745389
513166363
376276690
0
876231714
0
0
0
0
0
935471683
0
937930370
164057082
0
0
0
0
158671184
0
0
590035196
0
797759166
0
0
0
0
99743472
0
0
0
0
0
34944594
0
279799476
0
0
0
0
0
430525026
377470096
28587772
0
0
741007574
0
0
0
577605907
977...

result:

ok 100 numbers

Test #42:

score: 0
Accepted
time: 6ms
memory: 3848kb

input:

1000
14 14
-1 -1 -1 -1 -1 -1 -1 9 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 13 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 15 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 17 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1...

output:

0
0
0
0
0
0
0
0
0
0
0
10530
184870
22386
0
0
350
6720143
9327696
0
0
0
0
0
5328687
0
0
0
0
0
12397
0
0
15301
0
0
0
0
0
0
0
857208
0
0
18575
0
0
7220
99968
94240
5040
0
0
0
0
1000792
0
875150
0
10846143
0
2244
0
0
334125
0
0
22638
0
0
0
37542195
0
0
0
0
0
0
0
0
7102753
0
33649
0
30032464
0
5910900
0
...

result:

ok 1000 numbers

Test #43:

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

input:

10000
20 1
-1
3
-1
-1
-1
6
8
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1
20
-1
20 1
-1
2
-1
-1
-1
7
-1
-1
-1
-1
-1
-1
13
-1
-1
-1
18
-1
19
20
20 1
-1
-1
-1
-1
5
-1
-1
-1
-1
-1
-1
-1
13
-1
-1
-1
-1
18
-1
-1
2 10
-1 -1 -1 -1 -1 6 -1 -1 -1 11
-1 -1 -1 -1 -1 -1 8 -1 10 -1
20 1
1
-1
-1
-1
-1
-1
8
9
-1
-1
-1
-1
13
-...

output:

0
0
3
1
0
21
0
0
2
5
1
0
1
0
0
0
75
2
21
12
0
80
0
35
0
21
0
0
64
4
15
29
0
3
56
0
0
0
0
4
2
6
3
0
0
0
10
0
1
0
5
0
18
0
0
0
2
106
0
0
0
0
0
0
4
0
1
10
0
0
15
25
21
35
15
3
0
51
0
64
0
0
3
0
19
0
0
0
0
0
9
0
0
0
0
0
3
0
0
0
16
1
20
0
0
17
4
55
0
45
1
0
0
0
51
0
29
0
8
13
0
0
111
8
0
0
0
0
0
10
6
3
0...

result:

ok 10000 numbers