QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#234509#670. K-th StringPetroTarnavskyi#WA 1ms3504kbC++171.3kb2023-11-01 18:22:352023-11-01 18:22:37

Judging History

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

  • [2023-11-01 18:22:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3504kb
  • [2023-11-01 18:22:35]
  • 提交

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 main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	
	k -= SZ(s);
	int p = 0;
	FOR (i, 1, SZ(s))
	{
		if (s[i] < s[0])
			p |= 1 << i;
	}
	int msk = (1 << SZ(s)) - 1;
	int cnt = s[0] - 'a';
	int ans = 0;
	FOR (mask, 0, 1 << n)
	{
		if (__builtin_popcount(mask) != cnt)
			continue;
		int val = 0;
		FOR (j, 0, n)
		{
			if (mask & (1 << j))
				val += n - j;
		}
		if (val != k)
			continue;
		int ms = msk;
		int pt = p;
		FOR (j, 0, n - SZ(s) + 1)
		{
			if ((mask & ms) == pt)
				ans++;
			ms <<= 1;
			p <<= 1;
		}
	}
	int c = cnt - __builtin_popcount(p);
	
	FOR (i, 1, c + 1)
		ans = mult(ans, i);
	FOR (i, 1, n - c - SZ(s) + 1)
		ans = mult(ans, i);
	cout << ans << '\n';
	
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3396kb

input:

7 12
caedgfb

output:

0

result:

ok single line: '0'

Test #2:

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

input:

2 3
b

output:

1

result:

ok single line: '1'

Test #3:

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

input:

8 4
febadh

output:

0

result:

ok single line: '0'

Test #4:

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

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #5:

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

input:

4 9
bca

output:

0

result:

ok single line: '0'

Test #6:

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

input:

3 2
bc

output:

0

result:

ok single line: '0'

Test #7:

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

input:

1 1
a

output:

1

result:

ok single line: '1'

Test #8:

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

input:

8 8
acgefbdh

output:

1

result:

ok single line: '1'

Test #9:

score: -100
Wrong Answer
time: 1ms
memory: 3504kb

input:

4 7
cb

output:

1

result:

wrong answer 1st lines differ - expected: '2', found: '1'