QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#631291#7006. Rikka with SubsequencespskkkAC ✓2176ms4216kbC++231.4kb2024-10-11 23:51:382024-10-11 23:51:40

Judging History

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

  • [2024-10-11 23:51:40]
  • 评测
  • 测评结果:AC
  • 用时:2176ms
  • 内存:4216kb
  • [2024-10-11 23:51:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    vector<vector<int>> f(n + 1, vector<int>(n + 1, 0)), s(n + 1, vector<int>(n + 1, 0));
    vector<string> m(n + 1);
    int ans = 0;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 1; i <= n; i++)
        cin >> m[i], reverse(m[i].begin(), m[i].end()), m[i] += ' ', reverse(m[i].begin(), m[i].end());
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                (f[j][k] += ((f[j - 1][k] + f[j][k - 1]) % mod + (mod - f[j - 1][k - 1]) % mod) % mod) %= mod;
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++)
                if (m[a[i - 1]][a[j]] == '1')
                    (s[j][k] += f[j - 1][k - 1]) %= mod;
        for (int j = 1; j <= n; j++)
            for (int k = 1; k <= n; k++) {
                if (a[i] == a[j] && a[i] == a[k])
                    f[j][k] = s[j][k] + 1;
                else
                    f[j][k] = 0;
                (ans += f[j][k]) %= mod;
            }
    }
    cout << ans << '\n';
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3836kb

input:

1
4
1 2 1 2
1111
1111
1111
1111

output:

51

result:

ok single line: '51'

Test #2:

score: 0
Accepted
time: 2176ms
memory: 4216kb

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