QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#130679 | #5066. String-dle Count | PetroTarnavskyi | WA | 2ms | 5564kb | C++17 | 2.2kb | 2023-07-24 19:38:49 | 2023-07-24 19:38:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FILL(a, b) memset(a, b, sizeof(a))
typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int mod = 1e9 + 7;
void upd(int& a, int b){
a += b;
if(a >= mod)
a -= mod;
}
const int ALP = 26;
const int K = 19;
int L[ALP], R[ALP];
bool can[ALP][K];
int dp[2][1 << K][K + 1][K + 1];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
FOR(i, 0, ALP){
FOR(j, 0, k)
can[i][j] = 1;
R[i] = k;
L[i] = 0;
R[i] = k;
}
int ans = 1;
FOR(i, 0, n){
string q, a;
cin >> q >> a;
VI cnt(ALP);
FOR(j, 0, k)
cnt[q[j] - 'A'] += (a[j] != 'x');
FOR(j, 0, k){
int pos = q[j] - 'A';
L[pos] = max(L[pos], cnt[pos]);
if(a[j] == 'x'){
can[pos][j] = 0;
if(L[pos] > cnt[pos])
ans = 0;
if(R[pos] < cnt[pos])
ans = 0;
L[pos] = R[pos] = cnt[pos];
continue;
}
if(a[j] == '-')
can[pos][j] = 0;
else{
FOR(bad, 0, ALP)
if(bad != pos)
can[bad][j] = 0;
}
}
}
if(ans == 0){
cout << 0 << "\n";
return 0;
}
dp[0][(1 << k) - 1][0][0] = 1;
FOR(a, 0, ALP){
int t = a % 2;
int nt = (a + 1) % 2;
//clear
FOR(mask, 0, 1 << k)
FOR(bit, 0, k + 1)
FOR(cnt, 0, k + 1)
dp[nt][mask][bit][cnt] = 0;
//FILL(dp[nt], 0);
RFOR(mask, 1 << k, 0){
FOR(bit, 0, k){
FOR(cnt, 0, k + 1){
upd(dp[t][mask][bit + 1][cnt], dp[t][mask][bit][cnt]);
if((mask & (1 << bit)) == 0)
continue;
if(can[a][bit] == 0)
continue;
if(cnt + 1 > R[a])
continue;
upd(dp[t][mask - (1 << bit)][bit + 1][cnt + 1], dp[t][mask][bit][cnt]);
}
}
FOR(cnt, L[a], R[a] + 1)
upd(dp[nt][mask][0][0], dp[t][mask][k][cnt]);
}
}
cout << dp[ALP % 2][0][0][0] << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 5556kb
input:
2 5 CRANE xx--x NASAL OOxOO
output:
21
result:
ok 1 number(s): "21"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5564kb
input:
1 5 BBBAA xxxx-
output:
995328
result:
wrong answer 1st numbers differ - expected: '0', found: '995328'