QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#497847#3837. The Matching System PetroTarnavskyi#AC ✓16ms12024kbC++202.1kb2024-07-29 19:16:172024-07-29 19:16:17

Judging History

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

  • [2024-07-29 19:16:17]
  • 评测
  • 测评结果:AC
  • 用时:16ms
  • 内存:12024kb
  • [2024-07-29 19:16:17]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int mod = 1e9 + 7;

int mult(int a, int b)
{
	return (LL)a * b % mod;
}
int add(int a, int b)
{
	return a + b < mod ? a + b : a + b - mod;
}
int binpow(int a, int n)
{
	int res = 1;
	while(n)
	{
		if(n & 1)
			res = mult(res, a);
		a = mult(a, a);
		n /= 2;
	}
	return res;
}

const int N = 1 << 20;
int fact[N], ifact[N];
int C(int n, int k)
{
	if(k < 0 || k > n)
		return 0;
	return mult(fact[n], mult(ifact[k], ifact[n - k]));
}
int H(int cnt, int sum)
{
	return C(sum + cnt - 1, sum);
}

void init()
{
	fact[0] = 1;
	FOR(i, 1, N)
		fact[i] = mult(fact[i - 1], i);
	ifact[N - 1] = binpow(fact[N - 1], mod - 2);
	RFOR(i, N, 1)
		ifact[i - 1] = mult(ifact[i], i);
}





int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	init();
	
	int n;
	cin >> n;
	if(n < 3)
	{
		if(n == 1)
		{
			cout << "0" << "\n";
			cout << "0" << "\n";
			cout << "1" << "\n";
			cout << "*" << "\n";
			cout << "0" << "\n";
			cout << "2" << "\n";
		}
		else
		{
			cout << "*0" << "\n";
			cout << "00" << "\n";
			cout << "3" << "\n";
			cout << "*0" << "\n";
			cout << "00" << "\n";
			cout << "4" << "\n";
		}
		return 0;
	}
	cout << string(n - 2, '*') + "0*" << "\n";
	cout << "0" + string(n - 1, '1') << "\n";
	int mxAns = add(1, H(n - 1, n - 1));
	FOR(k, 0, n - 2)
	{
		if(k == 0)
			mxAns = add(mxAns, n + 1);
		else
		{
			FOR(l, 0, n + 1)
			{
				mxAns = add(mxAns, mult(n - l + 1, H(k, l)));
			}
		}
	}
	cout << mxAns << "\n";
	
	
	
	cout << string((n + 1) / 2, '*') + string(n / 2, '0') << "\n";
	cout << string(n, '0') << "\n";
	int k = n / 2;
	int mnAns = k * (k + 3);
	if(n & 1)
		mnAns += k + 2;
	cout << mnAns << "\n";
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 7ms
memory: 11812kb

input:

3

output:

*0*
011
8
**0
000
7

result:

ok Accepted

Test #2:

score: 0
Accepted
time: 11ms
memory: 11948kb

input:

1

output:

0
0
1
*
0
2

result:

ok Accepted

Test #3:

score: 0
Accepted
time: 11ms
memory: 11728kb

input:

2

output:

*0
00
3
*0
00
4

result:

ok Accepted

Test #4:

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

input:

4

output:

**0*
0111
31
**00
0000
10

result:

ok Accepted

Test #5:

score: 0
Accepted
time: 11ms
memory: 11980kb

input:

5

output:

***0*
01111
119
***00
00000
14

result:

ok Accepted

Test #6:

score: 0
Accepted
time: 11ms
memory: 11804kb

input:

6

output:

****0*
011111
456
***000
000000
18

result:

ok Accepted

Test #7:

score: 0
Accepted
time: 11ms
memory: 11812kb

input:

10

output:

********0*
0111111111
99892
*****00000
0000000000
40

result:

ok Accepted

Test #8:

score: 0
Accepted
time: 11ms
memory: 11784kb

input:

20

output:

******************0*
01111111111111111111
31775330
**********0000000000
00000000000000000000
130

result:

ok Accepted

Test #9:

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

input:

30

output:

****************************0*
011111111111111111111111111111
37652369
***************000000000000000
000000000000000000000000000000
270

result:

ok Accepted

Test #10:

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

input:

50

output:

************************************************0*
01111111111111111111111111111111111111111111111111
637736708
*************************0000000000000000000000000
00000000000000000000000000000000000000000000000000
700

result:

ok Accepted

Test #11:

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

input:

100

output:

**************************************************************************************************0*
0111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
990322733
**************************************************00000000000000000000000000000000000000...

result:

ok Accepted

Test #12:

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

input:

200

output:

******************************************************************************************************************************************************************************************************0*
011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

result:

ok Accepted

Test #13:

score: 0
Accepted
time: 12ms
memory: 12024kb

input:

499

output:

************************************************************************************************************************************************************************************************************************************************************************************************************...

result:

ok Accepted

Test #14:

score: 0
Accepted
time: 15ms
memory: 11748kb

input:

888

output:

************************************************************************************************************************************************************************************************************************************************************************************************************...

result:

ok Accepted

Test #15:

score: 0
Accepted
time: 16ms
memory: 11724kb

input:

999

output:

************************************************************************************************************************************************************************************************************************************************************************************************************...

result:

ok Accepted

Test #16:

score: 0
Accepted
time: 16ms
memory: 11728kb

input:

1000

output:

************************************************************************************************************************************************************************************************************************************************************************************************************...

result:

ok Accepted