1457D - XOR-gun - CodeForces Solution


brute force constructive algorithms dp *2000

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

using namespace std;

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef LOCAL
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

#define ar array
#define ll long long
#define ld long double
#define sza(x) ((int)x.size())
#define all(a) (a).begin(), (a).end()

const int MAX_N = 2e5 + 5;
const ll MOD =  998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;

ll inv(ll a) {
  return a <= 1 ? a : MOD - (long long)(MOD/a) * inv(MOD % a) % MOD;
}

void solve()
{
    ll n;cin>>n;
    vector<ll> a(n);
    for(ll i=0;i<n;i++)
    cin>>a[i];
    if(n>=100)
    {
        cout << "1\n";
        return;
    }
    ll ans = 1e9;
    for(ll i=0;i<n;i++)
    {
        ll t1=0,t2=0;
        for(ll j=i+1;j<n;j++)
        {
            t1^=a[j];
            t2=0;
            for(ll k=i;k>=0;k--)
            {
                t2^=a[k];
                if(t2>t1)
                {
                    ans=min(ans,j-k-1);
                }
            }
        }
    }

    if(ans==1e9)
    cout << -1 << "\n";
    else
    cout << ans << "\n";

    return; 
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int tc=1 ;
    // cin >> tc;
    for (int t = 1; t <= tc; t++) {
                //    cout << "Case #" << t << ": ";
        solve();
    }
}


Comments

Submit
0 Comments
More Questions

32B - Borze
1651B - Prove Him Wrong
381A - Sereja and Dima
41A - Translation
1559A - Mocha and Math
832A - Sasha and Sticks
292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols
1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General
1106A - Lunar New Year and Cross Counting
58A - Chat room