Submission #31065492


Source Code Expand

#include <bits/stdc++.h>

template < typename T >
inline void read(T &cnt)
{
	cnt = 0; char ch = getchar(); bool op = 1;
	for (; ! isdigit(ch); ch = getchar())
		if (ch == '-') op = 0;
	for (; isdigit(ch); ch = getchar())
		cnt = cnt * 10 + ch - 48;
	cnt = op ? cnt : - cnt;
}
const int N = 3e3 + 10;
int n, p;
int f[N][N][2];
int main()
{
	read(n), read(p);
	f[2][1][1] = 4;
	f[2][2][0] = 3;
	f[2][0][1] = 1;
	for (int i = 3; i <= n; ++ i)
	{
		f[i][0][1] = 1;
		for (int j = 1; j < n; ++ j)
		{
			f[i][j][1] = (f[i - 1][j][0] + f[i - 1][j][1] + 3ll * f[i - 1][j - 1][1] % p) % p;
			if (j >= 2) f[i][j][0] = (2ll * f[i - 1][j - 2][1] % p);
			 f[i][j][0] = (f[i][j][0] + f[i - 1][j - 1][0]) % p;
		}
	}

	for (int i = 1; i < n; ++ i)
		std::cout << f[n][i][1] << ' ';
	return 0;
}

Submission Info

Submission Time
Task F - Keep Connect
User chzhc
Language C++ (GCC 9.2.1)
Score 500
Code Size 818 Byte
Status AC
Exec Time 286 ms
Memory 74088 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 20
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt
Case Name Status Exec Time Memory
example_00.txt AC 5 ms 3456 KiB
example_01.txt AC 2 ms 3588 KiB
hand_00.txt AC 2 ms 3440 KiB
hand_01.txt AC 2 ms 3580 KiB
hand_02.txt AC 2 ms 3508 KiB
hand_03.txt AC 286 ms 74088 KiB
hand_04.txt AC 282 ms 73872 KiB
hand_05.txt AC 282 ms 74072 KiB
random_00.txt AC 143 ms 45464 KiB
random_01.txt AC 112 ms 36340 KiB
random_02.txt AC 257 ms 70348 KiB
random_03.txt AC 269 ms 72180 KiB
random_04.txt AC 6 ms 4488 KiB
random_05.txt AC 281 ms 73476 KiB
random_06.txt AC 260 ms 71116 KiB
random_07.txt AC 272 ms 72468 KiB
random_08.txt AC 206 ms 62660 KiB
random_09.txt AC 244 ms 68288 KiB
random_10.txt AC 281 ms 73752 KiB
random_11.txt AC 268 ms 72244 KiB