QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#769007 | #7006. Rikka with Subsequences | hhoppitree | AC ✓ | 739ms | 4496kb | C++17 | 1.3kb | 2024-11-21 15:42:41 | 2024-11-21 15:42:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 205, P = 1e9 + 7;
void add(int &x, int y) {
((x += y) >= P) && (x -= P);
}
int a[N], b[N][N], f[N][N], sum[N][N];
signed main() {
int T; scanf("%d", &T);
while (T--) {
int n; scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
memset(f, 0, sizeof(f));
for (int i = 1; i <= n; ++i) {
string S; cin >> S;
for (int j = 1; j <= n; ++j) b[i][j] = S[j - 1] - '0';
}
int res = 0;
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k) {
if (!b[a[k]][a[i]]) sum[j][k] = 0;
else sum[j][k] = f[j][k];
add(sum[j][k], sum[j][k - 1]);
add(sum[j][k], sum[j - 1][k]);
add(sum[j][k], P - sum[j - 1][k - 1]);
}
}
for (int j = 1; j <= n; ++j) {
for (int k = 1; k <= n; ++k) {
if (a[i] != a[j] || a[j] != a[k] || a[k] != a[i]) continue;
add(f[j][k], sum[j - 1][k - 1] + 1);
add(res, sum[j - 1][k - 1] + 1);
}
}
}
printf("%d\n", res);
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 4020kb
input:
1 4 1 2 1 2 1111 1111 1111 1111
output:
51
result:
ok single line: '51'
Test #2:
score: 0
Accepted
time: 739ms
memory: 4496kb
input:
20 195 4 5 4 3 2 4 3 5 1 5 4 3 4 3 1 5 4 4 5 2 2 2 2 4 1 5 3 4 1 1 1 2 1 1 5 5 4 5 4 5 5 4 5 2 1 2 5 4 5 1 1 3 1 2 2 3 3 5 2 3 3 1 4 4 2 4 2 4 3 4 1 1 1 4 3 5 1 1 3 2 2 5 1 3 1 5 1 5 5 3 5 3 3 2 5 1 3 2 4 1 5 5 1 3 3 2 4 2 3 3 3 4 1 3 3 3 5 5 1 1 4 2 5 1 2 5 4 3 5 1 5 5 5 4 2 2 5 3 2 3 4 1 3 2 1 5 3...
output:
806298135 541285042 48173297 222851978 875793336 100057791 156057874 129923599 551277543 874547790 544405786 653241411 521317929 370918040 803940504 969296122 806596012 469227084 338962879 194278629
result:
ok 20 lines