比赛 收心赛 评测结果 AAAAAAAAEEEEAAAAEEEE
题目名称 异或粽子 最终得分 60
用户昵称 赵飞羽 运行时间 1.579 s
代码语言 C++ 内存使用 5.75 MiB
提交时间 2026-02-24 09:37:08
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1010;
int n, k, a[N], s[N], cnt, ans;
priority_queue <int> q;

signed main() {
    freopen("xor.in", "r", stdin);
    freopen("xor.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
	    cin >> a[i];
        s[i] = (a[i] ^ s[i-1]);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = i; j <= n; j++) {
            cnt = (s[j] ^ s[i-1]);
            q.push(cnt);
        }
    }
    for (int i = 1; i <= k; i++) {
        ans += q.top();
        q.pop();
    }
    cout << ans;
	return 0;
}