Cod sursa(job #1783632)
Utilizator | Data | 19 octombrie 2016 10:49:59 | |
---|---|---|---|
Problema | Xor Max | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.63 kb |
#include <fstream>
using namespace std;
ifstream f("xormax.in");
ofstream g("xormax.out");
int n, a[100005], i, j;
int k, kmax, lmax, rmax;
int main() {
f >> n;
for (i = 1; i <= n; i++)
f >> a[i];
for (i = 1; i <= n; i++) {
k = a[i];
for (j = i+1; j <= min(i+25, n); j++) {
k = (k^a[j]);
if (k > kmax) {
kmax = k;
rmax = j, lmax = i;
}
else if (k == kmax && (j-i+1) > rmax-lmax+1)
rmax = j, lmax = i;
}
}
g << kmax << ' ' << lmax << ' ' << rmax;
return 0;
}