C++ 数组染色问题:计算红色和蓝色数字乘积之和
#include
const int mod = 1e9 + 7;
int n, a[100005], red[100005], blue[100005]; long long ans = 0;
int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } string s; cin >> s; for (int i = 1; i <= n; i++) { if (s[i-1] == 'R') { red[++red[0]] = a[i]; } else { blue[++blue[0]] = a[i]; } } for (int i = 1; i <= red[0]; i++) { for (int j = 1; j <= blue[0]; j++) { ans = (ans + red[i] * 1ll * blue[j]) % mod; } } cout << ans << endl; return 0; }
原文地址: https://www.cveoy.top/t/topic/l0zb 著作权归作者所有。请勿转载和采集!