QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#818412 | #7006. Rikka with Subsequences | SGColin | AC ✓ | 436ms | 4324kb | C++20 | 1.0kb | 2024-12-17 20:06:53 | 2024-12-17 20:07:00 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
constexpr int N = 207;
constexpr int mod = 1000000007;
char M[N][N];
int n, a[N], f[N][N], g[N][N];
inline void add(int &x, int y) {x = (x + y >= mod ? x + y - mod : x + y);}
inline void work() {
ll ans = 0;
scanf("%d", &n);
rep(i, 1, n) scanf("%d", &a[i]);
rep(i, 1, n) scanf("%s", M[i] + 1);
memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
rep(i, 1, n) {
rep(j, 1, n)
rep(k, 1, n) {
f[j][k] = ((a[i] == a[j] && a[i] == a[k]) ? (g[j][k] + 1) : 0);
ans += f[j][k];
}
rep(j, 1, n) rep(k, 1, n) {
add(f[j][k], f[j - 1][k]);
add(f[j][k], f[j][k - 1]);
add(f[j][k], mod - f[j - 1][k - 1]);
}
rep(j, 1, n) rep(k, 1, n)
if (M[a[i]][a[j]] == '1') add(g[j][k], f[j - 1][k - 1]);
}
printf("%lld\n", ans % mod);
}
int main() {
int t;
scanf("%d", &t);
while (t--) work();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4280kb
input:
1 4 1 2 1 2 1111 1111 1111 1111
output:
51
result:
ok single line: '51'
Test #2:
score: 0
Accepted
time: 436ms
memory: 4324kb
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