QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#749934#7006. Rikka with SubsequencesMade_in_CodeAC ✓734ms4320kbC++141.6kb2024-11-15 11:33:522024-11-15 11:33:53

Judging History

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

  • [2024-11-15 11:33:53]
  • 评测
  • 测评结果:AC
  • 用时:734ms
  • 内存:4320kb
  • [2024-11-15 11:33:52]
  • 提交

answer

#include <iostream>
#define LL long long

using namespace std;

const int kMaxN = 201, kMod = 1e9 + 7;
int t, n, a[kMaxN];
LL ans;
LL f[kMaxN][kMaxN];  // 三个子序列分别以 i, j, k 作为开头, 其中 i 一维滚动
LL g[kMaxN][kMaxN];  // 只有 j, k 被转移, i 还在原来的地方, 其中 i 一维滚动
bool e[kMaxN][kMaxN];

int main() {
  cin.tie(0), cout.tie(0);
  ios::sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {
        static char c;
        cin >> c, e[i][j] = c == '1', f[i][j] = g[i][j] = 0;
      }
    }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= n; j++) {  // 对 f_{i-1} 的 j, k 两维做前缀和
        for (int k = 1; k <= n; k++) {
          f[j][k] = (f[j][k] + f[j - 1][k] + f[j][k - 1] - f[j - 1][k - 1] + kMod) % kMod;
        }
      }
      for (int j = 1; j <= n; j++) {  // 将 i-1 加入 g 中, 同时在 i 一维做前缀和
        for (int k = 1; k <= n; k++) {
          if (a[j] == a[k] && e[a[i - 1]][a[j]]) {
            g[j][k] = (g[j][k] + f[j - 1][k - 1]) % kMod;
          }
        }
      }
      for (int j = 1; j <= n; j++) {  // 计算 f_i
        for (int k = 1; k <= n; k++) {
          if (a[i] == a[j] && a[i] == a[k]) {
            f[j][k] = (g[j][k] + 1) % kMod;
            ans = (ans + f[j][k]) % kMod;
          } else {
            f[j][k] = 0;
          }
        }
      }
    }
    cout << ans << '\n', ans = 0;
  }
  return 0;
}

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

詳細信息

Test #1:

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

input:

1
4
1 2 1 2
1111
1111
1111
1111

output:

51

result:

ok single line: '51'

Test #2:

score: 0
Accepted
time: 734ms
memory: 4320kb

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