QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#276814#7006. Rikka with Subsequencesucup-team1209#AC ✓243ms71392kbC++202.1kb2023-12-06 11:05:482023-12-06 11:05:48

Judging History

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

  • [2023-12-06 11:05:48]
  • 评测
  • 测评结果:AC
  • 用时:243ms
  • 内存:71392kb
  • [2023-12-06 11:05:48]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin, std::cout;
using u64 = unsigned long long;
const int mod = 1e9 + 7;
const int N = 205;
int n;
void add(int & x, int y) {
	if((x += y) >= mod) {
		x -= mod;
	}
}
void sub(int & x, int y) {
	x -= y, x += x >> 31 & mod;
}
int dp[N][N][N];
int sum[N][N][N];
std::vector<int> v[N];
int pre[N][N];
int a[N];
void clear() {
	memset(dp, 0, sizeof(dp));
	memset(sum, 0, sizeof(sum));
	memset(pre, 0, sizeof(pre));
	for(int i = 0;i < N;++i) v[i].clear();
}
int ok[N][N];
int main() {
	std::ios::sync_with_stdio(false), cin.tie(0);
	int T; cin >> T;
	for(int i = 0;i < T;++i) {
		clear();
		cin >> n;
		for(int i = 1;i <= n;++i) {
			cin >> a[i];
			memcpy(pre[i], pre[i - 1], sizeof(pre[0]));
			if(i > 1) pre[i][a[i - 1]] = i - 1;
		}
		for(int i = 1;i <= n;++i) {
			for(int j = 1;j <= n;++j) {
				char c; cin >> c;
				ok[i][j] = c == '1';
			}
		}
		for(int i = 1;i <= n;++i) {
			for(int j = 1;j < i;++j) {
				if(ok[a[j]][a[i]]) v[i].push_back(a[j]);
			}
			sort(v[i].begin(), v[i].end());
			v[i].erase(unique(v[i].begin(), v[i].end()), v[i].end());
		}
		int ans = 0;
		for(int i = 1;i <= n;++i) {
			for(int j = 1;j <= n;++j) {
				for(int k = 1;k <= n;++k) {
					if(a[i] != a[j]) continue;
					if(a[i] != a[k]) continue;
					if(i <= j && j <= k) {
						int su = 1;
						for(int x : v[i]) {
							add(su, sum[pre[i][x]][pre[j][x]][pre[k][x]]);
						}
						dp[i][j][k] = su;
						dp[i][k][j] = su;
						dp[j][i][k] = su;
						dp[j][k][i] = su;
						dp[k][i][j] = su;
						dp[k][j][i] = su;
					}
					add(ans, dp[i][j][k]);
					sum[i][j][k] = dp[i][j][k];
					int pi = pre[i][a[i]];
					int pj = pre[j][a[j]];
					int pk = pre[k][a[k]];
					add(sum[i][j][k], sum[pi][j][k]);
					add(sum[i][j][k], sum[i][pj][k]);
					add(sum[i][j][k], sum[i][j][pk]);

					sub(sum[i][j][k], sum[pi][pj][k]);
					sub(sum[i][j][k], sum[pi][j][pk]);
					sub(sum[i][j][k], sum[i][pj][pk]);

					add(sum[i][j][k], sum[pi][pj][pk]);
				}
			}
		}
		cout << ans << '\n';
	}
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 71056kb

input:

1
4
1 2 1 2
1111
1111
1111
1111

output:

51

result:

ok single line: '51'

Test #2:

score: 0
Accepted
time: 243ms
memory: 71392kb

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