QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#234509 | #670. K-th String | PetroTarnavskyi# | WA | 1ms | 3504kb | C++17 | 1.3kb | 2023-11-01 18:22:35 | 2023-11-01 18:22:37 |
Judging History
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'