Problem p02631 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif

using ll = long long;
/*
    g++ -std=c++11 test.cpp -o test.out && ./test.out
*/
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);

  vector<int> ans;
  int c = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    c ^= a[i];
  }

  for (int i = 0; i < n; i++) {
    c ^= a[i];
    ans.push_back(c);
    c ^= a[i];
  }

  for (int i = 0; i < n; i++)
    cout << ans[i] << " ";
}

const int MOD = 1e9 + 7;

int modpow(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = 1LL * ans * a % MOD;
    a = 1LL * a * a % MOD;
    b >>= 1;
  }
  return ans;
}

ll F[1000005], R[1000005];
void make() {
  F[0] = 1;
  for (int i = 1; i < 1000005; i++)
    F[i] = F[i - 1] * i % MOD;
  for (int i = 0; i < 1000005; i++)
    R[i] = modpow(F[i], MOD - 2);
}

ll sum(ll a, ll b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
  if (a < 0)
    a += MOD;
  return a;
}

ll mul(ll a, ll b) { return a * 1ll * b % MOD; }

ll sub(ll a, ll b) {
  a -= b;
  if (a < 0)
    a += MOD;
  return a;
}

// void solve(){
//     int k; cin >> k;
//     string str; cin >> str;

//     unordered_map<int,int> count;
//     for(int i = 0; i < str.size(); i++){
//         count[str[i] - 'a']++;;
//     }

//     int n = str.size();

// }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  solve();

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\\'' << x << '\\''; }
void __print(const char *x) { cerr << '\\"' << x << '\\"'; }
void __print(const string &x) { cerr << '\\"' << x << '\\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V> void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T> void __print(const T &x) {
  int f = 0;
  cerr << '{';
  for (auto &i : x)
    cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\\n"; }
template <typename T, typename... V> void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v))
    cerr << ", ";
  _print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)                                                            \\
  cerr << "[" << #x << "] = [";                                                \\
  _print(x)
#else
#define debug(x...)
#endif

using ll = long long;
/*
    g++ -std=c++11 test.cpp -o test.out && ./test.out
*/
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);

  vector<int> ans;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = 0; j < n; j++) {
      if (i == j)
        continue;

      c ^= a[j];
      // cout << c << endl;
    }

    ans.push_back(c);
  }

  for (int i = 0; i < n; i++)
    cout << ans[i] << " ";
}

const int MOD = 1e9 + 7;

int modpow(int a, int b) {
  int ans = 1;
  while (b > 0) {
    if (b & 1)
      ans = 1LL * ans * a % MOD;
    a = 1LL * a * a % MOD;
    b >>= 1;
  }
  return ans;
}

ll F[1000005], R[1000005];
void make() {
  F[0] = 1;
  for (int i = 1; i < 1000005; i++)
    F[i] = F[i - 1] * i % MOD;
  for (int i = 0; i < 1000005; i++)
    R[i] = modpow(F[i], MOD - 2);
}

ll sum(ll a, ll b) {
  a += b;
  if (a >= MOD)
    a -= MOD;
  if (a < 0)
    a += MOD;
  return a;
}

ll mul(ll a, ll b) { return a * 1ll * b % MOD; }

ll sub(ll a, ll b) {
  a -= b;
  if (a < 0)
    a += MOD;
  return a;
}

// void solve(){
//     int k; cin >> k;
//     string str; cin >> str;

//     unordered_map<int,int> count;
//     for(int i = 0; i < str.size(); i++){
//         count[str[i] - 'a']++;;
//     }

//     int n = str.size();

// }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  solve();

  return 0;
}