0分求助
查看原帖
0分求助
1121748
PYM20111102楼主2024/10/23 17:39
#include <bits/stdc++.h>
using namespace std;
int n, m;
int number[100005], color[100005];
long long tot;

int f(int x, int y, int z) {
    if (color[x] == color[z] && y - x == z - y) {
        int first = (x + z) % 10007;
        int second = (number[x] + number[z]) % 10007;
        tot += first * second;
    }
    if (x == n - 2 && y == n - 1 && z == n) return tot;
    else if (y == n - 1 && z == n) return f(x + 1, x + 2, x + 3);
    else if (z == n) return f(x, y + 1, y + 2);
    return f(x, y, z + 1);
}

int main(){
	cin >> n >> m;
	for (int i = 1; i <= n; i ++) {
        cin >> number[i];
	}
    for (int i = 1; i <= n; i ++) {
        cin >> color[i];
	}
	cout << f(1, 2, 3);
	return 0;
}

样例过

2024/10/23 17:39
加载中...