Datasets:

problem_id
stringlengths
6
6
buggy_code
stringlengths
8
526k
fixed_code
stringlengths
12
526k
labels
listlengths
0
15
buggy_submission_id
int64
1
1.54M
fixed_submission_id
int64
2
1.54M
user_id
stringlengths
10
10
language
stringclasses
9 values
p03138
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define req(i, n) for (int i = 1; i <= n; i++) #define rreq(i, n) for (ll i = n; i >= 1; i--) #define ALL(obj) begin(obj), end(obj) #define RALL(a) rbegin(a), rend(a) typedef long long int ll; typedef long double ld; const ll INF = 1e18; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } const int MOD = 1e9 + 7; int main(void) { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll val = 0; rep(i, 40) { int set = 0; rep(j, n) { if ((a[j] >> i) & 1) set++; } if (n - set > set && val + (1LL << i) <= k) val += (1LL << i); } ll ans = 0; rep(i, n) { ans += (a[i] ^ val); } cout << ans << endl; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <vector> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define req(i, n) for (int i = 1; i <= n; i++) #define rrep(i, n) for (ll i = n - 1; i >= 0; i--) #define ALL(obj) begin(obj), end(obj) #define RALL(a) rbegin(a), rend(a) typedef long long int ll; typedef long double ld; const ll INF = 1e18; template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); } const int MOD = 1e9 + 7; int main(void) { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll val = 0; rrep(i, 41) { int set = 0; rep(j, n) { if ((a[j] >> i) & 1) set++; } if (n - set > set && val + (1LL << i) <= k) val += (1LL << i); } ll ans = 0; rep(i, n) { ans += (a[i] ^ val); } cout << ans << endl; }
[ "identifier.change", "preprocessor.define.value.change", "literal.integer.change", "call.function.change", "literal.number.change", "call.arguments.change" ]
939,465
939,466
u670898337
cpp
p03138
#include <algorithm> #include <assert.h> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> // #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr long long int INFLL = 1001001001001001LL; constexpr long long int infll = 1001001001001001LL; constexpr int INF = 1000000007; constexpr int inf = 1000000007; const int mod = 1000000007; inline bool chmin(ll &a, ll b) { if (a > b) { a = b; return true; } return false; } inline bool chmax(ll &a, ll b) { if (a < b) { a = b; return true; } return false; } template <typename T> T seinomi(T a) { if (a > 0) { return a; } else { return 0; } } //桁数取得 template <typename T> T ketasuu(T num) { return std::to_string(num).length(); } //整数乗 ll llpow(ll a, ll n) { if (n == 0) { return 1; } else { ll rep = a; for (ll i = 1; i < n; i++) { rep *= a; } return rep; } } template <class ForwardIt, class T> void iota(ForwardIt first, ForwardIt last, T value) { while (first != last) { *first++ = value; ++value; } } template <typename T> T amarinasi(T a, T b) { if (a % b == 0) { return a / b; } else if (a % b > 0) { return a / b + 1; } else { return a / b - 1; } } //小数点以下10桁テンプレート(main関数内の最初に貼付け) // std::cout << std::fixed << std::setprecision(10); //---------------------------------------------------------------- const double pi = 3.14159265358979323846264; //進数変換 class base_convert { private: const char *s; int a[128]; public: base_convert(const char *s = "0123456789ABCDEF") : s(s) { int i; for (i = 0; s[i]; ++i) a[(int)s[i]] = i; } std::string to(long long p, int q) { int i; if (!p) return "0"; char t[64] = {}; for (i = 62; p; --i) { t[i] = s[p % q]; p /= q; } return std::string(t + i + 1); } std::string to(const std::string &t, int p, int q) { return to(to(t, p), q); } long long to(const std::string &t, int p) { int i; long long sm = a[(int)t[0]]; for (i = 1; i < (int)t.length(); ++i) sm = sm * p + a[(int)t[i]]; return sm; } }; base_convert bc; ll xor1(ll n, ll k, vector<ll> a) { if (k == 0) { ll tmp_sum = 0; for (ll i = 0; i < n; i++) { tmp_sum += a[i]; } return tmp_sum; } else if (k == 1) { ll tmp_sum = 0; for (ll i = 0; i < n; i++) { tmp_sum += a[i]; } ll tmp_sum2 = 0; for (ll i = 0; i < n; i++) { tmp_sum2 += 1 ^ a[i]; } return max(tmp_sum, tmp_sum2); } else { map<ll, ll> rensou; ll max_size = 0; for (ll i = 0; i < n; i++) { string tmp = bc.to(a[i], 2); chmax(max_size, tmp.size()); for (ll i = 0; i < tmp.size(); i++) { if (tmp[tmp.size() - 1 - i] == '1') { rensou[i]++; } } } ll ans = 0; for (ll i = 0; i < 40; i++) { ll mask1 = (1LL << i); if (!(k & mask1)) { continue; } ll sum = 0; for (ll j = 0; j < i; j++) { if (rensou[j] > n / 2) { sum += llpow(2, j) * rensou[j]; } else { sum += llpow(2, j) * (n - rensou[j]); } } sum += llpow(2, i) * rensou[i]; for (ll j = i + 1; j < 40; j++) { ll mask2 = (1LL << j); if (k & mask2) { sum += llpow(2, j) * (n - rensou[j]); } else { sum += llpow(2, j) * rensou[j]; } } chmax(ans, sum); } return ans; } } ll xor2(ll n, ll k, vector<ll> a) { ll sum = 0; for (ll i = 0; i <= k; i++) { ll tmp = 0; for (ll j = 0; j < n; j++) { tmp += a[j] ^ i; } chmax(sum, tmp); } return sum; } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } /*if (xor1(n, k, a) != xor2(n, k, a)) { cout << "!!!" << endl; cout << xor1(n, k, a) << endl; cout << xor2(n, k, a) << endl; } */ cout << xor1(n, k, a) << endl; }
#include <algorithm> #include <assert.h> #include <bitset> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <set> #include <vector> // #include<bits/stdc++.h> using namespace std; typedef long long ll; constexpr long long int INFLL = 1001001001001001LL; constexpr long long int infll = 1001001001001001LL; constexpr int INF = 1000000007; constexpr int inf = 1000000007; const int mod = 1000000007; inline bool chmin(ll &a, ll b) { if (a > b) { a = b; return true; } return false; } inline bool chmax(ll &a, ll b) { if (a < b) { a = b; return true; } return false; } template <typename T> T seinomi(T a) { if (a > 0) { return a; } else { return 0; } } //桁数取得 template <typename T> T ketasuu(T num) { return std::to_string(num).length(); } //整数乗 ll llpow(ll a, ll n) { if (n == 0) { return 1; } else { ll rep = a; for (ll i = 1; i < n; i++) { rep *= a; } return rep; } } template <class ForwardIt, class T> void iota(ForwardIt first, ForwardIt last, T value) { while (first != last) { *first++ = value; ++value; } } template <typename T> T amarinasi(T a, T b) { if (a % b == 0) { return a / b; } else if (a % b > 0) { return a / b + 1; } else { return a / b - 1; } } //小数点以下10桁テンプレート(main関数内の最初に貼付け) // std::cout << std::fixed << std::setprecision(10); //---------------------------------------------------------------- const double pi = 3.14159265358979323846264; //進数変換 class base_convert { private: const char *s; int a[128]; public: base_convert(const char *s = "0123456789ABCDEF") : s(s) { int i; for (i = 0; s[i]; ++i) a[(int)s[i]] = i; } std::string to(long long p, int q) { int i; if (!p) return "0"; char t[64] = {}; for (i = 62; p; --i) { t[i] = s[p % q]; p /= q; } return std::string(t + i + 1); } std::string to(const std::string &t, int p, int q) { return to(to(t, p), q); } long long to(const std::string &t, int p) { int i; long long sm = a[(int)t[0]]; for (i = 1; i < (int)t.length(); ++i) sm = sm * p + a[(int)t[i]]; return sm; } }; base_convert bc; ll xor1(ll n, ll k, vector<ll> a) { if (k == 0) { ll tmp_sum = 0; for (ll i = 0; i < n; i++) { tmp_sum += a[i]; } return tmp_sum; } else if (k == 1) { ll tmp_sum = 0; for (ll i = 0; i < n; i++) { tmp_sum += a[i]; } ll tmp_sum2 = 0; for (ll i = 0; i < n; i++) { tmp_sum2 += 1 ^ a[i]; } return max(tmp_sum, tmp_sum2); } else { k++; map<ll, ll> rensou; ll max_size = 0; for (ll i = 0; i < n; i++) { string tmp = bc.to(a[i], 2); chmax(max_size, tmp.size()); for (ll i = 0; i < tmp.size(); i++) { if (tmp[tmp.size() - 1 - i] == '1') { rensou[i]++; } } } ll ans = 0; for (ll i = 0; i < 40; i++) { ll mask1 = (1LL << i); if (!(k & mask1)) { continue; } ll sum = 0; for (ll j = 0; j < i; j++) { if (rensou[j] > n / 2) { sum += llpow(2, j) * rensou[j]; } else { sum += llpow(2, j) * (n - rensou[j]); } } sum += llpow(2, i) * rensou[i]; for (ll j = i + 1; j < 40; j++) { ll mask2 = (1LL << j); if (k & mask2) { sum += llpow(2, j) * (n - rensou[j]); } else { sum += llpow(2, j) * rensou[j]; } } chmax(ans, sum); } return ans; } } ll xor2(ll n, ll k, vector<ll> a) { ll sum = 0; for (ll i = 0; i <= k; i++) { ll tmp = 0; for (ll j = 0; j < n; j++) { tmp += a[j] ^ i; } chmax(sum, tmp); } return sum; } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; } /*if (xor1(n, k, a) != xor2(n, k, a)) { cout << "!!!" << endl; cout << xor1(n, k, a) << endl; cout << xor2(n, k, a) << endl; }*/ cout << xor1(n, k, a) << endl; }
[ "expression.unary.arithmetic.add" ]
939,467
939,468
u863537799
cpp
p03138
#include "bits/stdc++.h" using namespace std; long long dp[101][2]; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (int n = 0; n < N; ++n) { cin >> A[n]; } for (int n = 0; n < 101; ++n) { dp[n][0] = dp[n][1] = -1; } dp[0][0] = 0; for (int n = 0; n < 100; ++n) { long long mask = 1LL << (99 - n); long long count = 0; for (int i = 0; i < N; ++i) { if (A[i] & mask) { count++; } } if (dp[n][1] >= 0) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][1] + mask * max(count, N - count)); } if (dp[n][0] >= 0) { if (K & mask) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + mask * count); dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * (N - count)); } else { dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * count); } } } cout << max(dp[100][0], dp[100][1]) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; long long dp[101][2]; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (int n = 0; n < N; ++n) { cin >> A[n]; } for (int n = 0; n < 101; ++n) { dp[n][0] = dp[n][1] = -1; } dp[0][0] = 0; for (int n = 0; n < 40; ++n) { long long mask = 1LL << (39 - n); long long count = 0; for (int i = 0; i < N; ++i) { if (A[i] & mask) { count++; } } if (dp[n][1] >= 0) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][1] + mask * max(count, N - count)); } if (dp[n][0] >= 0) { if (K & mask) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + mask * count); dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * (N - count)); } else { dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * count); } } } cout << max(dp[40][0], dp[40][1]) << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "variable_access.subscript.index.change", "io.output.change" ]
939,485
939,486
u835523614
cpp
p03138
#include "bits/stdc++.h" using namespace std; long long dp[101][2]; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (int n = 0; n < N; ++n) { cin >> A[n]; } for (int n = 0; n < 101; ++n) { dp[n][0] = dp[n][1] = -1; } dp[0][0] = 0; for (int n = 0; n < 100; ++n) { long long mask = 1LL << (99 - n); long long count = 0; for (int i = 0; i < N; ++i) { if (A[i] & mask) { count++; } } if (dp[n][1] >= 0) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][1] + mask * max(count, N - count)); } if (dp[n][0] >= 0) { if (K & mask) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + mask * count); dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * (N - count)); } else { dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * count); } } } cout << max(dp[100][0], dp[100][1]) << endl; return 0; }
#include "bits/stdc++.h" using namespace std; long long dp[101][2]; int main() { long long N, K; cin >> N >> K; vector<long long> A(N); for (int n = 0; n < N; ++n) { cin >> A[n]; } for (int n = 0; n < 101; ++n) { dp[n][0] = dp[n][1] = -1; } dp[0][0] = 0; for (int n = 0; n < 45; ++n) { long long mask = 1LL << (44 - n); long long count = 0; for (int i = 0; i < N; ++i) { if (A[i] & mask) { count++; } } if (dp[n][1] >= 0) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][1] + mask * max(count, N - count)); } if (dp[n][0] >= 0) { if (K & mask) { dp[n + 1][1] = max(dp[n + 1][1], dp[n][0] + mask * count); dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * (N - count)); } else { dp[n + 1][0] = max(dp[n + 1][0], dp[n][0] + mask * count); } } } cout << max(dp[45][0], dp[45][1]) << endl; return 0; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "variable_access.subscript.index.change", "io.output.change" ]
939,485
939,488
u835523614
cpp
p03138
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; const long long MOD = 1000000007; ll N, K, M; ll A[100010]; ll cnt[100], K2[100], pow2[100]; ll dp[100][2]; ll solve() { ll ret = 0; for (int i = 64; i >= 0; i--) { dp[i][0] = dp[i + 1][0] + K2[i] * (N - cnt[i]) * pow2[i] + (1 - K2[i]) * cnt[i] * pow2[i]; if (i < M) { dp[i][1] = dp[i + 1][1] + max(cnt[i], N - cnt[i]) * pow2[i]; if (K2[i] == 1) dp[i][1] = max(dp[i][1], dp[i + 1][0] + (N - cnt[i]) * pow2[i]); } } return max(dp[0][0], dp[0][1]); } signed main() { cin >> N >> K; REP(i, N) cin >> A[i]; REP(i, 64) { REP(j, N) { if (A[j] % 2 == 1) cnt[i]++; A[j] /= 2; } if (K % 2 == 1) { K2[i] = 1; M = i; } K /= 2; } pow2[0] = 1; REP(i, 64) pow2[i + 1] = pow2[i] * 2; PRINT(solve()); return 0; }
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; const long long MOD = 1000000007; ll N, K, M; ll A[100010]; ll cnt[100], K2[100], pow2[100]; ll dp[100][2]; ll solve() { ll ret = 0; for (int i = 64; i >= 0; i--) { dp[i][0] = dp[i + 1][0] + K2[i] * (N - cnt[i]) * pow2[i] + (1 - K2[i]) * cnt[i] * pow2[i]; if (i < M) dp[i][1] = dp[i + 1][1] + max(cnt[i], N - cnt[i]) * pow2[i]; if (K2[i] == 1) dp[i][1] = max(dp[i][1], dp[i + 1][0] + cnt[i] * pow2[i]); } return max(dp[0][0], dp[0][1]); } signed main() { cin >> N >> K; REP(i, N) cin >> A[i]; REP(i, 64) { REP(j, N) { if (A[j] % 2 == 1) cnt[i]++; A[j] /= 2; } if (K % 2 == 1) { K2[i] = 1; M = i; } K /= 2; } pow2[0] = 1; REP(i, 64) pow2[i + 1] = pow2[i] * 2; PRINT(solve()); return 0; }
[ "call.arguments.change" ]
939,489
939,490
u569690172
cpp
p03138
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; const long long MOD = 1000000007; ll N, K, M; ll A[100010]; ll cnt[100], K2[100], pow2[100]; ll dp[100][2]; ll solve() { ll ret = 0; for (int i = 64; i >= 0; i--) { dp[i][0] = dp[i + 1][0] + K2[i] * (N - cnt[i]) * pow2[i] + (1 - K2[i]) * cnt[i] * pow2[i]; if (i < M) dp[i][1] = dp[i + 1][1] + max(cnt[i], N - cnt[i]) * pow2[i]; if (K2[i] == 1) dp[i][1] = max(dp[i][1], dp[i + 1][0] + (N - cnt[i]) * pow2[i]); } return max(dp[0][0], dp[0][1]); } signed main() { cin >> N >> K; REP(i, N) cin >> A[i]; REP(i, 64) { REP(j, N) { if (A[j] % 2 == 1) cnt[i]++; A[j] /= 2; } if (K % 2 == 1) { K2[i] = 1; M = i; } K /= 2; } pow2[0] = 1; REP(i, 64) pow2[i + 1] = pow2[i] * 2; PRINT(solve()); return 0; }
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; const long long MOD = 1000000007; ll N, K, M; ll A[100010]; ll cnt[100], K2[100], pow2[100]; ll dp[100][2]; ll solve() { ll ret = 0; for (int i = 64; i >= 0; i--) { dp[i][0] = dp[i + 1][0] + K2[i] * (N - cnt[i]) * pow2[i] + (1 - K2[i]) * cnt[i] * pow2[i]; if (i < M) dp[i][1] = dp[i + 1][1] + max(cnt[i], N - cnt[i]) * pow2[i]; if (K2[i] == 1) dp[i][1] = max(dp[i][1], dp[i + 1][0] + cnt[i] * pow2[i]); } return max(dp[0][0], dp[0][1]); } signed main() { cin >> N >> K; REP(i, N) cin >> A[i]; REP(i, 64) { REP(j, N) { if (A[j] % 2 == 1) cnt[i]++; A[j] /= 2; } if (K % 2 == 1) { K2[i] = 1; M = i; } K /= 2; } pow2[0] = 1; REP(i, 64) pow2[i + 1] = pow2[i] * 2; PRINT(solve()); return 0; }
[ "call.arguments.change" ]
939,491
939,490
u569690172
cpp
p03138
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; const long long MOD = 1000000007; ll N, K, M; ll A[100010]; ll cnt[100], K2[100], pow2[100]; ll dp[100][2]; ll solve() { ll ret = 0; for (int i = 64; i >= 0; i--) { dp[i][0] = dp[i + 1][0] + K2[i] * (N - cnt[i]) * pow2[i] + (1 - K2[i]) * cnt[i] * pow2[i]; if (i <= M) dp[i][1] = dp[i + 1][1] + max(cnt[i], N - cnt[i]) * pow2[i]; if (K2[i] == 1) dp[i][1] = max(dp[i][1], dp[i + 1][0] + (N - cnt[i]) * pow2[i]); } return max(dp[0][0], dp[0][1]); } signed main() { cin >> N >> K; REP(i, N) cin >> A[i]; REP(i, 64) { REP(j, N) { if (A[j] % 2 == 1) cnt[i]++; A[j] /= 2; } if (K % 2 == 1) { K2[i] = 1; M = i; } K /= 2; } pow2[0] = 1; REP(i, 64) pow2[i + 1] = pow2[i] * 2; PRINT(solve()); return 0; }
#include <bits/stdc++.h> #define REP(i, e) for (int(i) = 0; (i) < (e); ++(i)) #define FOR(i, b, e) for (int(i) = (b); (i) < (e); ++(i)) #define ALL(c) (c).begin(), (c).end() #define PRINT(x) cout << (x) << "\n" using namespace std; using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>; const long long MOD = 1000000007; ll N, K, M; ll A[100010]; ll cnt[100], K2[100], pow2[100]; ll dp[100][2]; ll solve() { ll ret = 0; for (int i = 64; i >= 0; i--) { dp[i][0] = dp[i + 1][0] + K2[i] * (N - cnt[i]) * pow2[i] + (1 - K2[i]) * cnt[i] * pow2[i]; if (i < M) dp[i][1] = dp[i + 1][1] + max(cnt[i], N - cnt[i]) * pow2[i]; if (K2[i] == 1) dp[i][1] = max(dp[i][1], dp[i + 1][0] + cnt[i] * pow2[i]); } return max(dp[0][0], dp[0][1]); } signed main() { cin >> N >> K; REP(i, N) cin >> A[i]; REP(i, 64) { REP(j, N) { if (A[j] % 2 == 1) cnt[i]++; A[j] /= 2; } if (K % 2 == 1) { K2[i] = 1; M = i; } K /= 2; } pow2[0] = 1; REP(i, 64) pow2[i + 1] = pow2[i] * 2; PRINT(solve()); return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "call.arguments.change" ]
939,492
939,490
u569690172
cpp
p03138
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; #define INF __INT32_MAX__ void chmax(ll &x, ll y) { if (x < y) x = y; } int main() { ll N, K; cin >> N >> K; vl A(N); rep(i, N) { cin >> A[i]; } const int DIGIT_MAX = 50; vector<vector<ll>> dp(DIGIT_MAX + 1, vector<ll>(2, -1)); dp[0][0] = 0; for (int d = 0; d < DIGIT_MAX; d++) { ll mask = 1LL << (DIGIT_MAX - 1 - d); ll num = 0; for (int i = 0; i < N; i++) { if (A[i] & mask) num++; } ll cost0 = mask * num; ll cost1 = mask * (N - num); if (dp[d][0] != -1) { if (K & mask) { chmax(dp[d + 1][0], dp[d][0] + cost1); } else { chmax(dp[d + 1][0], dp[d][0] + cost0); } } if (dp[d][0] != -1) { if (K & mask) { chmax(dp[d + 1][1], dp[d][0] + cost1); } } if (dp[d][1] != -1) { chmax(dp[d + 1][1], dp[d][1] + max(cost0, cost1)); } } cout << max(dp[DIGIT_MAX][0], dp[DIGIT_MAX][1]) << endl; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); i++) using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<long long> vl; #define INF __INT32_MAX__ void chmax(ll &x, ll y) { if (x < y) x = y; } int main() { ll N, K; cin >> N >> K; vl A(N); rep(i, N) { cin >> A[i]; } const int DIGIT_MAX = 50; vector<vector<ll>> dp(DIGIT_MAX + 1, vector<ll>(2, -1)); dp[0][0] = 0; for (int d = 0; d < DIGIT_MAX; d++) { ll mask = 1LL << (DIGIT_MAX - 1 - d); ll num = 0; for (int i = 0; i < N; i++) { if (A[i] & mask) num++; } ll cost0 = mask * num; ll cost1 = mask * (N - num); if (dp[d][0] != -1) { if (K & mask) { chmax(dp[d + 1][0], dp[d][0] + cost1); } else { chmax(dp[d + 1][0], dp[d][0] + cost0); } } if (dp[d][0] != -1) { if (K & mask) { chmax(dp[d + 1][1], dp[d][0] + cost0); } } if (dp[d][1] != -1) { chmax(dp[d + 1][1], dp[d][1] + max(cost0, cost1)); } } cout << max(dp[DIGIT_MAX][0], dp[DIGIT_MAX][1]) << endl; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
939,493
939,494
u376366206
cpp
p03138
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, 0, N) cin >> A[i]; ll cnt[60] = {}; REP(i, 0, N) { ll tmp = A[i]; REP(j, 0, 60) { cnt[j] += tmp & 1; tmp >>= 1; } } ll sum[61] = {}; REP(i, 1, 61) { sum[i] = sum[i - 1] + (1LL << (i - 1)) * max(cnt[0], N - cnt[0]); } // REP(i, 0, 10) cout << sum[i] << " "; // cout << endl; ll ans = 0, cur = 0; for (int i = 59; i >= 0; i--) { if (K & (1LL << i)) { ans = max(ans, cur + cnt[i] * (1LL << i) + sum[i]); cur += (1LL << i) * (N - cnt[i]); } else { cur += (1LL << i) * cnt[i]; } } ans = max(ans, cur); cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define REP(i, s, n) for (int i = s; i < (int)(n); i++) #define ALL(a) a.begin(), a.end() #define MOD 1000000007 using namespace std; using ll = long long; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, 0, N) cin >> A[i]; ll cnt[60] = {}; REP(i, 0, N) { ll tmp = A[i]; REP(j, 0, 60) { cnt[j] += tmp & 1; tmp >>= 1; } } ll sum[61] = {}; REP(i, 1, 61) { sum[i] = sum[i - 1] + (1LL << (i - 1)) * max(cnt[i - 1], N - cnt[i - 1]); } // REP(i, 0, 10) cout << sum[i] << " "; // cout << endl; ll ans = 0, cur = 0; for (int i = 59; i >= 0; i--) { if (K & (1LL << i)) { ans = max(ans, cur + cnt[i] * (1LL << i) + sum[i]); cur += (1LL << i) * (N - cnt[i]); } else { cur += (1LL << i) * cnt[i]; } } ans = max(ans, cur); cout << ans << endl; return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change", "assignment.change" ]
939,509
939,510
u483992368
cpp
p03138
#include <bits/stdc++.h> using namespace std; const int MAX_BIT = 50; int main() { long long n, k, dp[MAX_BIT + 1][2], c[MAX_BIT + 1]; cin >> n >> k; memset(c, 0, sizeof(c)); memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) { long long a; cin >> a; for (int j = 0; j <= MAX_BIT; j++) { if ((a >> j) & 1) c[j]++; } } dp[0][0] = 0; dp[0][1] = 0; for (int i = 1; i <= MAX_BIT; i++) { if (dp[i - 1][0] == 0) { if (k >> (MAX_BIT - i) & 1) { dp[i][0] = c[MAX_BIT - i]; dp[i][1] = (dp[i - 1][1] << 1) + n - c[MAX_BIT - i]; } else { dp[i][1] = (dp[i - 1][1] << 1) + c[MAX_BIT - i]; } } else { dp[i][0] = max(dp[i][0], (dp[i - 1][0] << 1) + c[MAX_BIT - i]); dp[i][0] = max(dp[i][0], (dp[i - 1][0] << 1) + n - c[MAX_BIT - i]); if (k >> (MAX_BIT - i) & 1) { dp[i][0] = max(dp[i][0], (dp[i - 1][1] << 1) + c[MAX_BIT - i]); dp[i][1] = (dp[i - 1][1] << 1) + c[MAX_BIT - i]; } else { dp[i][1] = (dp[i - 1][1] << 1) + (n - c[MAX_BIT - i]); } } } cout << max(dp[MAX_BIT][1], dp[MAX_BIT][0]) << endl; }
#include <bits/stdc++.h> using namespace std; const int MAX_BIT = 50; int main() { long long n, k, dp[MAX_BIT + 1][2], c[MAX_BIT + 1]; cin >> n >> k; memset(c, 0, sizeof(c)); memset(dp, 0, sizeof(dp)); for (int i = 0; i < n; i++) { long long a; cin >> a; for (int j = 0; j <= MAX_BIT; j++) { if ((a >> j) & 1) c[j]++; } } dp[0][0] = 0; dp[0][1] = 0; for (int i = 1; i <= MAX_BIT; i++) { if (dp[i - 1][0] == 0) { if (k >> (MAX_BIT - i) & 1) { dp[i][0] = c[MAX_BIT - i]; dp[i][1] = (dp[i - 1][1] << 1) + n - c[MAX_BIT - i]; } else { dp[i][1] = (dp[i - 1][1] << 1) + c[MAX_BIT - i]; } } else { dp[i][0] = max(dp[i][0], (dp[i - 1][0] << 1) + c[MAX_BIT - i]); dp[i][0] = max(dp[i][0], (dp[i - 1][0] << 1) + n - c[MAX_BIT - i]); if (k >> (MAX_BIT - i) & 1) { dp[i][0] = max(dp[i][0], (dp[i - 1][1] << 1) + c[MAX_BIT - i]); dp[i][1] = (dp[i - 1][1] << 1) + n - c[MAX_BIT - i]; } else { dp[i][1] = (dp[i - 1][1] << 1) + (c[MAX_BIT - i]); } } } cout << max(dp[MAX_BIT][1], dp[MAX_BIT][0]) << endl; }
[ "assignment.change", "expression.operation.binary.remove" ]
939,511
939,512
u112318601
cpp
p03138
#include <bits/stdc++.h> // #undef DEBUG // Uncomment this line to forcefully disable debug print. #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T &value, Ts &...args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T &value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T &value, const Ts &...args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; // 001 // 110 // 011 // 11 int main() { in(ll, n, k); vector<ll> a(n); rep(i, n) cin >> a[i]; ll bit = 1, shifts = 0; while ((bit << 1) <= k) { bit <<= 1; ++shifts; } vector<int> cnt(shifts + 1); rep(i, n) rep(j, shifts) if ((a[i] >> j) & 1)++ cnt[j]; ll x = 0; for (int i = shifts; i >= 0; --i) { if ((x | (1LL << i)) > k) continue; if (cnt[i] < (n - cnt[i])) x |= (1LL << i); } dbg(x); ll ans = 0; for (ll ai : a) ans += ai ^ x; out(ans); }
#include <bits/stdc++.h> // #undef DEBUG // Uncomment this line to forcefully disable debug print. #if DEBUG template <typename T> void debug(T value) { std::cerr << value; } template <typename T, typename... Ts> void debug(T value, Ts... args) { std::cerr << value << ", "; debug(args...); } #define dbg(...) \ do { \ cerr << #__VA_ARGS__ << ": "; \ debug(__VA_ARGS__); \ cerr << " (L" << __LINE__ << ")" << endl; \ } while (0) #else #define dbg(...) #endif void read_from_cin() {} template <typename T, typename... Ts> void read_from_cin(T &value, Ts &...args) { std::cin >> value; read_from_cin(args...); } #define in(type, ...) \ type __VA_ARGS__; \ read_from_cin(__VA_ARGS__); template <typename T> void write_to_cout(const T &value) { std::cout << value << std::endl; } template <typename T, typename... Ts> void write_to_cout(const T &value, const Ts &...args) { std::cout << value << ' '; write_to_cout(args...); } #define out(...) write_to_cout(__VA_ARGS__); #define all(x) (x).begin(), (x).end() #define rep(i, n) for (int i = 0; i < (int)(n); ++i) using ll = long long; using namespace std; // 001 // 110 // 011 // 11 int main() { in(ll, n, k); vector<ll> a(n); rep(i, n) cin >> a[i]; ll bit = 1, shifts = 0; while ((bit << 1) <= k) { bit <<= 1; ++shifts; } vector<int> cnt(shifts + 1); rep(i, n) rep(j, shifts + 1) if ((a[i] >> j) & 1)++ cnt[j]; ll x = 0; for (int i = shifts; i >= 0; --i) { if ((x | (1LL << i)) > k) continue; if (cnt[i] < (n - cnt[i])) x |= (1LL << i); } dbg(x); ll ans = 0; for (ll ai : a) ans += ai ^ x; out(ans); }
[ "expression.operation.binary.add" ]
939,513
939,514
u505122009
cpp
p03138
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) long long mo = 1e9 + 7; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; template <class T, class S> void cmin(T &a, const S &b) { if (a > b) a = b; } template <class T, class S> void cmax(T &a, const S &b) { if (a < b) a = b; } template <class A> void PR(A a, ll n) { rep(i, n) { if (i) cout << ' '; cout << a[i]; } cout << "\n"; } ld PI = 3.14159265358979323846; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } ll X = 0; for (ll i = 40; i >= 0; i--) { X += (1LL << i); if (X > K) { X -= (1LL << i); continue; } ll cnt = 0; rep(j, N) { if ((A[i] >> i) & 1LL) cnt++; } if (cnt > N / 2) { X -= (1LL << i); } } ll ans = 0; rep(i, N) { ans += (X ^ A[i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < n; i++) #define REP(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++) long long mo = 1e9 + 7; typedef long long ll; typedef long double ld; typedef pair<int, int> Pii; typedef pair<ll, ll> Pll; template <class T, class S> void cmin(T &a, const S &b) { if (a > b) a = b; } template <class T, class S> void cmax(T &a, const S &b) { if (a < b) a = b; } template <class A> void PR(A a, ll n) { rep(i, n) { if (i) cout << ' '; cout << a[i]; } cout << "\n"; } ld PI = 3.14159265358979323846; int main() { ll N, K; cin >> N >> K; vector<ll> A(N); rep(i, N) { cin >> A[i]; } ll X = 0; for (ll i = 40; i >= 0; i--) { X += (1LL << i); if (X > K) { X -= (1LL << i); continue; } ll cnt = 0; rep(j, N) { if ((A[j] >> i) & 1LL) cnt++; } if (cnt > N / 2) { X -= (1LL << i); } } ll ans = 0; rep(i, N) { ans += (X ^ A[i]); } cout << ans << endl; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
939,515
939,516
u601256797
cpp
p03138
#include <bits/stdc++.h> using namespace std; /*{{{*/ // template #define rep(i, n) for (int i = 0; i < (int)(n); i++) constexpr int INF = numeric_limits<int>::max() / 2; constexpr long long LINF = numeric_limits<long long>::max() / 3; #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define all(v) (v).begin(), (v).end() #define sz(x) (int)(x).size() #define debug(x) cerr << #x << ":" << x << endl #define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl // struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_; struct Double { double d; explicit Double(double x) : d(x) {} }; ostream &operator<<(ostream &os, const Double x) { os << fixed << setprecision(20) << x.d; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { os << "{"; for (T v : st) os << v << ","; os << "}"; return os; } template <typename T, typename U> inline void chmax(T &x, U y) { if (y > x) x = y; } template <typename T, typename U> inline void chmin(T &x, U y) { if (y < x) x = y; } typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } // constexpr double eps = 1e-14; constexpr double eps = 1e-10; constexpr ll mod = 1e9 + 7; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; /*}}}*/ int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; bool miman = false; ll x = 0; for (int i = 62; i >= 0; i--) { if (miman || (k & (1ll << i))) { int one = 0; rep(j, n) { if (a[i] & (1ll << i)) { one++; } } int zero = n - one; if (zero > one) { // oneにする x |= (1ll << i); } else { // zeroにする if (k & (1ll << i)) { miman = true; } } } } // cout << x << endl; assert(x <= k); ll ans = 0; for (int i = 0; i < n; i++) { ans += (x ^ a[i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; /*{{{*/ // template #define rep(i, n) for (int i = 0; i < (int)(n); i++) constexpr int INF = numeric_limits<int>::max() / 2; constexpr long long LINF = numeric_limits<long long>::max() / 3; #define mp make_pair #define pb push_back #define eb emplace_back #define fi first #define se second #define all(v) (v).begin(), (v).end() #define sz(x) (int)(x).size() #define debug(x) cerr << #x << ":" << x << endl #define debug2(x, y) cerr << #x << "," << #y ":" << x << "," << y << endl // struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_; struct Double { double d; explicit Double(double x) : d(x) {} }; ostream &operator<<(ostream &os, const Double x) { os << fixed << setprecision(20) << x.d; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) { os << "["; for (const auto &v : vec) { os << v << ","; } os << "]"; return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const set<T> &st) { os << "{"; for (T v : st) os << v << ","; os << "}"; return os; } template <typename T, typename U> inline void chmax(T &x, U y) { if (y > x) x = y; } template <typename T, typename U> inline void chmin(T &x, U y) { if (y < x) x = y; } typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<vi> vvi; ll gcd(ll a, ll b) { if (b == 0) return a; else return gcd(b, a % b); } // constexpr double eps = 1e-14; constexpr double eps = 1e-10; constexpr ll mod = 1e9 + 7; const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1}; /*}}}*/ int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; bool miman = false; ll x = 0; for (int i = 62; i >= 0; i--) { if (miman || (k & (1ll << i))) { int one = 0; rep(j, n) { if (a[j] & (1ll << i)) { one++; } } int zero = n - one; if (zero > one) { // oneにする x |= (1ll << i); } else { // zeroにする if (k & (1ll << i)) { miman = true; } } } } // cout << x << endl; assert(x <= k); ll ans = 0; for (int i = 0; i < n; i++) { ans += (x ^ a[i]); } cout << ans << endl; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
939,517
939,518
u013750540
cpp
p03138
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; vector<ll> num; struct Nbase { int n; int sz = 1; long long max = 1e18; Nbase(int k = 2) { n = k; while (max != 0) { max /= n; sz++; } num.resize(sz); }; //繰り返し二乗法 ll EX(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 1) return EX(x, n - 1) * x; else return EX(x * x, n / 2); } vector<int> to_n(ll num) { vector<int> ret(sz); for (int i = sz - 1; i >= 0; i--) { long long subtraction = EX(n, i); if (subtraction <= num) { for (int j = 1; j <= n; j++) { if (num < j * subtraction) { ret[i] = j - 1; num -= ret[i] * subtraction; } } } else ret[i] = 0; } return ret; } long long re_n(vector<ll> &vec) { long long ret = 0; vec.resize(sz); for (int i = 0; i < sz; i++) { ret += vec[i] * EX(n, i); } return ret; } void supress(const vector<int> &lim, vector<int> &at) { bool upper = true; for (int i = sz; i >= 0; i--) { /*if(upper && lim[i] > 0) upper = false; if(lim[i] > at[i]) break; else if(upper || lim[i] < at[i]) at[i] = lim[i];*/ if (upper && lim[i] == 1) upper = false; if (lim[i] == 1 && at[i] == 0) break; else if (lim[i] == 0 || upper) at[i] = 0; } } }; int main() { Nbase base = 2; ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; vector<int> sam = base.to_n(a[i]); for (int j = 0; j < base.sz; j++) { if (sam[j] == 1) num[j]++; } } vector<ll> x(base.sz); for (int i = 0; i < base.sz; i++) { if (num[i] <= n / 2) x[i] = 1; else x[i] = 0; } vector<int> kd = base.to_n(k); // base.supress(kd,x); bool flag = true; for (int i = base.sz; i >= 0; i--) { if (flag && kd[i] == 1) flag = false; if (kd[i] == 1 && x[i] == 0) break; else if (kd[i] == 0 || flag) x[i] = 0; } ll X = base.re_n(x); ll ans = 0; for (int i = 0; i < n; i++) { ans += X ^ a[i]; } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll mod = 1e9 + 7; vector<ll> num; struct Nbase { int n; int sz = 1; long long max = 1e18; Nbase(int k = 2) { n = k; while (max != 0) { max /= n; sz++; } num.resize(sz); }; //繰り返し二乗法 ll EX(ll x, ll n) { if (n == 0) return 1; else if (n % 2 == 1) return EX(x, n - 1) * x; else return EX(x * x, n / 2); } vector<int> to_n(ll num) { vector<int> ret(sz); for (int i = sz - 1; i >= 0; i--) { long long subtraction = EX(n, i); if (subtraction <= num) { for (int j = 1; j <= n; j++) { if (num < j * subtraction) { ret[i] = j - 1; num -= ret[i] * subtraction; } } } else ret[i] = 0; } return ret; } long long re_n(vector<int> &vec) { long long ret = 0; vec.resize(sz); for (int i = 0; i < sz; i++) { ret += vec[i] * EX(n, i); } return ret; } void supress(const vector<int> &lim, vector<int> &at) { bool upper = true; for (int i = sz; i >= 0; i--) { /*if(upper && lim[i] > 0) upper = false; if(lim[i] > at[i]) break; else if(upper || lim[i] < at[i]) at[i] = lim[i];*/ if (upper && lim[i] == 1) upper = false; if (lim[i] == 1 && at[i] == 0) break; else if (lim[i] == 0 || upper) at[i] = 0; } } }; int main() { Nbase base = 2; ll n, k; cin >> n >> k; vector<ll> a(n); for (ll i = 0; i < n; i++) { cin >> a[i]; vector<int> sam = base.to_n(a[i]); for (int j = 0; j < base.sz; j++) { if (sam[j] == 1) num[j]++; } } vector<int> x(base.sz); for (int i = 0; i < base.sz; i++) { if (num[i] <= n / 2) x[i] = 1; else x[i] = 0; } vector<int> kd = base.to_n(k); // base.supress(kd,x); bool flag = true; for (int i = base.sz; i >= 0; i--) { if (flag && kd[i] == 1) flag = false; if (kd[i] == 1 && x[i] == 0) break; else if (kd[i] == 0 || flag) x[i] = 0; } ll X = base.re_n(x); ll ans = 0; for (int i = 0; i < n; i++) { ans += X ^ a[i]; } cout << ans << endl; return 0; }
[]
939,539
939,540
u191484928
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; ll dp[100][2]; int main() { ll n, k; cin >> n >> k; vector<ll> a(n), b; for (int i = 0; i < n; i++) cin >> a[i]; while (k) { b.emplace_back(k % 2); k /= 2; } reverse(b.begin(), b.end()); ll bn = b.size(); dp[0][0] = 0; dp[0][1] = 1LL << (bn - 1); for (int i = 1; i < bn; i++) { if (b[i] == 0) //未満は1と0に分岐、そうじゃなければ、0 { dp[i][1] = dp[i - 1][1]; ll hoge = dp[i - 1][0]; ll sum = 0; for (int j = 0; j < n; j++) sum += a[j] ^ hoge; ll sum2 = 0; ll hoge2 = dp[i - 1][0] + (1LL << (bn - i - 1)); for (int j = 0; j < n; j++) sum2 += a[j] ^ hoge2; if (sum2 > sum) dp[i][0] = hoge2; else dp[i][0] = hoge; } else { ll sum[2] = {}, bit[2] = {}; //まず、dp[i][0]の3つの候補を決める bit[0] = dp[i - 1][0]; for (int j = 0; j < n; j++) sum[0] += a[j] ^ bit[0]; if (sum[1] < sum[0]) { sum[1] = sum[0]; bit[1] = bit[0]; } sum[0] = 0; bit[0] = dp[i - 1][0] + (1LL << (bn - i - 1)); for (int j = 0; j < n; j++) sum[0] += a[j] ^ bit[0]; if (sum[1] < sum[0]) { sum[1] = sum[0]; bit[1] = bit[0]; } sum[0] = 0; bit[0] = dp[i - 1][1]; for (int j = 0; j < n; j++) sum[0] += a[j] ^ bit[0]; if (sum[1] < sum[0]) { sum[1] = sum[0]; bit[1] = bit[0]; } dp[i][0] = bit[1]; dp[i][1] = dp[i - 1][1] + (1LL << (bn - i - 1)); } } ll ans[2] = {}; if (k == 0) { dp[0][0] = dp[0][1] = 0; bn = 1; } // cout << bn << endl; // cout << dp[bn-1][1]<< ' ' << dp[bn-1][0] << endl; // for(int i = 0;i<2;i++){for(int j = 0; j<bn;j++){cout << dp[j][i] << ' // ';}cout << endl;} for (int i = 0; i < n; i++) { ans[1] += a[i] ^ dp[bn - 1][1]; ans[0] += a[i] ^ dp[bn - 1][0]; } cout << max(ans[1], ans[0]) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; ll dp[100][2]; int main() { ll n, k; cin >> n >> k; ll K = k; vector<ll> a(n), b; for (int i = 0; i < n; i++) cin >> a[i]; while (k) { b.emplace_back(k % 2); k /= 2; } reverse(b.begin(), b.end()); ll bn = b.size(); dp[0][0] = 0; dp[0][1] = 1LL << (bn - 1); for (int i = 1; i < bn; i++) { if (b[i] == 0) //未満は1と0に分岐、そうじゃなければ、0 { dp[i][1] = dp[i - 1][1]; ll hoge = dp[i - 1][0]; ll sum = 0; for (int j = 0; j < n; j++) sum += a[j] ^ hoge; ll sum2 = 0; ll hoge2 = dp[i - 1][0] + (1LL << (bn - i - 1)); for (int j = 0; j < n; j++) sum2 += a[j] ^ hoge2; if (sum2 > sum) dp[i][0] = hoge2; else dp[i][0] = hoge; } else { ll sum[2] = {}, bit[2] = {}; //まず、dp[i][0]の3つの候補を決める bit[0] = dp[i - 1][0]; for (int j = 0; j < n; j++) sum[0] += a[j] ^ bit[0]; if (sum[1] < sum[0]) { sum[1] = sum[0]; bit[1] = bit[0]; } sum[0] = 0; bit[0] = dp[i - 1][0] + (1LL << (bn - i - 1)); for (int j = 0; j < n; j++) sum[0] += a[j] ^ bit[0]; if (sum[1] < sum[0]) { sum[1] = sum[0]; bit[1] = bit[0]; } sum[0] = 0; bit[0] = dp[i - 1][1]; for (int j = 0; j < n; j++) sum[0] += a[j] ^ bit[0]; if (sum[1] < sum[0]) { sum[1] = sum[0]; bit[1] = bit[0]; } dp[i][0] = bit[1]; dp[i][1] = dp[i - 1][1] + (1LL << (bn - i - 1)); } } ll ans[2] = {}; if (K == 0) { dp[0][0] = dp[0][1] = 0; bn = 1; } // cout << bn << endl; // cout << dp[bn-1][1]<< ' ' << dp[bn-1][0] << endl; // for(int i = 0;i<2;i++){for(int j = 0; j<bn;j++){cout << dp[j][i] << ' // ';}cout << endl;} for (int i = 0; i < n; i++) { ans[1] += a[i] ^ dp[bn - 1][1]; ans[0] += a[i] ^ dp[bn - 1][0]; } cout << max(ans[1], ans[0]) << endl; }
[ "variable_declaration.add", "identifier.change", "control_flow.branch.if.condition.change" ]
939,541
939,542
u184929210
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PLL = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define drep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define drepn(i, n) for (int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) \ do { \ std::cout << #var << " : "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T = int> using V = vector<T>; template <class T = int> using VV = vector<V<T>>; bool isIn(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void err() { cout << -1 << endl; } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; V<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; rep(i, 50) { int cnt = 0; rep(j, n) if (1 & a[j] >> i) cnt++; if (cnt <= (n - 1) / 2) { ll tmp = ans + (1LL << i); if (tmp <= k) ans += (1LL << i); else break; } } ll res = 0; rep(i, n) res += (a[i] ^ ans); cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PLL = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define drep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define drepn(i, n) for (int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) \ do { \ std::cout << #var << " : "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T = int> using V = vector<T>; template <class T = int> using VV = vector<V<T>>; bool isIn(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void err() { cout << -1 << endl; } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; V<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; drep(i, 50) { int cnt = 0; rep(j, n) if (1 & a[j] >> i) cnt++; if (cnt <= (n - 1) / 2) { ll tmp = ans + (1LL << i); if (tmp <= k) ans += (1LL << i); else continue; } } ll res = 0; rep(i, n) res += (a[i] ^ ans); cout << res << endl; }
[ "identifier.change", "call.function.change", "control_flow.break.remove", "control_flow.continue.add" ]
939,543
939,544
u279033107
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PLL = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define drep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define drepn(i, n) for (int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) \ do { \ std::cout << #var << " : "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T = int> using V = vector<T>; template <class T = int> using VV = vector<V<T>>; bool isIn(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void err() { cout << -1 << endl; } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; V<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; rep(i, 41) { int cnt = 0; rep(j, n) if (1 & a[j] >> i) cnt++; if (cnt <= (n - 1) / 2) { ll tmp = ans + (1LL << i); if (tmp <= k) ans += (1LL << i); else break; } } ll res = 0; rep(i, n) res += (a[i] ^ ans); cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PLL = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define drep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define drepn(i, n) for (int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) \ do { \ std::cout << #var << " : "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T = int> using V = vector<T>; template <class T = int> using VV = vector<V<T>>; bool isIn(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void err() { cout << -1 << endl; } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; V<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; drep(i, 50) { int cnt = 0; rep(j, n) if (1 & a[j] >> i) cnt++; if (cnt <= (n - 1) / 2) { ll tmp = ans + (1LL << i); if (tmp <= k) ans += (1LL << i); else continue; } } ll res = 0; rep(i, n) res += (a[i] ^ ans); cout << res << endl; }
[ "identifier.change", "call.function.change", "literal.number.change", "call.arguments.change", "control_flow.break.remove", "control_flow.continue.add" ]
939,545
939,544
u279033107
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PLL = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define drep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define drepn(i, n) for (int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) \ do { \ std::cout << #var << " : "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T = int> using V = vector<T>; template <class T = int> using VV = vector<V<T>>; bool isIn(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void err() { cout << -1 << endl; } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; V<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; rep(i, 31) { int cnt = 0; rep(j, n) if (1 & a[j] >> i) cnt++; if (cnt <= (n - 1) / 2) { ll tmp = ans + (1LL << i); if (tmp <= k) ans += (1LL << i); else break; } } ll res = 0; rep(i, n) res += (a[i] ^ ans); cout << res << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; using PLL = pair<ll, ll>; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repn(i, n) for (int i = 0; i <= (int)(n); i++) #define srep(i, l, n) for (int i = l; i < (int)(n); i++) #define srepn(i, l, n) for (int i = l; i <= (int)(n); i++) #define drep(i, n) for (int i = (int)(n - 1); i >= 0; i--) #define drepn(i, n) for (int i = (int)(n); i >= 0; i--) #define size(s) (int)s.size() #define debug(var) \ do { \ std::cout << #var << " : "; \ view(var); \ } while (0) template <typename T> void view(T e) { std::cout << e << std::endl; } template <typename T> void view(const std::vector<T> &v) { for (const auto &e : v) { std::cout << e << " "; } std::cout << std::endl; } template <typename T> void view(const std::vector<std::vector<T>> &vv) { for (const auto &v : vv) { view(v); } } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <class T = int> using V = vector<T>; template <class T = int> using VV = vector<V<T>>; bool isIn(int i, int j, int h, int w) { return i >= 0 && i < h && j >= 0 && j < w; } void Yes() { cout << "Yes" << endl; } void No() { cout << "No" << endl; } void YES() { cout << "YES" << endl; } void NO() { cout << "NO" << endl; } void err() { cout << -1 << endl; } #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define pb push_back #define ep emplace_back const int MOD = 1000000007; const int INF = 1e9; #define PI acos(-1); int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int ddx[8] = {1, 1, 1, -1, -1, -1, 0, 0}; int ddy[8] = {0, 1, -1, 0, 1, -1, 1, -1}; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; ll k; cin >> n >> k; V<ll> a(n); rep(i, n) cin >> a[i]; ll ans = 0; drep(i, 50) { int cnt = 0; rep(j, n) if (1 & a[j] >> i) cnt++; if (cnt <= (n - 1) / 2) { ll tmp = ans + (1LL << i); if (tmp <= k) ans += (1LL << i); else continue; } } ll res = 0; rep(i, n) res += (a[i] ^ ans); cout << res << endl; }
[ "identifier.change", "call.function.change", "literal.number.change", "call.arguments.change", "control_flow.break.remove", "control_flow.continue.add" ]
939,546
939,544
u279033107
cpp
p03138
/////////////////////////////////////////////////////////////////////////////// #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <typeinfo> #include <vector> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define pb push_back #define V vector #define ll long long #define ull unsigned long long #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; --i) struct UnionFind { unsigned ll *parent, *count, *rank; UnionFind(unsigned ll n) { parent = new unsigned ll[n + 1]; count = new unsigned ll[n + 1]; rank = new unsigned ll[n + 1]; for (unsigned ll i = 0UL; i < n + 1; ++i) { parent[i] = i; count[i] = 1; rank[i] = 0; } } unsigned ll root(unsigned ll i) { if (parent[i] == i) return i; parent[i] = root(parent[i]); return parent[i]; } void unite(unsigned ll i, unsigned ll j) { unsigned ll rooti = root(i); unsigned ll rootj = root(j); if (rooti == rootj) return; if (rank[rootj] < rank[rooti]) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] += count[rootj]; } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] += count[rooti]; if (rank[rootj] == rank[rooti]) rank[rootj]++; } } bool same(unsigned ll i, unsigned ll j) { return root(i) == root(j); } }; struct T2 { ll t0; ll t1; }; struct T3 { ll t0; ll t1; ll t2; }; struct T4 { ll t0; ll t1; ll t2; ll t3; }; bool operator<(const T2 &lhs, const T2 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0; return lhs.t1 < rhs.t1; } bool operator>(const T2 &lhs, const T2 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0; return lhs.t1 > rhs.t1; } bool operator==(const T2 &lhs, const T2 &rhs) { if (lhs.t0 != rhs.t0) return false; return lhs.t1 == rhs.t1; } bool operator!=(const T2 &lhs, const T2 &rhs) { return !(lhs == rhs); } bool operator<(const T3 &lhs, const T3 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 < rhs.t1; return lhs.t2 < rhs.t2; } bool operator>(const T3 &lhs, const T3 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 > rhs.t1; return lhs.t2 > rhs.t2; } bool operator==(const T3 &lhs, const T3 &rhs) { if (lhs.t0 != rhs.t0) return false; if (lhs.t1 != rhs.t1) return false; return lhs.t2 == rhs.t2; } bool operator!=(const T3 &lhs, const T3 &rhs) { return !(lhs == rhs); } bool operator<(const T4 &lhs, const T4 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 < rhs.t1; if (lhs.t2 != rhs.t2) return lhs.t2 < rhs.t2; return lhs.t3 < rhs.t3; } bool operator>(const T4 &lhs, const T4 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 > rhs.t1; if (lhs.t2 != rhs.t2) return lhs.t2 > rhs.t2; return lhs.t3 > rhs.t3; } bool operator==(const T4 &lhs, const T4 &rhs) { if (lhs.t0 != rhs.t0) return false; if (lhs.t1 != rhs.t1) return false; if (lhs.t2 != rhs.t2) return false; return lhs.t3 == rhs.t3; } bool operator!=(const T4 &lhs, const T4 &rhs) { return !(lhs == rhs); } void llin(ll &a) { cin >> a; } void llinl1(auto &v, ll count) { for (ll i = 0; i < count; ++i) { ll a; cin >> a; v.push_back(a); } } void llinl2(auto &v, ll count) { for (ll i = 0; i < count; ++i) { ll a, b; cin >> a >> b; v.push_back({a, b}); } } void llinl3(auto &v, ll count) { for (ll i = 0; i < count; ++i) { ll a, b, c; cin >> a >> b >> c; v.push_back({a, b, c}); } } void llina(auto &v, ll count) { llinl1(v, count); } ll min(const V<ll> v) { ll ret = (ll)numeric_limits<double>::infinity(); for (auto i : v) ret = min(ret, i); return ret; } void sort(V<ll> &v) { sort(v.begin(), v.end()); } void sort_reverse(V<ll> &v) { sort(v.begin(), v.end(), greater<ll>()); } void get_divisors(V<ll> &retlist, ll x) { for (int i = 1; i < sqrt(x) + 3; ++i) { if (x % i == 0) { retlist.push_back(i); retlist.push_back(x / i); } } } void intersection(const set<ll> &a, const set<ll> &b, set<ll> &result) { V<ll> resultlist; set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(resultlist)); set<ll> resultset(resultlist.begin(), resultlist.end()); result = resultset; } unsigned ll combination(ll x, ll y) { if (y > x / 2L) y = x - y; unsigned ll ret = 1; for (int i = 0; i < y; ++i) { ret *= x--; ret /= (i + 1); } return ret; } void debug_print(auto xlist) { for (auto x : xlist) cout << "-- " << x << endl; } /////////////////////////////////////////////////////////////////////////////// ll count0[61]; ll count1[61]; ll f(ll sum, ll k, ll bit) { if (bit == 0LL) { if (k & 1LL) { sum += max(count0[0], count1[1]); return sum; } return sum + count1[1]; } if (((k >> bit) & 1LL) == 0LL) { sum += (1LL << bit) * count1[bit]; return f(sum, k, bit - 1LL); } if (((1LL << bit) - 1LL) == (k - (1LL << bit))) { ll sum0 = sum + (1LL << bit) * count1[bit]; ll sum1 = sum + (1LL << bit) * count0[bit]; return f(max(sum0, sum1), (1LL << bit) - 1LL, bit - 1LL); ; } // select 0 ll sum0 = sum + (1LL << bit) * count1[bit]; ll ret0 = f(sum0, (1LL << bit) - 1LL, bit - 1LL); if (count1[bit] >= count0[bit]) return ret0; // select 1 ll sum1 = sum + (1LL << bit) * count0[bit]; ll ret1 = f(sum1, k - (1LL << bit), bit - 1LL); return max(ret0, ret1); } int main() { ll n, k; llin((ll &)n); llin((ll &)k); V<ll> alist; llina(alist, n); rep(i, 61) count0[i] = count1[i] = 0LL; for (auto a : alist) { rep(i, 61) { if ((a >> i) & 1LL) count1[i]++; else count0[i]++; } } cout << f(0LL, k, 60LL); return 0; } ///////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////// #include <algorithm> #include <cmath> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <typeinfo> #include <vector> using namespace std; /////////////////////////////////////////////////////////////////////////////// #define pb push_back #define V vector #define ll long long #define ull unsigned long long #define rep(i, n) for (int i = 0; i < n; ++i) #define rrep(i, n) for (int i = n - 1; i >= 0; --i) struct UnionFind { unsigned ll *parent, *count, *rank; UnionFind(unsigned ll n) { parent = new unsigned ll[n + 1]; count = new unsigned ll[n + 1]; rank = new unsigned ll[n + 1]; for (unsigned ll i = 0UL; i < n + 1; ++i) { parent[i] = i; count[i] = 1; rank[i] = 0; } } unsigned ll root(unsigned ll i) { if (parent[i] == i) return i; parent[i] = root(parent[i]); return parent[i]; } void unite(unsigned ll i, unsigned ll j) { unsigned ll rooti = root(i); unsigned ll rootj = root(j); if (rooti == rootj) return; if (rank[rootj] < rank[rooti]) { parent[i] = parent[j] = parent[rootj] = rooti; count[rooti] += count[rootj]; } else { parent[i] = parent[j] = parent[rooti] = rootj; count[rootj] += count[rooti]; if (rank[rootj] == rank[rooti]) rank[rootj]++; } } bool same(unsigned ll i, unsigned ll j) { return root(i) == root(j); } }; struct T2 { ll t0; ll t1; }; struct T3 { ll t0; ll t1; ll t2; }; struct T4 { ll t0; ll t1; ll t2; ll t3; }; bool operator<(const T2 &lhs, const T2 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0; return lhs.t1 < rhs.t1; } bool operator>(const T2 &lhs, const T2 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0; return lhs.t1 > rhs.t1; } bool operator==(const T2 &lhs, const T2 &rhs) { if (lhs.t0 != rhs.t0) return false; return lhs.t1 == rhs.t1; } bool operator!=(const T2 &lhs, const T2 &rhs) { return !(lhs == rhs); } bool operator<(const T3 &lhs, const T3 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 < rhs.t1; return lhs.t2 < rhs.t2; } bool operator>(const T3 &lhs, const T3 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 > rhs.t1; return lhs.t2 > rhs.t2; } bool operator==(const T3 &lhs, const T3 &rhs) { if (lhs.t0 != rhs.t0) return false; if (lhs.t1 != rhs.t1) return false; return lhs.t2 == rhs.t2; } bool operator!=(const T3 &lhs, const T3 &rhs) { return !(lhs == rhs); } bool operator<(const T4 &lhs, const T4 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 < rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 < rhs.t1; if (lhs.t2 != rhs.t2) return lhs.t2 < rhs.t2; return lhs.t3 < rhs.t3; } bool operator>(const T4 &lhs, const T4 &rhs) { if (lhs.t0 != rhs.t0) return lhs.t0 > rhs.t0; if (lhs.t1 != rhs.t1) return lhs.t1 > rhs.t1; if (lhs.t2 != rhs.t2) return lhs.t2 > rhs.t2; return lhs.t3 > rhs.t3; } bool operator==(const T4 &lhs, const T4 &rhs) { if (lhs.t0 != rhs.t0) return false; if (lhs.t1 != rhs.t1) return false; if (lhs.t2 != rhs.t2) return false; return lhs.t3 == rhs.t3; } bool operator!=(const T4 &lhs, const T4 &rhs) { return !(lhs == rhs); } void llin(ll &a) { cin >> a; } void llinl1(auto &v, ll count) { for (ll i = 0; i < count; ++i) { ll a; cin >> a; v.push_back(a); } } void llinl2(auto &v, ll count) { for (ll i = 0; i < count; ++i) { ll a, b; cin >> a >> b; v.push_back({a, b}); } } void llinl3(auto &v, ll count) { for (ll i = 0; i < count; ++i) { ll a, b, c; cin >> a >> b >> c; v.push_back({a, b, c}); } } void llina(auto &v, ll count) { llinl1(v, count); } ll min(const V<ll> v) { ll ret = (ll)numeric_limits<double>::infinity(); for (auto i : v) ret = min(ret, i); return ret; } void sort(V<ll> &v) { sort(v.begin(), v.end()); } void sort_reverse(V<ll> &v) { sort(v.begin(), v.end(), greater<ll>()); } void get_divisors(V<ll> &retlist, ll x) { for (int i = 1; i < sqrt(x) + 3; ++i) { if (x % i == 0) { retlist.push_back(i); retlist.push_back(x / i); } } } void intersection(const set<ll> &a, const set<ll> &b, set<ll> &result) { V<ll> resultlist; set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(resultlist)); set<ll> resultset(resultlist.begin(), resultlist.end()); result = resultset; } unsigned ll combination(ll x, ll y) { if (y > x / 2L) y = x - y; unsigned ll ret = 1; for (int i = 0; i < y; ++i) { ret *= x--; ret /= (i + 1); } return ret; } void debug_print(auto xlist) { for (auto x : xlist) cout << "-- " << x << endl; } /////////////////////////////////////////////////////////////////////////////// ll count0[61]; ll count1[61]; ll f(ll sum, ll k, ll bit) { if (bit == 0LL) { if (k & 1LL) { sum += max(count0[0], count1[0]); return sum; } return sum + count1[0]; } if (((k >> bit) & 1LL) == 0LL) { sum += (1LL << bit) * count1[bit]; return f(sum, k, bit - 1LL); } if (((1LL << bit) - 1LL) == (k - (1LL << bit))) { ll sum0 = sum + (1LL << bit) * count1[bit]; ll sum1 = sum + (1LL << bit) * count0[bit]; return f(max(sum0, sum1), (1LL << bit) - 1LL, bit - 1LL); ; } // select 0 ll sum0 = sum + (1LL << bit) * count1[bit]; ll ret0 = f(sum0, (1LL << bit) - 1LL, bit - 1LL); if (count1[bit] >= count0[bit]) return ret0; // select 1 ll sum1 = sum + (1LL << bit) * count0[bit]; ll ret1 = f(sum1, k - (1LL << bit), bit - 1LL); return max(ret0, ret1); } int main() { ll n, k; llin((ll &)n); llin((ll &)k); V<ll> alist; llina(alist, n); rep(i, 61) count0[i] = count1[i] = 0LL; for (auto a : alist) { rep(i, 61) { if ((a >> i) & 1LL) count1[i]++; else count0[i]++; } } cout << f(0LL, k, 60LL); return 0; } ///////////////////////////////////////////////////////////////////////////////
[ "literal.number.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "function.return_value.change", "expression.operation.binary.change" ]
939,548
939,549
u167931717
cpp
p03138
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-10) #define pb push_back long long MOD = 1000000007; // long long MOD = 998244353; const long long INF = 1LL << 60; const long double PI = acos(-1.0); struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator==(const mint a) const { return x == a.x; } bool operator!=(const mint a) const { return x != a.x; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; // struct edge { ll to, cost; }; typedef long double ld; using Graph = vector<vector<int>>; struct UnionFind { vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) UnionFind() {} // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.resize(sz_, 1); for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { // assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; struct edge { int to, cost; }; /* ・MODあってる??? */ signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(20); // combination com(200010); int n, k; cin >> n >> k; VE a(n); rep(i, n) cin >> a[i]; int x = 0; for (int i = 59; i >= 0; i--) { int now = 0; if (x + (1LL << i) > k) continue; rep(j, n) { if ((bool)(a[i] & (1LL << i))) now++; } if (now <= n - now) x += (1LL << i); } int ans = 0; rep(i, n) ans += a[i] ^ x; cout << ans << endl; return 0; }
#include <algorithm> #include <bitset> #include <cassert> #include <cfloat> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <limits.h> #include <list> #include <map> #include <math.h> #include <numeric> #include <queue> #include <random> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } using namespace std; #define int long long #define ll long long #define rep(i, n) for (ll i = 0; i < (n); i++) #define P pair<ll, ll> #define sz(x) (ll) x.size() #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define VE vector<ll> #define COUT(x) cout << (x) << endl #define MA map<ll, ll> #define SE set<ll> #define PQ priority_queue<ll> #define PQR priority_queue<ll, VE, greater<ll>> #define YES(n) cout << ((n) ? "YES" : "NO") << endl #define Yes(n) cout << ((n) ? "Yes" : "No") << endl #define EPS (1e-10) #define pb push_back long long MOD = 1000000007; // long long MOD = 998244353; const long long INF = 1LL << 60; const long double PI = acos(-1.0); struct mint { ll x; // typedef long long ll; mint(ll x = 0) : x((x % MOD + MOD) % MOD) {} mint operator-() const { return mint(-x); } mint &operator+=(const mint a) { if ((x += a.x) >= MOD) x -= MOD; return *this; } mint &operator-=(const mint a) { if ((x += MOD - a.x) >= MOD) x -= MOD; return *this; } mint &operator*=(const mint a) { (x *= a.x) %= MOD; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime MOD mint inv() const { return pow(MOD - 2); } mint &operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } bool operator==(const mint a) const { return x == a.x; } bool operator!=(const mint a) const { return x != a.x; } }; istream &operator>>(istream &is, const mint &a) { return is >> a.x; } ostream &operator<<(ostream &os, const mint &a) { return os << a.x; } struct Sieve { int n; vector<int> f, primes; Sieve(int n = 1) : n(n), f(n + 1) { f[0] = f[1] = -1; for (ll i = 2; i <= n; ++i) { if (f[i]) continue; primes.push_back(i); f[i] = i; for (ll j = i * i; j <= n; j += i) { if (!f[j]) f[j] = i; } } } bool isPrime(int x) { return f[x] == x; } vector<int> factorList(int x) { vector<int> res; while (x != 1) { res.push_back(f[x]); x /= f[x]; } return res; } vector<P> factor(int x) { vector<int> fl = factorList(x); if (fl.size() == 0) return {}; vector<P> res(1, P(fl[0], 0)); for (int p : fl) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } }; template <class t> t gcd(t a, t b) { return b != 0 ? gcd(b, a % b) : a; } ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; } bool prime(ll n) { for (ll i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return n != 1; } map<ll, ll> prime_factor(ll n) { map<ll, ll> ret; for (ll i = 2; i * i <= n; i++) { while (n % i == 0) { ret[i]++; n /= i; } } if (n != 1) ret[n] = 1; return ret; } ll modinv(ll a, ll m) { ll b = m, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= m; if (u < 0) u += m; return u; } vector<pair<char, int>> RunLength(string s) { if (s.size() == 0) return {}; vector<pair<char, int>> res(1, pair<char, int>(s[0], 0)); for (char p : s) { if (res.back().first == p) { res.back().second++; } else { res.emplace_back(p, 1); } } return res; } // Digit Count int GetDigit(int num) { return log10(num) + 1; } // bit calculation[how many "1"] (= __builtin_popcount()) int bit_count(int n) { int cnt = 0; while (n > 0) { if (n % 2 == 1) cnt++; n /= 2; } return cnt; } vector<long long> enum_divisors(long long N) { vector<long long> res; for (long long i = 1; i * i <= N; ++i) { if (N % i == 0) { res.push_back(i); if (N / i != i) res.push_back(N / i); } } sort(res.begin(), res.end()); return res; } const ll dx[4] = {1, 0, -1, 0}; const ll dy[4] = {0, 1, 0, -1}; // struct edge { ll to, cost; }; typedef long double ld; using Graph = vector<vector<int>>; struct UnionFind { vector<ll> par; // 各元の親を表す配列 vector<ll> siz; // 素集合のサイズを表す配列(1 で初期化) UnionFind() {} // Constructor UnionFind(ll sz_) : par(sz_), siz(sz_, 1) { for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } void init(ll sz_) { par.resize(sz_); siz.resize(sz_, 1); for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身 } // Member Function // Find ll root(ll x) { // 根の検索 while (par[x] != x) { x = par[x] = par[par[x]]; // x の親の親を x の親とする } return x; } // Union(Unite, Merge) bool merge(ll x, ll y) { x = root(x); y = root(y); if (x == y) return false; // merge technique(データ構造をマージするテク.小を大にくっつける) if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(ll x, ll y) { // 連結判定 return root(x) == root(y); } ll size(ll x) { // 素集合のサイズ return siz[root(x)]; } }; struct combination { vector<mint> fact, ifact; combination(int n) : fact(n + 1), ifact(n + 1) { // assert(n < mod); fact[0] = 1; for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i; ifact[n] = fact[n].inv(); for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i; } mint operator()(int n, int k) { if (k < 0 || k > n) return 0; return fact[n] * ifact[k] * ifact[n - k]; } }; struct edge { int to, cost; }; /* ・MODあってる??? */ signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // cout << fixed << setprecision(20); // combination com(200010); int n, k; cin >> n >> k; VE a(n); rep(i, n) cin >> a[i]; int x = 0; for (int i = 59; i >= 0; i--) { int now = 0; if (x + (1LL << i) > k) continue; rep(j, n) { if ((bool)(a[j] & (1LL << i))) now++; } if (now <= n - now) x += (1LL << i); } int ans = 0; rep(i, n) ans += a[i] ^ x; cout << ans << endl; return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
939,554
939,555
u809967037
cpp
p03138
#include <bits/stdc++.h> #define int long long typedef long long ll; using namespace std; const ll MAXN = 200000; const ll INF = 1001001001; ll N, K, ans = 0, tmp = 0, dgt[42][2]; vector<ll> A; signed main() { cin >> N >> K; for (int i = 0; i < N; i++) { ll a; cin >> a; A.push_back(a); int ct = 0; while (a >= 1) { ll a1 = a % 2; dgt[ct][a1]++; a /= 2; ct++; } } for (int i = 41; i >= 0; i--) { if (K < pow(2, i)) continue; if (N - dgt[i][1] > dgt[i][1]) { tmp += pow(2, i); if (tmp > K) { tmp -= pow(2, i); break; } } } for (int i = 0; i < A.size(); i++) { ans += A[i] ^ tmp; } // cout << tmp << " " << ans << endl; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define int long long typedef long long ll; using namespace std; const ll MAXN = 200000; const ll INF = 1001001001; ll N, K, ans = 0, tmp = 0, dgt[42][2]; vector<ll> A; signed main() { cin >> N >> K; for (int i = 0; i < N; i++) { ll a; cin >> a; A.push_back(a); int ct = 0; while (a >= 1) { ll a1 = a % 2; dgt[ct][a1]++; a /= 2; ct++; } } for (int i = 41; i >= 0; i--) { if (K < pow(2, i)) continue; if (N - dgt[i][1] > dgt[i][1]) { tmp += pow(2, i); if (tmp > K) { tmp -= pow(2, i); // break; } } } for (int i = 0; i < A.size(); i++) { ans += A[i] ^ tmp; } // cout << tmp << " " << ans << endl; cout << ans << endl; return 0; }
[]
939,561
939,562
u132452589
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; #define SORT(a) sort((a).begin(), (a).end()) #define rSORT(a) reverse((a).begin(), (a).end()) #define For(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // Write From this Line ll dp[100][2]; int main() { int N; cin >> N; ll K; cin >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; for (int i = 0; i < N; i++) dp[i][0] = dp[i][1] = -1; dp[45][0] = 0; for (int d = 44; d >= 0; --d) { ll mask = 1LL << d; int num = 0; for (int i = 0; i < N; i++) if (A[i] & mask) ++num; // d桁目が立ってるやつの数 if (dp[d + 1][1] >= 0) chmax(dp[d][1], dp[d + 1][1] + mask * max(num, N - num)); if (dp[d + 1][0] >= 0) { if (K & (1LL << d)) { chmax(dp[d][1], dp[d + 1][0] + mask * num); chmax(dp[d][0], dp[d + 1][0] + mask * (N - num)); } else { chmax(dp[d][0], dp[d + 1][0] + mask * num); } } } cout << max(dp[0][0], dp[0][1]) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; typedef pair<int, int> P; #define SORT(a) sort((a).begin(), (a).end()) #define rSORT(a) reverse((a).begin(), (a).end()) #define For(i, a, b) for (int i = (a); i < (b); ++i) #define rep(i, n) For(i, 0, n) #define debug(x) cerr << #x << " = " << (x) << endl; template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // Write From this Line ll dp[100][2]; int main() { int N; cin >> N; ll K; cin >> K; vector<ll> A(N); rep(i, N) cin >> A[i]; for (int i = 0; i < 100; i++) dp[i][0] = dp[i][1] = -1; dp[45][0] = 0; for (int d = 44; d >= 0; --d) { ll mask = 1LL << d; int num = 0; for (int i = 0; i < N; i++) if (A[i] & mask) ++num; // d桁目が立ってるやつの数 if (dp[d + 1][1] >= 0) chmax(dp[d][1], dp[d + 1][1] + mask * max(num, N - num)); if (dp[d + 1][0] >= 0) { if (K & (1LL << d)) { chmax(dp[d][1], dp[d + 1][0] + mask * num); chmax(dp[d][0], dp[d + 1][0] + mask * (N - num)); } else { chmax(dp[d][0], dp[d + 1][0] + mask * num); } } } cout << max(dp[0][0], dp[0][1]) << endl; }
[ "identifier.replace.remove", "literal.replace.add", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
939,565
939,566
u298620933
cpp
p03138
// https://atcoder.jp/contests/abc117/tasks/abc117_d // https://drken1215.hatenablog.com/entry/2019/02/03/224200 #include <cmath> #include <iostream> #include <vector> using namespace std; int binary_digit_one_num[100]; // i桁目の値が1の個数; int main() { int N; long long K; cin >> N >> K; vector<long long> a(N); for (int i = 0; i < N; ++i) { cin >> a[i]; } // 10進数を2進数にして、各桁で1があるところを記録 for (int i = 0; i < N; ++i) { long long NUM = a[i]; int keta = 0; int cnt = 0; while (NUM > 0) { if (NUM & 1) { keta = cnt; binary_digit_one_num[keta]++; } NUM >>= 1; cnt++; } } int max_keta = 0; int cnt = 0; long long k = K; while (k > 0) { if (K & 1) max_keta = cnt; k >>= 1; cnt++; } long long candidate = 0; for (int keta = max_keta; keta >= 0; --keta) { if (N % 2 == 0) { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2) { long long tmp = candidate + pow(2, keta); if (tmp <= K) { candidate = tmp; } } } else { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2 + 1) { long long tmp = candidate + pow(2, keta); if (tmp <= K) { candidate = tmp; } } } } long long ans = 0; for (int i = 0; i < N; ++i) { ans += candidate ^ a[i]; } cout << ans << endl; }
#include <cmath> #include <iostream> #include <vector> using namespace std; int binary_digit_one_num[100]; // i桁目の値が1の個数; int main() { int N; long long K; cin >> N >> K; vector<long long> a(N); for (int i = 0; i < N; ++i) { cin >> a[i]; } // 10進数を2進数にして、各桁で1があるところを記録 for (int i = 0; i < N; ++i) { long long NUM = a[i]; int keta = 0; int cnt = 0; while (NUM > 0) { if (NUM & 1) { keta = cnt; binary_digit_one_num[keta]++; } NUM >>= 1; cnt++; } } int max_keta = 0; int cnt = 0; long long k = K; while (k > 0) { if (k & 1) max_keta = cnt; k >>= 1; cnt++; } long long candidate = 0; for (int keta = max_keta; keta >= 0; --keta) { if (N % 2 == 0) { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2) { long long tmp = candidate + pow(2, keta); if (tmp <= K) { candidate = tmp; } } } else { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2 + 1) { long long tmp = candidate + pow(2, keta); if (tmp <= K) { candidate = tmp; } } } } long long ans = 0; for (int i = 0; i < N; ++i) { ans += candidate ^ a[i]; } cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
939,567
939,568
u218744484
cpp
p03138
#include <cmath> #include <iostream> #include <vector> using namespace std; int binary_digit_one_num[100]; // i桁目の値が1の個数; int main() { int N; long long K; cin >> N >> K; vector<long long> a(N); for (int i = 0; i < N; ++i) { cin >> a[i]; } // 10進数を2進数にして、各桁で1があるところを記録 for (int i = 0; i < N; ++i) { long long NUM = a[i]; int keta = 0; int cnt = 0; while (NUM > 0) { if (NUM & 1) { keta = cnt; binary_digit_one_num[keta]++; } NUM >>= 1; cnt++; } } int max_keta = 0; int cnt = 0; long long k = K; while (k > 0) { if (K & 1) max_keta = cnt; k >>= 1; cnt++; } long long candidate = 0; for (int keta = max_keta; keta >= 0; --keta) { if (N % 2 == 0) { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2) { long long tmp = candidate + pow(2, keta); if (tmp < K) { candidate = tmp; } } } else { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2 + 1) { long long tmp = candidate + pow(2, keta); if (tmp < K) { candidate = tmp; } } } } long long ans = 0; for (int i = 0; i < N; ++i) { ans += candidate ^ a[i]; } cout << ans << endl; }
#include <cmath> #include <iostream> #include <vector> using namespace std; int binary_digit_one_num[100]; // i桁目の値が1の個数; int main() { int N; long long K; cin >> N >> K; vector<long long> a(N); for (int i = 0; i < N; ++i) { cin >> a[i]; } // 10進数を2進数にして、各桁で1があるところを記録 for (int i = 0; i < N; ++i) { long long NUM = a[i]; int keta = 0; int cnt = 0; while (NUM > 0) { if (NUM & 1) { keta = cnt; binary_digit_one_num[keta]++; } NUM >>= 1; cnt++; } } int max_keta = 0; int cnt = 0; long long k = K; while (k > 0) { if (k & 1) max_keta = cnt; k >>= 1; cnt++; } long long candidate = 0; for (int keta = max_keta; keta >= 0; --keta) { if (N % 2 == 0) { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2) { long long tmp = candidate + pow(2, keta); if (tmp <= K) { candidate = tmp; } } } else { // 0が多いので1を選択 if (binary_digit_one_num[keta] < N / 2 + 1) { long long tmp = candidate + pow(2, keta); if (tmp <= K) { candidate = tmp; } } } } long long ans = 0; for (int i = 0; i < N; ++i) { ans += candidate ^ a[i]; } cout << ans << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change", "expression.operator.compare.change" ]
939,569
939,568
u218744484
cpp
p03138
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) \ for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) \ for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using tll = tuple<ll, ll, ll>; using vtll = vector<tuple<ll, ll, ll>>; using vb = vector<bool>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; // https://www.hamayanhamayan.com/entry/2019/02/03/234144 ll dp[100][2]; signed main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vll a(n); rep(i, n) cin >> a[i]; rep(i, 61) rep(j, 2) dp[i][j] = -LINF; dp[0][0] = 0; rep(i, 60) rep(j, 2) { if (dp[i][j] < 0) continue; ll d = 60 - i - 1; ll msk = 1LL << d; ll one = 0, zero = 0; rep(i, n) { if (a[i] & msk) one++; else zero++; } ll nj = j; if (k & msk) nj = 1; chmax(dp[i + 1][nj], dp[i][j] + one * msk); if ((k & msk) or k == 1) chmax(dp[i + 1][j], dp[i][j] + zero * msk); } cout << max(dp[60][0], dp[60][1]) << endl; }
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) \ for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) \ for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using tll = tuple<ll, ll, ll>; using vtll = vector<tuple<ll, ll, ll>>; using vb = vector<bool>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; // https://www.hamayanhamayan.com/entry/2019/02/03/234144 ll dp[100][2]; signed main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vll a(n); rep(i, n) cin >> a[i]; rep(i, 41) rep(j, 2) dp[i][j] = -LINF; dp[0][0] = 0; rep(i, 40) rep(j, 2) { if (dp[i][j] < 0) continue; ll d = 40 - i - 1; ll msk = 1LL << d; ll one = 0, zero = 0; rep(i, n) { if (a[i] & msk) one++; else zero++; } ll nj = j; if (k & msk) nj = 1; chmax(dp[i + 1][nj], dp[i][j] + one * msk); if ((k & msk) or j == 1) chmax(dp[i + 1][j], dp[i][j] + zero * msk); } cout << max(dp[40][0], dp[40][1]) << endl; }
[ "literal.number.change", "call.arguments.change", "expression.operation.binary.change", "identifier.change", "control_flow.branch.if.condition.change", "variable_access.subscript.index.change", "io.output.change" ]
939,570
939,571
u530107518
cpp
p03138
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) \ for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) \ for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using tll = tuple<ll, ll, ll>; using vtll = vector<tuple<ll, ll, ll>>; using vb = vector<bool>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; // https://www.hamayanhamayan.com/entry/2019/02/03/234144 ll dp[100][2]; signed main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vll a(n); rep(i, n) cin >> a[i]; rep(i, 41) rep(j, 2) dp[i][j] = -LINF; dp[0][0] = 0; rep(i, 40) rep(j, 2) { if (dp[i][j] < 0) continue; ll d = 40 - i - 1; ll msk = 1LL << d; ll one = 0, zero = 0; rep(i, n) { if (a[i] & msk) one++; else zero++; } ll nj = j; if (k & msk) nj = 1; chmax(dp[i + 1][nj], dp[i][j] + one * msk); if ((k & msk) or k == 1) chmax(dp[i + 1][j], dp[i][j] + zero * msk); } cout << max(dp[40][0], dp[40][1]) << endl; }
#include <bits/stdc++.h> using namespace std; // #define int long long #define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i) #define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i) #define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--) #define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--) #define irep(i, m, n) \ for (long long i = (long long)(m); i < (long long)(n); ++i) #define ireps(i, m, n) \ for (long long i = (long long)(m); i <= (long long)(n); ++i) #define SORT(v, n) sort(v, v + n); #define REVERSE(v, n) reverse(v, v + n); #define vsort(v) sort(v.begin(), v.end()); #define all(v) v.begin(), v.end() #define mp(n, m) make_pair(n, m); #define cout(d) cout << d << endl; #define coutd(d) cout << std::setprecision(10) << d << endl; #define cinline(n) getline(cin, n); #define replace_all(s, b, a) replace(s.begin(), s.end(), b, a); #define PI (acos(-1)) #define FILL(v, n, x) fill(v, v + n, x); #define sz(x) long long(x.size()) using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using vll = vector<ll>; using vvll = vector<vll>; using pii = pair<int, int>; using pll = pair<ll, ll>; using vs = vector<string>; using vpll = vector<pair<ll, ll>>; using tll = tuple<ll, ll, ll>; using vtll = vector<tuple<ll, ll, ll>>; using vb = vector<bool>; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return 1; } return 0; } const ll INF = 1e9; const ll MOD = 1e9 + 7; const ll LINF = 1e18; // https://www.hamayanhamayan.com/entry/2019/02/03/234144 ll dp[100][2]; signed main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vll a(n); rep(i, n) cin >> a[i]; rep(i, 41) rep(j, 2) dp[i][j] = -LINF; dp[0][0] = 0; rep(i, 40) rep(j, 2) { if (dp[i][j] < 0) continue; ll d = 40 - i - 1; ll msk = 1LL << d; ll one = 0, zero = 0; rep(i, n) { if (a[i] & msk) one++; else zero++; } ll nj = j; if (k & msk) nj = 1; chmax(dp[i + 1][nj], dp[i][j] + one * msk); if ((k & msk) or j == 1) chmax(dp[i + 1][j], dp[i][j] + zero * msk); } cout << max(dp[40][0], dp[40][1]) << endl; }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
939,572
939,571
u530107518
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; int d = 0; while ((1LL << d) <= k) d++; ll nums[61] = {}; for (int i = 0; i < n; i++) { ll a; cin >> a; for (int j = 0; j < 61; j++) { nums[j] += (a & (1LL << j)) >> j; } } ll dp_limit = 0, ans = 0; bool limit = true; for (int i = 60; i >= 0; i--) { if (i < d) { if (k & (1LL << i) == 0) { if (!limit) { if (nums[i] >= n - nums[i]) ans += nums[i] * (1LL << i); // select 0 else ans += (n - nums[i]) * (1LL << i); // select 1 } dp_limit += nums[i] * (1LL << i); // select 0 } else { if (nums[i] >= n - nums[i]) { // select 0 ans = max(ans, dp_limit) + nums[i] * (1LL << i); dp_limit += nums[i] * (1LL << i); limit = false; } else { // select 1 if (!limit) ans += (n - nums[i]) * (1LL << i); else { ans = dp_limit + nums[i] * (1LL << i); limit = false; } dp_limit += (n - nums[i]) * (1LL << i); } } } else { dp_limit += nums[i] * (1LL << i); } } cout << max(ans, dp_limit) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ll n, k; cin >> n >> k; int d = 0; while ((1LL << d) <= k) d++; ll nums[61] = {}; for (int i = 0; i < n; i++) { ll a; cin >> a; for (int j = 0; j < 61; j++) { nums[j] += (a & (1LL << j)) >> j; } } ll dp_limit = 0, ans = 0; bool limit = true; for (int i = 60; i >= 0; i--) { if (i < d) { if ((k & (1LL << i)) == 0) { if (!limit) { if (nums[i] >= n - nums[i]) ans += nums[i] * (1LL << i); // select 0 else ans += (n - nums[i]) * (1LL << i); // select 1 } dp_limit += nums[i] * (1LL << i); // select 0 } else { if (nums[i] >= n - nums[i]) { // select 0 ans = max(ans, dp_limit) + nums[i] * (1LL << i); dp_limit += nums[i] * (1LL << i); limit = false; } else { // select 1 if (!limit) ans += (n - nums[i]) * (1LL << i); else { ans = dp_limit + nums[i] * (1LL << i); // select 0 limit = false; } dp_limit += (n - nums[i]) * (1LL << i); } } } else { dp_limit += nums[i] * (1LL << i); } } cout << max(ans, dp_limit) << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
939,578
939,579
u795630164
cpp
p03138
#include <bits/stdc++.h> using namespace std; #define all(n) begin(n), end(n) const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef unsigned long long ull; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } int main() { ll N, K; const int D = 5; cin >> N >> K; vector<ll> A(N); vector<bitset<D>> B(N); for (size_t i = 0; i < N; i++) { cin >> A[i]; B[i] = A[i]; } vll C(D); for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < D; j++) { if (B[i][j]) C[j]++; } } ll ans = 0, mul = 1, now = 0; for (size_t i = 0; i < D - 1; i++) { mul *= 2; } for (int i = D - 1; i >= 0; i--) { if (now + mul > K) { ans += mul * C[i]; mul /= 2; continue; } if (C[i] < N - C[i] and now + mul <= K) // 1のやつが0より少ない、つまり1にしたほうが嬉しいやつ { now += mul; ans += mul * (N - C[i]); } else { ans += mul * C[i]; } mul /= 2; } cout << max(ans, accumulate(all(A), 0LL)); return 0; }
#include <bits/stdc++.h> using namespace std; #define all(n) begin(n), end(n) const long long INF = numeric_limits<long long>::max(); typedef long long ll; typedef vector<int> vint; typedef vector<vector<int>> vvint; typedef vector<ll> vll; typedef vector<vector<ll>> vvll; typedef unsigned long long ull; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); } template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...)); } template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; } template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); } int main() { ll N, K; const int D = 45; cin >> N >> K; vector<ll> A(N); vector<bitset<D>> B(N); for (size_t i = 0; i < N; i++) { cin >> A[i]; B[i] = A[i]; } vll C(D); for (size_t i = 0; i < N; i++) { for (size_t j = 0; j < D; j++) { if (B[i][j]) C[j]++; } } ll ans = 0, mul = 1, now = 0; for (size_t i = 0; i < D - 1; i++) { mul *= 2; } for (int i = D - 1; i >= 0; i--) { if (now + mul > K) { ans += mul * C[i]; mul /= 2; continue; } if (C[i] < N - C[i] and now + mul <= K) // 1のやつが0より少ない、つまり1にしたほうが嬉しいやつ { now += mul; ans += mul * (N - C[i]); } else { ans += mul * C[i]; } mul /= 2; } cout << max(ans, accumulate(all(A), 0LL)); return 0; }
[ "literal.number.change", "variable_declaration.value.change" ]
939,588
939,589
u987913144
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { ll n, K; cin >> n >> K; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<ll>> dp(50, vector<ll>(2, -1)); dp[40][0] = 0; for (int d = 45; d >= 0; d--) { ll num = 0, mask = 1LL << d; for (int j = 0; j < n; j++) if (a[j] & mask) num++; if (dp[d + 1][1] != -1) dp[d][1] = max(dp[d][1], dp[d + 1][1] + mask * max(num, n - num)); if (dp[d + 1][0] != -1) { if (K & mask) { dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * num); dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * (n - num)); } else dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * num); } } cout << max(dp[0][0], dp[0][1]) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { ll n, K; cin >> n >> K; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<ll>> dp(50, vector<ll>(2, -1)); dp[40][0] = 0; for (int d = 45; d >= 0; d--) { ll num = 0, mask = 1LL << d; for (int j = 0; j < n; j++) if (a[j] & mask) num++; if (dp[d + 1][1] != -1) dp[d][1] = max(dp[d][1], dp[d + 1][1] + mask * max(num, n - num)); if (dp[d + 1][0] != -1) { if (K & mask) { dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * num); dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * (n - num)); } else dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * num); } } cout << max(dp[0][0], dp[0][1]) << endl; }
[ "literal.number.change", "assignment.variable.change", "variable_access.subscript.index.change", "assignment.value.change", "call.arguments.change" ]
939,590
939,591
u265359795
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { ll n, K; cin >> n >> K; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<ll>> dp(50, vector<ll>(2, -1)); dp[40][0] = 0; for (int d = 45; d >= 0; d--) { ll num = 0, mask = 1LL << d; for (int j = 0; j < n; j++) if (a[j] & mask) num++; if (dp[d + 1][1] != -1) dp[d][1] = max(dp[d][1], dp[d + 1][1] + mask * max(num, n - num)); if (dp[d + 1][0] != -1) { if (K & mask) { dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * num); dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * (n - num)); } else dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * num); } } cout << max(dp[0][0], dp[0][1]) << endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; signed main() { ll n, K; cin >> n >> K; vector<ll> a(n); for (int i = 0; i < n; i++) cin >> a[i]; vector<vector<ll>> dp(50, vector<ll>(2, -1)); dp[40][0] = 0; for (int d = 45; d >= 0; d--) { ll num = 0, mask = 1LL << d; for (int j = 0; j < n; j++) if (a[j] & mask) num++; if (dp[d + 1][1] != -1) dp[d][1] = max(dp[d][1], dp[d + 1][1] + mask * max(num, n - num)); if (dp[d + 1][0] != -1) { if (K & mask) { dp[d][1] = max(dp[d][1], dp[d + 1][0] + mask * num); dp[d][0] = max(dp[d][1], dp[d + 1][0] + mask * (n - num)); } else dp[d][0] = max(dp[d][0], dp[d + 1][0] + mask * num); } } cout << max(dp[0][0], dp[0][1]) << endl; }
[ "literal.number.change", "assignment.variable.change", "variable_access.subscript.index.change" ]
939,590
939,592
u265359795
cpp
p03138
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using P = pair<int, int>; using vs = vector<string>; using vi = vector<ll>; using vvi = vector<vi>; const int INF = 100010001; const ll LINF = (ll)INF * INF * 10; int main() { int n; cin >> n; ll k; cin >> k; vi a(n); rep(i, n) { cin >> a[i]; } int num = 64 - __builtin_clzll(k); if (k == 0) { num = 0; } ll K = 0; bool ch = true; rep(i_, num) { int i = num - 1 - i_; int z, o; rep(j, n) { if ((a[j] >> i) & 1) { ++o; } else { ++z; } } if (ch) { if ((k >> i) & 1) { if (z <= o) { ch = false; } } else { z -= 1000000; } } K += (1LL << i) * (o < z); } ll ans = 0LL; rep(i, n) { ans += K ^ a[i]; } cout << ans << endl; }
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; ++i) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() using namespace std; using ll = int64_t; using P = pair<int, int>; using vs = vector<string>; using vi = vector<ll>; using vvi = vector<vi>; const int INF = 100010001; const ll LINF = (ll)INF * INF * 10; int main() { int n; cin >> n; ll k; cin >> k; vi a(n); rep(i, n) { cin >> a[i]; } int num = 64 - __builtin_clzll(k); if (k == 0) { num = 0; } ll K = 0; bool ch = true; rep(i_, num) { int i = num - 1 - i_; int z = 0, o = 0; rep(j, n) { if ((a[j] >> i) & 1) { ++o; } else { ++z; } } if (ch) { if ((k >> i) & 1) { if (z <= o) { ch = false; } } else { z -= 1000000; } } K += (1LL << i) * (o < z); } ll ans = 0LL; rep(i, n) { ans += K ^ a[i]; } cout << ans << endl; }
[ "variable_declaration.value.change" ]
939,600
939,601
u802434195
cpp
p03138
#pragma GCC optimize("O3") #pragma GCC optimize("O1") #pragma GCC optimize("O2") #pragma GCC optimize("Os") #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false); #define FO cout.tie(NULL); #define FI cin.tie(NULL); #define IN cin >> #define OUT cout << #define loop(i, a, n) for (int i = a; i < n; i++) #define rloop(i, a, n) for (int i = a; i >= n; i--) #define endl "\n"; #define pb push_back #define mp make_pair #define set_bits(a) __builtin_popcountll(a) #define ll long long int #define ld long double #define vll vector<long long int> #define pll pair<long long int, long long int> #define mod 1000000007 #define M 998244353 using namespace std; ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); } ll P(ll B, ll power, ll modulo) { ll ans = 1LL; while (power > 0LL) { if (power % 2LL == 1LL) { ans = (ans * B) % modulo; } B = (B * B) % modulo; power /= 2LL; } return ans; } bool isPrime(ll n) { if (n <= 1LL) { return false; } if (n <= 3LL) { return true; } if (n % 2 == 0LL || n % 3 == 0LL) { return false; } for (ll i = 5LL; (i * i) <= n; i += 6LL) { if (n % i == 0LL || n % (i + 2LL) == 0LL) { return false; } } return true; } void vok() { FAST FO FI } int main() { vok(); ll n, k; IN n >> k; vll a(n); bitset<50> b[n]; loop(i, 0, n) { IN a[i]; bitset<50> temp(a[i]); b[i] = temp; } bitset<50> ans(0); loop(i, 0, 50) { int countt = 0; loop(j, 0, n) { if (b[j][i]) { countt++; } cout << ""; } cout << ""; ans[i] = 1; if ((countt * 2) < n && ans.to_ullong() <= k) { // Do Nothing } else { ans[i] = 0; } } ll fans = 0LL; cout << ""; ll X = ans.to_ullong(); loop(i, 0, n) { cout << ""; fans += (X ^ a[i]); } OUT fans << endl return 0; }
#pragma GCC optimize("O3") #pragma GCC optimize("O1") #pragma GCC optimize("O2") #pragma GCC optimize("Os") #pragma GCC optimize("Ofast") #pragma GCC target("avx2") #pragma GCC optimization("unroll-loops") #include <bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false); #define FO cout.tie(NULL); #define FI cin.tie(NULL); #define IN cin >> #define OUT cout << #define loop(i, a, n) for (int i = a; i < n; i++) #define rloop(i, a, n) for (int i = a; i >= n; i--) #define endl "\n"; #define pb push_back #define mp make_pair #define set_bits(a) __builtin_popcountll(a) #define ll long long int #define ld long double #define vll vector<long long int> #define pll pair<long long int, long long int> #define mod 1000000007 #define M 998244353 using namespace std; ll gcd(ll a, ll b) { return (b ? gcd(b, a % b) : a); } ll P(ll B, ll power, ll modulo) { ll ans = 1LL; while (power > 0LL) { if (power % 2LL == 1LL) { ans = (ans * B) % modulo; } B = (B * B) % modulo; power /= 2LL; } return ans; } bool isPrime(ll n) { if (n <= 1LL) { return false; } if (n <= 3LL) { return true; } if (n % 2 == 0LL || n % 3 == 0LL) { return false; } for (ll i = 5LL; (i * i) <= n; i += 6LL) { if (n % i == 0LL || n % (i + 2LL) == 0LL) { return false; } } return true; } void vok() { FAST FO FI } int main() { vok(); ll n, k; IN n >> k; vll a(n); bitset<50> b[n]; loop(i, 0, n) { IN a[i]; bitset<50> temp(a[i]); b[i] = temp; } bitset<50> ans(0); rloop(i, 49, 0) { int countt = 0; loop(j, 0, n) { if (b[j][i]) { countt++; } cout << ""; } cout << ""; ans[i] = 1; if ((countt * 2) < n && ans.to_ullong() <= k) { // Do Nothing } else { ans[i] = 0; } } ll fans = 0LL; cout << ""; ll X = ans.to_ullong(); loop(i, 0, n) { cout << ""; fans += (X ^ a[i]); } OUT fans << endl return 0; }
[ "identifier.change", "call.function.change", "literal.number.change", "call.arguments.change" ]
939,614
939,615
u927949305
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll MOD = 1e9 + 7; constexpr ll INF = 1ll << 60; #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return false; } return true; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return false; } return true; } template <class T> bool chmax(T &a, initializer_list<T> l) { return chmax(a, *max_element(l.begin(), l.end())); } template <class T> bool chmin(T &a, initializer_list<T> l) { return chmin(a, *min_element(l.begin(), l.end)); } constexpr ll MAX_B = 50; ll dp[100][2]; int main(int argc, char **argv) { ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, N) cin >> A[i]; for (ll i = 0; i < 100; ++i) dp[i][0] = dp[i][1] = -1; **dp = 0; REP(b, MAX_B) { ll mask = 1ll << (MAX_B - b - 1); ll cnt1{0}; REP(i, N) { if (mask & A[i]) ++cnt1; } ll add0 = cnt1 * mask; ll add1 = (N - cnt1) * mask; if (dp[b][true] != -1) chmax(dp[b + 1][true], dp[b][true] + max(add0, add1)); if (dp[b][false] != -1) { if (K & mask) chmax(dp[b + 1][true], dp[b][false] + add1); } if (dp[b][false] != -1) { if (K & mask) chmax(dp[b + 1][false], dp[b][false] + add1); else chmax(dp[b + 1][false], dp[b][false] + add0); } } std::cout << max(dp[MAX_B][false], dp[MAX_B][true]) << std::endl; }
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll MOD = 1e9 + 7; constexpr ll INF = 1ll << 60; #define FOR(i, a, b) for (ll i = (a); i < (b); ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(v) (v).begin(), (v).end() template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return false; } return true; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return false; } return true; } template <class T> bool chmax(T &a, initializer_list<T> l) { return chmax(a, *max_element(l.begin(), l.end())); } template <class T> bool chmin(T &a, initializer_list<T> l) { return chmin(a, *min_element(l.begin(), l.end)); } constexpr ll MAX_B = 50; ll dp[100][2]; int main(int argc, char **argv) { ll N, K; cin >> N >> K; vector<ll> A(N); REP(i, N) cin >> A[i]; for (ll i = 0; i < 100; ++i) dp[i][0] = dp[i][1] = -1; **dp = 0; REP(b, MAX_B) { ll mask = 1ll << (MAX_B - b - 1); ll cnt1{0}; REP(i, N) { if (mask & A[i]) ++cnt1; } ll add0 = cnt1 * mask; ll add1 = (N - cnt1) * mask; if (dp[b][true] != -1) chmax(dp[b + 1][true], dp[b][true] + max(add0, add1)); if (dp[b][false] != -1) { if (K & mask) chmax(dp[b + 1][true], dp[b][false] + add0); } if (dp[b][false] != -1) { if (K & mask) chmax(dp[b + 1][false], dp[b][false] + add1); else chmax(dp[b + 1][false], dp[b][false] + add0); } } std::cout << max(dp[MAX_B][false], dp[MAX_B][true]) << std::endl; }
[ "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
939,616
939,617
u350072791
cpp
p03138
// INCLUDES #include <assert.h> #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // DEFINES #define MAX 1000001 #define pii pair<int, int> #define F first #define S second #define all(s) begin(s), end(s) #define MIN3POS(a, b, c) \ (a) = < (b) ? ((a) = < (c) ? 1 : 3) : ((b) = < (c) ? 2 : 3) #define MAX3POS(a, b, c) \ (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2 : 3) #define endl '\n' #define int long long #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define FOR(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } // NAMESPACES using namespace __gnu_pbds; using namespace std; vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef XOX #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif // HELPERS int binpow(int a, int b) { if (b == 0) return 1; if (b & 1) return a * binpow(a, b - 1); return binpow(a, b / 2) * binpow(a, b / 2); } vector<int> powers2(32, 0); void initialize() { for (int i = 1; i < powers2.size(); i++) powers2[i] = powers2[i - 1] * 2; } int32_t main() { IOS int n, k; cin >> n >> k; vector<bitset<42>> v(n); FOR(i, 0, n) { int a; cin >> a; v[i] = a; } int ans = 0; // cout<<v[0]<<endl; for (int i = 41; i >= 0; i--) { int cnt = 0; FOR(j, 0, n) if (v[j][i] == 1) cnt++; int val = binpow(2, i); if (n - cnt > cnt && k > val) ans += val * (n - cnt), k -= val; else ans += val * cnt; } cout << ans; return 0; } // Use emplace back in place of pushback // Use tie function , for object destructuring
// INCLUDES #include <assert.h> #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> // DEFINES #define MAX 1000001 #define pii pair<int, int> #define F first #define S second #define all(s) begin(s), end(s) #define MIN3POS(a, b, c) \ (a) = < (b) ? ((a) = < (c) ? 1 : 3) : ((b) = < (c) ? 2 : 3) #define MAX3POS(a, b, c) \ (a) >= (b) ? ((a) >= (c) ? 1 : 3) : ((b) >= (c) ? 2 : 3) #define endl '\n' #define int long long #define ordered_set \ tree<int, null_type, less<int>, rb_tree_tag, \ tree_order_statistics_node_update> #define FOR(i, begin, end) \ for (__typeof(end) i = (begin) - ((begin) > (end)); \ i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) #define IOS \ ios_base::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define error(args...) \ { \ string _s = #args; \ replace(_s.begin(), _s.end(), ',', ' '); \ stringstream _ss(_s); \ istream_iterator<string> _it(_ss); \ err(_it, args); \ } // NAMESPACES using namespace __gnu_pbds; using namespace std; vector<string> vec_splitter(string s) { s += ','; vector<string> res; while (!s.empty()) { res.push_back(s.substr(0, s.find(','))); s = s.substr(s.find(',') + 1); } return res; } void debug_out(vector<string> __attribute__((unused)) args, __attribute__((unused)) int idx, __attribute__((unused)) int LINE_NUM) { cerr << endl; } template <typename Head, typename... Tail> void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) { if (idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") "; stringstream ss; ss << H; cerr << args[idx] << " = " << ss.str(); debug_out(args, idx + 1, LINE_NUM, T...); } #ifdef XOX #define debug(...) \ debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__) #else #define debug(...) 42 #endif // HELPERS int binpow(int a, int b) { if (b == 0) return 1; if (b & 1) return a * binpow(a, b - 1); return binpow(a, b / 2) * binpow(a, b / 2); } vector<int> powers2(32, 0); void initialize() { for (int i = 1; i < powers2.size(); i++) powers2[i] = powers2[i - 1] * 2; } int32_t main() { IOS int n, k; cin >> n >> k; vector<bitset<50>> v(n); FOR(i, 0, n) { int a; cin >> a; v[i] = a; } int ans = 0; // cout<<v[0]<<endl; for (int i = 49; i >= 0; i--) { int cnt = 0; FOR(j, 0, n) if (v[j][i] == 1) cnt++; int val = binpow(2, i); if (n - cnt > cnt && k >= val) ans += val * (n - cnt), k -= val; else ans += val * cnt; } cout << ans; return 0; } // Use emplace back in place of pushback // Use tie function , for object destructuring
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
939,634
939,635
u301593159
cpp
p03138
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() #define bit(x) (1L << (x)) using ll = long long; using namespace std; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll x = 0; for (int i = 60; i >= 0; i--) { if ((1LL << i) > k) continue; int t = 0; rep(j, n) { if ((1LL << i) & a[j]) { t++; } } if (t < n - t) { x += 1LL << i; } } ll ans = 0; rep(i, n) ans += x ^ a[i]; cout << ans << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) #define all(x) (x).begin(), (x).end() #define bit(x) (1L << (x)) using ll = long long; using namespace std; template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); } template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll x = 0; for (int i = 60; i >= 0; i--) { if (x + (1LL << i) > k) continue; int t = 0; rep(j, n) { if ((1LL << i) & a[j]) { t++; } } if (t < n - t) { x += 1LL << i; } } ll ans = 0; rep(i, n) ans += x ^ a[i]; cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
939,636
939,637
u772304668
cpp
p03138
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define rep(i, n) for (ll i = 0; i < n; i++) template <class T, class U> void cmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void cmin(T &a, U b) { if (a > b) a = b; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; ll k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll X = 0; ll ans = 0; for (ll i = 50; i >= 0; i--) { ll cnt = 0; rep(j, n) { if ((1LL << i) & a[j]) cnt++; } // 1 if (cnt < n - cnt && X < k && (1LL << i) <= k) { ans += (1LL << i) * (n - cnt); X |= (1LL << i); // X を0 } else { ans += (1LL << i) * cnt; } } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define rep(i, n) for (ll i = 0; i < n; i++) template <class T, class U> void cmax(T &a, U b) { if (a < b) a = b; } template <class T, class U> void cmin(T &a, U b) { if (a > b) a = b; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n; ll k; cin >> n >> k; vector<ll> a(n); rep(i, n) cin >> a[i]; ll X = 0; ll ans = 0; for (ll i = 60; i >= 0; i--) { ll cnt = 0; rep(j, n) { if ((1LL << i) & a[j]) cnt++; } // 1 if (cnt < n - cnt && (X | (1LL << i)) <= k) { ans += (1LL << i) * (n - cnt); X |= (1LL << i); // X を0 } else { ans += (1LL << i) * cnt; } } cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change", "expression.operation.binary.remove" ]
939,678
939,679
u366644013
cpp
p03138
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, k; ll fx(ll x, vector<ll> &a) { ll sum = 0; for (ll i = 0; i < (ll)a.size(); i++) sum += a[i] ^ x; return sum; } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); vector<int> bit_nums(64); vector<int> x_vec(64); for (int i = 0; i < n; i++) cin >> a[i]; for (ll i = 1; i <= ll(a.size()); i++) { ll t = 0; for (ll j = 0; j < 64; j++) { t = a[i] >> j; bit_nums[j] += (int)(t & ll(1)); } } for (int i = 0; i < 64; i++) { if (n % 2 != 0) { if (bit_nums[i] > (n / 2)) x_vec[i] = 0; else x_vec[i] = 1; } else { if (bit_nums[i] >= (n / 2)) x_vec[i] = 0; else x_vec[i] = 1; } } ll x = 0; for (int i = 62; i >= 0; i--) { ll temp = x; temp += x_vec[i] * ((ll)1 << i); if (temp > k) continue; else x = temp; } ll ans = fx(x, a); cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll n, k; ll fx(ll x, vector<ll> &a) { ll sum = 0; for (ll i = 0; i < (ll)a.size(); i++) sum += a[i] ^ x; return sum; } int main() { ll n, k; cin >> n >> k; vector<ll> a(n); vector<int> bit_nums(64); vector<int> x_vec(64); for (int i = 0; i < n; i++) cin >> a[i]; for (ll i = 0; i < ll(a.size()); i++) { ll t = 0; for (ll j = 0; j < 64; j++) { t = a[i] >> j; bit_nums[j] += (int)(t & ll(1)); } } for (int i = 0; i < 64; i++) { if (n % 2 != 0) { if (bit_nums[i] > (n / 2)) x_vec[i] = 0; else x_vec[i] = 1; } else { if (bit_nums[i] >= (n / 2)) x_vec[i] = 0; else x_vec[i] = 1; } } ll x = 0; for (int i = 62; i >= 0; i--) { ll temp = x; temp += x_vec[i] * ((ll)1 << i); if (temp > k) continue; else x = temp; } ll ans = fx(x, a); cout << ans << endl; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "expression.off_by_one", "expression.operator.compare.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change" ]
939,680
939,681
u883564798
cpp
p03138
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < n; i++) ll A[100100]; int H[50]; ll DP[100][2]; ll N, K; ll func(int i, bool bit) { int h = H[i]; int num; if (bit) num = N - h; else num = h; ll base = pow(2, i); return num * base; } int main() { cin >> N >> K; REP(i, N) { ll a; cin >> a; A[i] = a; } int keta = 0; ll tmpK = K; while (tmpK > 0) { tmpK /= 2; keta++; } if (keta == 0) keta++; for (int k = 0; k < 50; k++) { int hbit = 0; for (int i = 0; i < N; i++) { ll a = A[i]; int bit = (a >> k) & 1; hbit += bit; } H[k] = hbit; } ll ans = 0; if (K != 0) DP[0][1] = func(keta - 1, 1); else DP[0][1] = 0; DP[0][0] = func(keta - 1, 0); int k; for (k = 1; k < keta; k++) { int inv = keta - 1 - k; bool bit = (K >> inv) & 1; DP[k][1] = DP[k - 1][1] + func(inv, k); DP[k][0] = DP[k - 1][0] + max(func(inv, 0), func(inv, 1)); if (bit) DP[k][0] = max(DP[k][0], DP[k - 1][1] + func(inv, 0)); } for (; k < 50; k++) { ans += func(k, 0); } // for(int i = 0; i < keta; i++){ // printf("%lld ", DP[i][1]); //} // printf("\n"); // for(int i = 0; i < keta; i++){ // printf("%lld ", DP[i][0]); //} // printf("\n"); ans += max(DP[keta - 1][0], DP[keta - 1][1]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < n; i++) ll A[100100]; int H[50]; ll DP[100][2]; ll N, K; ll func(int i, bool bit) { int h = H[i]; int num; if (bit) num = N - h; else num = h; ll base = pow(2, i); return num * base; } int main() { cin >> N >> K; REP(i, N) { ll a; cin >> a; A[i] = a; } int keta = 0; ll tmpK = K; while (tmpK > 0) { tmpK /= 2; keta++; } if (keta == 0) keta++; for (int k = 0; k < 50; k++) { int hbit = 0; for (int i = 0; i < N; i++) { ll a = A[i]; int bit = (a >> k) & 1; hbit += bit; } H[k] = hbit; } ll ans = 0; if (K != 0) DP[0][1] = func(keta - 1, 1); else DP[0][1] = 0; DP[0][0] = func(keta - 1, 0); int k; for (k = 1; k < keta; k++) { int inv = keta - 1 - k; bool bit = (K >> inv) & 1; DP[k][1] = DP[k - 1][1] + func(inv, bit); DP[k][0] = DP[k - 1][0] + max(func(inv, 0), func(inv, 1)); if (bit) DP[k][0] = max(DP[k][0], DP[k - 1][1] + func(inv, 0)); } for (; k < 50; k++) { ans += func(k, 0); } // for(int i = 0; i < keta; i++){ // printf("%lld ", DP[i][1]); //} // printf("\n"); // for(int i = 0; i < keta; i++){ // printf("%lld ", DP[i][0]); //} // printf("\n"); ans += max(DP[keta - 1][0], DP[keta - 1][1]); cout << ans << endl; return 0; }
[ "assignment.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
939,692
939,693
u666394517
cpp
p03138
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < n; i++) ll A[100100]; int H[50]; ll N, K; ll calc(ll X) { ll num = 0; for (int i = 0; i < N; i++) { num += X ^ A[i]; } return num; } int main() { cin >> N >> K; REP(i, N) { ll a; cin >> a; A[i] = a; } int keta = 0; ll tmpK = K; while (tmpK > 0) { tmpK /= 2; keta++; } for (int k = 0; k < 50; k++) { int hbit = 0; for (int i = 0; i < N; i++) { ll a = A[i]; int bit = (a >> k) & 1; hbit += bit; } H[k] = hbit; } ll ans = calc(K); for (int i = 0; i < keta; i++) { if ((1LL << i) & K == 0) continue; ll X = 0; int j; for (j = 0; j < i; j++) { // if(H[j] <= N/2){ // X += (1LL << j); //} if (H[j] <= N - H[j]) X += (1LL << j); } for (j = j + 1; j < keta; j++) { if ((1LL << j) & K) X += (1LL << j); } ans = max(ans, calc(X)); } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define REP(i, n) for (int i = 0; i < n; i++) ll A[100100]; int H[50]; ll N, K; ll calc(ll X) { ll num = 0; for (int i = 0; i < N; i++) { num += X ^ A[i]; } return num; } int main() { cin >> N >> K; REP(i, N) { ll a; cin >> a; A[i] = a; } int keta = 0; ll tmpK = K; while (tmpK > 0) { tmpK /= 2; keta++; } for (int k = 0; k < 50; k++) { int hbit = 0; for (int i = 0; i < N; i++) { ll a = A[i]; int bit = (a >> k) & 1; hbit += bit; } H[k] = hbit; } ll ans = calc(K); for (int i = 0; i < keta; i++) { if (!((1LL << i) & K)) continue; // printf("%lld\n", ) ll X = 0; int j; for (j = 0; j < i; j++) { // if(H[j] <= N/2){ // X += (1LL << j); //} if (H[j] <= N - H[j]) X += (1LL << j); } for (j = j + 1; j < keta; j++) { if ((1LL << j) & K) X += (1LL << j); } ans = max(ans, calc(X)); } cout << ans << endl; return 0; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
939,694
939,695
u666394517
cpp
p03138
#include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); } template <class T> constexpr T HINF() { return INF<T>() / 2; } template <typename T_char> T_char TL(T_char cX) { return tolower(cX); }; template <typename T_char> T_char TU(T_char cX) { return toupper(cX); }; typedef pair<LL, LL> pii; const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0}, vx[] = {-1, 0, 1, 1, 1, 0, -1, -1}; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++) if ((n >> i) & 1) cnt++; return cnt; } int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; } return ret; } int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; } return ret; } LL gcd(LL a, LL b) { if (b == 0) return a; return gcd(b, a % b); }; LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g * b; }; #define ALL(qpqpq) (qpqpq).begin(), (qpqpq).end() #define UNIQUE(wpwpw) \ sort(ALL((wpwpw))); \ (wpwpw).erase(unique(ALL((wpwpw))), (wpwpw).end()) #define LOWER(epepe) transform(ALL((epepe)), (epepe).begin(), TL<char>) #define UPPER(rprpr) transform(ALL((rprpr)), (rprpr).begin(), TU<char>) #define FOR(i, tptpt, ypypy) for (LL i = (tptpt); i < (ypypy); i++) #define REP(i, upupu) FOR(i, 0, upupu) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) LL n, k; LL a[101010]; LL cnt[101]; LL dp[101][2]; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, 45) { REP(j, n) { if ((1LL << i) & a[j]) cnt[i]++; } } REP(i, 101) REP(j, 2) dp[i][j] = -1; dp[45][0] = 0; for (int i = 44; i >= 0; i--) { LL mask = 1LL << i; LL num = 0; REP(j, n) { if (a[j] & mask) num++; } LL s0 = mask * num; LL s1 = mask * (n - num); if (dp[i + 1][1] >= 0) { dp[i][1] = max(dp[i][1], max(dp[i + 1][1] + s0, dp[i + 1][0] + s1)); } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][1] = max(dp[i][1], dp[i + 1][0] + s0); } } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s1); } else { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s0); } } } cout << max(dp[0][1], dp[0][0]) << endl; }
#include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); } template <class T> constexpr T HINF() { return INF<T>() / 2; } template <typename T_char> T_char TL(T_char cX) { return tolower(cX); }; template <typename T_char> T_char TU(T_char cX) { return toupper(cX); }; typedef pair<LL, LL> pii; const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0}, vx[] = {-1, 0, 1, 1, 1, 0, -1, -1}; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++) if ((n >> i) & 1) cnt++; return cnt; } int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; } return ret; } int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; } return ret; } LL gcd(LL a, LL b) { if (b == 0) return a; return gcd(b, a % b); }; LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g * b; }; #define ALL(qpqpq) (qpqpq).begin(), (qpqpq).end() #define UNIQUE(wpwpw) \ sort(ALL((wpwpw))); \ (wpwpw).erase(unique(ALL((wpwpw))), (wpwpw).end()) #define LOWER(epepe) transform(ALL((epepe)), (epepe).begin(), TL<char>) #define UPPER(rprpr) transform(ALL((rprpr)), (rprpr).begin(), TU<char>) #define FOR(i, tptpt, ypypy) for (LL i = (tptpt); i < (ypypy); i++) #define REP(i, upupu) FOR(i, 0, upupu) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) LL n, k; LL a[101010]; LL cnt[101]; LL dp[101][2]; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, 45) { REP(j, n) { if ((1LL << i) & a[j]) cnt[i]++; } } REP(i, 101) REP(j, 2) dp[i][j] = -1; dp[45][0] = 0; for (LL i = 44; i >= 0; i--) { LL mask = 1LL << i; LL num = 0; REP(j, n) { if (a[j] & mask) num++; } LL s0 = mask * num; LL s1 = mask * (n - num); if (dp[i + 1][1] >= 0) { dp[i][1] = max(dp[i][1], max(dp[i + 1][1] + s0, dp[i + 1][1] + s1)); } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][1] = max(dp[i][1], dp[i + 1][0] + s0); } } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s1); } else { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s0); } } } cout << max(dp[0][1], dp[0][0]) << endl; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "literal.number.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
939,700
939,701
u093922224
cpp
p03138
#include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); } template <class T> constexpr T HINF() { return INF<T>() / 2; } template <typename T_char> T_char TL(T_char cX) { return tolower(cX); }; template <typename T_char> T_char TU(T_char cX) { return toupper(cX); }; typedef pair<LL, LL> pii; const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0}, vx[] = {-1, 0, 1, 1, 1, 0, -1, -1}; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++) if ((n >> i) & 1) cnt++; return cnt; } int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; } return ret; } int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; } return ret; } LL gcd(LL a, LL b) { if (b == 0) return a; return gcd(b, a % b); }; LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g * b; }; #define ALL(qpqpq) (qpqpq).begin(), (qpqpq).end() #define UNIQUE(wpwpw) \ sort(ALL((wpwpw))); \ (wpwpw).erase(unique(ALL((wpwpw))), (wpwpw).end()) #define LOWER(epepe) transform(ALL((epepe)), (epepe).begin(), TL<char>) #define UPPER(rprpr) transform(ALL((rprpr)), (rprpr).begin(), TU<char>) #define FOR(i, tptpt, ypypy) for (LL i = (tptpt); i < (ypypy); i++) #define REP(i, upupu) FOR(i, 0, upupu) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) LL n, k; LL a[101010]; LL cnt[101]; LL dp[101][2]; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, 45) { REP(j, n) { if ((1LL << i) & a[j]) cnt[i]++; } } REP(i, 101) REP(j, 2) dp[i][j] = -1; dp[45][0] = 0; for (int i = 44; i >= 0; i--) { LL mask = 1LL << i; int num = 0; REP(j, n) { if (a[j] & mask) num++; } LL s0 = mask * num; LL s1 = mask * (n - num); if (dp[i + 1][1] >= 0) { dp[i][1] = max(dp[i][1], max(dp[i + 1][1] + s0, dp[i + 1][0] + s1)); } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][1] = max(dp[i][1], dp[i + 1][0] + s0); } } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s1); } else { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s0); } } } cout << max(dp[0][1], dp[0][0]) << endl; }
#include "bits/stdc++.h" using namespace std; using LL = long long; using ULL = unsigned long long; const double PI = acos(-1); template <class T> constexpr T INF() { return ::std::numeric_limits<T>::max(); } template <class T> constexpr T HINF() { return INF<T>() / 2; } template <typename T_char> T_char TL(T_char cX) { return tolower(cX); }; template <typename T_char> T_char TU(T_char cX) { return toupper(cX); }; typedef pair<LL, LL> pii; const int vy[] = {-1, -1, -1, 0, 1, 1, 1, 0}, vx[] = {-1, 0, 1, 1, 1, 0, -1, -1}; const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; int popcnt(unsigned long long n) { int cnt = 0; for (int i = 0; i < 64; i++) if ((n >> i) & 1) cnt++; return cnt; } int d_sum(LL n) { int ret = 0; while (n > 0) { ret += n % 10; n /= 10; } return ret; } int d_cnt(LL n) { int ret = 0; while (n > 0) { ret++; n /= 10; } return ret; } LL gcd(LL a, LL b) { if (b == 0) return a; return gcd(b, a % b); }; LL lcm(LL a, LL b) { LL g = gcd(a, b); return a / g * b; }; #define ALL(qpqpq) (qpqpq).begin(), (qpqpq).end() #define UNIQUE(wpwpw) \ sort(ALL((wpwpw))); \ (wpwpw).erase(unique(ALL((wpwpw))), (wpwpw).end()) #define LOWER(epepe) transform(ALL((epepe)), (epepe).begin(), TL<char>) #define UPPER(rprpr) transform(ALL((rprpr)), (rprpr).begin(), TU<char>) #define FOR(i, tptpt, ypypy) for (LL i = (tptpt); i < (ypypy); i++) #define REP(i, upupu) FOR(i, 0, upupu) #define INIT \ std::ios::sync_with_stdio(false); \ std::cin.tie(0) LL n, k; LL a[101010]; LL cnt[101]; LL dp[101][2]; int main() { cin >> n >> k; REP(i, n) cin >> a[i]; REP(i, 45) { REP(j, n) { if ((1LL << i) & a[j]) cnt[i]++; } } REP(i, 101) REP(j, 2) dp[i][j] = -1; dp[45][0] = 0; for (LL i = 44; i >= 0; i--) { LL mask = 1LL << i; LL num = 0; REP(j, n) { if (a[j] & mask) num++; } LL s0 = mask * num; LL s1 = mask * (n - num); if (dp[i + 1][1] >= 0) { dp[i][1] = max(dp[i][1], max(dp[i + 1][1] + s0, dp[i + 1][1] + s1)); } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][1] = max(dp[i][1], dp[i + 1][0] + s0); } } if (dp[i + 1][0] >= 0) { if (k & mask) { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s1); } else { dp[i][0] = max(dp[i][0], dp[i + 1][0] + s0); } } } cout << max(dp[0][1], dp[0][0]) << endl; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "literal.number.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
939,702
939,701
u093922224
cpp
p03138
#include <bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vst; typedef vector<bool> vb; typedef vector<ld> vld; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; int dy[9] = {0, 1, 0, -1, -1, -1, 1, 1, 0}; #define ln '\n' #define scnaf scanf #define sacnf scanf #define sancf scanf #define SS(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { cin >> first; MACRO_VAR_Scan(rest...); } #define SV(type, c, n) \ vector<type> c(n); \ for (auto &i : c) \ cin >> i; #define SVV(type, c, n, m) \ vector<vector<type>> c(n, vector<type>(m)); \ for (auto &r : c) \ for (auto &i : r) \ cin >> i; template <class T> ostream &operator<<(ostream &o, const vector<T> &j) { o << "{"; for (int i = 0; i < (int)j.size(); ++i) o << (i > 0 ? ", " : "") << j[i]; o << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &j) { o << "{" << j.first << ", " << j.second << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } inline int print(void) { cout << endl; return 0; } template <class Head> int print(Head &&head) { cout << head; print(); return 0; } template <class Head, class... Tail> int print(Head &&head, Tail &&...tail) { cout << head << " "; print(forward<Tail>(tail)...); return 0; } inline int debug(void) { cerr << endl; return 0; } template <class Head> int debug(Head &&head) { cerr << head; debug(); return 0; } template <class Head, class... Tail> int debug(Head &&head, Tail &&...tail) { cerr << head << " "; debug(forward<Tail>(tail)...); return 0; } template <typename T> void PA(T &a) { int ASIZE = sizeof(a) / sizeof(a[0]); for (int ii = 0; ii < ASIZE; ++ii) { cout << a[ii] << " \n"[ii == ASIZE - 1]; } } template <typename T> void PV(T &v) { int VSIZE = v.size(); for (int ii = 0; ii < VSIZE; ++ii) { cout << v[ii] << " \n"[ii == VSIZE - 1]; } } #define ER(x) cerr << #x << " = " << (x) << endl; #define ERV(v) \ { \ cerr << #v << " : "; \ for (const auto &xxx : v) { \ cerr << xxx << " "; \ } \ cerr << "\n"; \ } inline int YES(bool x) { cout << ((x) ? "YES" : "NO") << endl; return 0; } inline int Yes(bool x) { cout << ((x) ? "Yes" : "No") << endl; return 0; } inline int yes(bool x) { cout << ((x) ? "yes" : "no") << endl; return 0; } inline int yES(bool x) { cout << ((x) ? "yES" : "nO") << endl; return 0; } inline int Yay(bool x) { cout << ((x) ? "Yay!" : ":(") << endl; return 0; } template <typename A, typename B> void sankou(bool x, A a, B b) { cout << ((x) ? (a) : (b)) << endl; } #define _overload3(_1, _2, _3, name, ...) name #define _REP(i, n) REPI(i, 0, n) #define REPI(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define REP(...) _overload3(__VA_ARGS__, REPI, _REP, )(__VA_ARGS__) #define _RREP(i, n) RREPI(i, n, 0) #define RREPI(i, a, b) for (ll i = ll(a); i >= ll(b); --i) #define RREP(...) _overload3(__VA_ARGS__, RREPI, _RREP, )(__VA_ARGS__) #define EACH(e, v) for (auto &e : v) #define PERM(v) \ sort((v).begin(), (v).end()); \ for (bool c##p = 1; c##p; c##p = next_permutation((v).begin(), (v).end())) #define ADD(a, b) a = (a + ll(b)) % MOD #define MUL(a, b) a = (a * ll(b)) % MOD inline ll MOP(ll x, ll n, ll m = MOD) { ll r = 1; while (n > 0) { if (n & 1) (r *= x) %= m; (x *= x) %= m; n >>= 1; } return r; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); } inline ll POW(ll a, ll b) { ll c = 1ll; do { if (b & 1) c *= 1ll * a; a *= 1ll * a; } while (b >>= 1); return c; } template <typename T, typename A, typename B> inline bool between(T x, A a, B b) { return ((a <= x) && (x < b)); } template <class T> inline T sqr(T x) { return x * x; } template <typename A, typename B> inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return 1; } return 0; } #define tmax(x, y, z) max((x), max((y), (z))) #define tmin(x, y, z) min((x), min((y), (z))) #define PB push_back #define MP make_pair #define MT make_tuple #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define EXIST(s, e) (find((s).begin(), (s).end(), (e)) != (s).end()) #define EXISTST(s, c) (((s).find(c)) != string::npos) #define POSL(x, val) (lower_bound(x.begin(), x.end(), val) - x.begin()) #define POSU(x, val) (upper_bound(x.begin(), x.end(), val) - x.begin()) #define GEQ(x, val) (int)(x).size() - POSL((x), (val)) #define GREATER(x, val) (int)(x).size() - POSU((x), (val)) #define LEQ(x, val) POSU((x), (val)) #define LESS(x, val) POSL((x), (val)) #define SZV(a) int((a).size()) #define SZA(a) sizeof(a) / sizeof(a[0]) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMINF(a) memset(a, 0x3f, sizeof(a)) #define FILL(a, b) memset(a, b, sizeof(a)) #define UNIQUE(v) \ sort((v).begin(), (v).end()); \ (v).erase(unique((v).begin(), (v).end()), (v).end()) struct abracadabra { abracadabra() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); cerr << fixed << setprecision(5); }; } ABRACADABRA; //---------------8<---------------8<---------------8<---------------8<---------------// ll N, K; vl A; ll dp[44][2]; ll rec(ll digit, bool strict, ll val = 0) { if (digit < 0) return val; auto &ret = dp[digit][strict]; debug(digit, strict, ret, val); // if (ret != -1) return ret = max(ret, val); ll mask = 1LL << digit; int num = 0; EACH(e, A) if (e & mask)++ num; ll zero = mask * num, one = mask * (N - num); if (strict) { if (K & mask) { // 1 -> strict = true // 0 -> strict = false return ret = max<ll>(rec(digit - 1, true, val + one), rec(digit - 1, false, val + zero)); } else { // 0のみ -> strict = true return ret = rec(digit - 1, true, val + zero); } } else { // 1でも0でも strict = false return ret = rec(digit - 1, false, val + max<ll>(one, zero)); } } signed main() { cin >> N >> K; A.resize(N); REP(i, N) cin >> A[i]; MINUS(dp); cout << rec(4, true) << ln; }
#include <bits/stdc++.h> using namespace std; #define int long long typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<string> vst; typedef vector<bool> vb; typedef vector<ld> vld; typedef vector<pii> vpii; typedef vector<pll> vpll; typedef vector<vector<int>> vvi; const int INF = (0x7FFFFFFFL); const ll INFF = (0x7FFFFFFFFFFFFFFFL); const string ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const int MOD = 1e9 + 7; const int MODD = 998244353; const string alphabet = "abcdefghijklmnopqrstuvwxyz"; const double PI = acos(-1.0); const double EPS = 1e-9; const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; int dx[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0}; int dy[9] = {0, 1, 0, -1, -1, -1, 1, 1, 0}; #define ln '\n' #define scnaf scanf #define sacnf scanf #define sancf scanf #define SS(type, ...) \ type __VA_ARGS__; \ MACRO_VAR_Scan(__VA_ARGS__); template <typename T> void MACRO_VAR_Scan(T &t) { cin >> t; } template <typename First, typename... Rest> void MACRO_VAR_Scan(First &first, Rest &...rest) { cin >> first; MACRO_VAR_Scan(rest...); } #define SV(type, c, n) \ vector<type> c(n); \ for (auto &i : c) \ cin >> i; #define SVV(type, c, n, m) \ vector<vector<type>> c(n, vector<type>(m)); \ for (auto &r : c) \ for (auto &i : r) \ cin >> i; template <class T> ostream &operator<<(ostream &o, const vector<T> &j) { o << "{"; for (int i = 0; i < (int)j.size(); ++i) o << (i > 0 ? ", " : "") << j[i]; o << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const pair<T, U> &j) { o << "{" << j.first << ", " << j.second << "}"; return o; } template <class T, class U> ostream &operator<<(ostream &o, const map<T, U> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } template <class T> ostream &operator<<(ostream &o, const set<T> &j) { o << "{"; for (auto t = j.begin(); t != j.end(); ++t) o << (t != j.begin() ? ", " : "") << *t; o << "}"; return o; } inline int print(void) { cout << endl; return 0; } template <class Head> int print(Head &&head) { cout << head; print(); return 0; } template <class Head, class... Tail> int print(Head &&head, Tail &&...tail) { cout << head << " "; print(forward<Tail>(tail)...); return 0; } inline int debug(void) { cerr << endl; return 0; } template <class Head> int debug(Head &&head) { cerr << head; debug(); return 0; } template <class Head, class... Tail> int debug(Head &&head, Tail &&...tail) { cerr << head << " "; debug(forward<Tail>(tail)...); return 0; } template <typename T> void PA(T &a) { int ASIZE = sizeof(a) / sizeof(a[0]); for (int ii = 0; ii < ASIZE; ++ii) { cout << a[ii] << " \n"[ii == ASIZE - 1]; } } template <typename T> void PV(T &v) { int VSIZE = v.size(); for (int ii = 0; ii < VSIZE; ++ii) { cout << v[ii] << " \n"[ii == VSIZE - 1]; } } #define ER(x) cerr << #x << " = " << (x) << endl; #define ERV(v) \ { \ cerr << #v << " : "; \ for (const auto &xxx : v) { \ cerr << xxx << " "; \ } \ cerr << "\n"; \ } inline int YES(bool x) { cout << ((x) ? "YES" : "NO") << endl; return 0; } inline int Yes(bool x) { cout << ((x) ? "Yes" : "No") << endl; return 0; } inline int yes(bool x) { cout << ((x) ? "yes" : "no") << endl; return 0; } inline int yES(bool x) { cout << ((x) ? "yES" : "nO") << endl; return 0; } inline int Yay(bool x) { cout << ((x) ? "Yay!" : ":(") << endl; return 0; } template <typename A, typename B> void sankou(bool x, A a, B b) { cout << ((x) ? (a) : (b)) << endl; } #define _overload3(_1, _2, _3, name, ...) name #define _REP(i, n) REPI(i, 0, n) #define REPI(i, a, b) for (ll i = ll(a); i < ll(b); ++i) #define REP(...) _overload3(__VA_ARGS__, REPI, _REP, )(__VA_ARGS__) #define _RREP(i, n) RREPI(i, n, 0) #define RREPI(i, a, b) for (ll i = ll(a); i >= ll(b); --i) #define RREP(...) _overload3(__VA_ARGS__, RREPI, _RREP, )(__VA_ARGS__) #define EACH(e, v) for (auto &e : v) #define PERM(v) \ sort((v).begin(), (v).end()); \ for (bool c##p = 1; c##p; c##p = next_permutation((v).begin(), (v).end())) #define ADD(a, b) a = (a + ll(b)) % MOD #define MUL(a, b) a = (a * ll(b)) % MOD inline ll MOP(ll x, ll n, ll m = MOD) { ll r = 1; while (n > 0) { if (n & 1) (r *= x) %= m; (x *= x) %= m; n >>= 1; } return r; } inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } inline ll lcm(ll a, ll b) { return a * b / gcd(a, b); } inline ll POW(ll a, ll b) { ll c = 1ll; do { if (b & 1) c *= 1ll * a; a *= 1ll * a; } while (b >>= 1); return c; } template <typename T, typename A, typename B> inline bool between(T x, A a, B b) { return ((a <= x) && (x < b)); } template <class T> inline T sqr(T x) { return x * x; } template <typename A, typename B> inline bool chmax(A &a, const B &b) { if (a < b) { a = b; return 1; } return 0; } template <typename A, typename B> inline bool chmin(A &a, const B &b) { if (a > b) { a = b; return 1; } return 0; } #define tmax(x, y, z) max((x), max((y), (z))) #define tmin(x, y, z) min((x), min((y), (z))) #define PB push_back #define MP make_pair #define MT make_tuple #define all(v) (v).begin(), (v).end() #define rall(v) (v).rbegin(), (v).rend() #define SORT(v) sort((v).begin(), (v).end()) #define RSORT(v) sort((v).rbegin(), (v).rend()) #define EXIST(s, e) (find((s).begin(), (s).end(), (e)) != (s).end()) #define EXISTST(s, c) (((s).find(c)) != string::npos) #define POSL(x, val) (lower_bound(x.begin(), x.end(), val) - x.begin()) #define POSU(x, val) (upper_bound(x.begin(), x.end(), val) - x.begin()) #define GEQ(x, val) (int)(x).size() - POSL((x), (val)) #define GREATER(x, val) (int)(x).size() - POSU((x), (val)) #define LEQ(x, val) POSU((x), (val)) #define LESS(x, val) POSL((x), (val)) #define SZV(a) int((a).size()) #define SZA(a) sizeof(a) / sizeof(a[0]) #define ZERO(a) memset(a, 0, sizeof(a)) #define MINUS(a) memset(a, 0xff, sizeof(a)) #define MEMINF(a) memset(a, 0x3f, sizeof(a)) #define FILL(a, b) memset(a, b, sizeof(a)) #define UNIQUE(v) \ sort((v).begin(), (v).end()); \ (v).erase(unique((v).begin(), (v).end()), (v).end()) struct abracadabra { abracadabra() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20); cerr << fixed << setprecision(5); }; } ABRACADABRA; //---------------8<---------------8<---------------8<---------------8<---------------// ll N, K; vl A; ll dp[44][2]; ll rec(ll digit, bool strict, ll val = 0) { if (digit < 0) return val; auto &ret = dp[digit][strict]; debug(digit, strict, ret, val); // if (ret != -1) return ret = max(ret, val); ll mask = 1LL << digit; int num = 0; EACH(e, A) if (e & mask)++ num; ll zero = mask * num, one = mask * (N - num); if (strict) { if (K & mask) { // 1 -> strict = true // 0 -> strict = false return ret = max<ll>(rec(digit - 1, true, val + one), rec(digit - 1, false, val + zero)); } else { // 0のみ -> strict = true return ret = rec(digit - 1, true, val + zero); } } else { // 1でも0でも strict = false return ret = rec(digit - 1, false, val + max<ll>(one, zero)); } } signed main() { cin >> N >> K; A.resize(N); REP(i, N) cin >> A[i]; MINUS(dp); cout << rec(43, true) << ln; }
[ "literal.number.change", "io.output.change" ]
939,703
939,704
u832039789
cpp
p03138
#include <iostream> #include <algorithm> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iomanip> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long LL; typedef unsigned int UI; #define rSort(a) sort(a.rbegin(), a.rend()) #define Sort(a) sort(a.begin(), a.end()) #define Sum(a) accumulate(a.begin(), a.end(), 0) #define REP(i, n) for (UI i = 0; i < n; i++) #define REPR(i, n) for (UI i = n; i >= 0; i--) #define FOR(i, m, n) for (UI i = m; i < n; i++) LL N, K, s[60], dp[60][2]; int main(int argc, const char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; REP(i, N) { LL a; cin >> a; REP(j, 50) if (a & (1ll << j)) s[j]++; } reverse(s, s + 50); REP(i, 50) { if (K & ((1ll << 50) - i - 1)) { dp[i + 1][0] = dp[i][0] * 2 + N - s[i]; dp[i + 1][1] = dp[i][0] * 2 + s[i]; } else dp[i + 1][0] = dp[i][0] * 2 + s[i]; if (dp[i][1] > 0) dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] * 2 + max(N - s[i], s[i])); } cout << max(dp[50][0], dp[50][1]) << endl; return 0; }
#include <iostream> #include <algorithm> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <functional> #include <iomanip> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; typedef long long LL; typedef unsigned int UI; #define rSort(a) sort(a.rbegin(), a.rend()) #define Sort(a) sort(a.begin(), a.end()) #define Sum(a) accumulate(a.begin(), a.end(), 0) #define REP(i, n) for (UI i = 0; i < n; i++) #define REPR(i, n) for (UI i = n; i >= 0; i--) #define FOR(i, m, n) for (UI i = m; i < n; i++) LL N, K, s[60], dp[60][2]; int main(int argc, const char *argv[]) { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; REP(i, N) { LL a; cin >> a; REP(j, 50) if (a & (1ll << j)) s[j]++; } reverse(s, s + 50); REP(i, 50) { if (K & (1ll << (50 - i - 1))) { dp[i + 1][0] = dp[i][0] * 2 + N - s[i]; dp[i + 1][1] = dp[i][0] * 2 + s[i]; } else dp[i + 1][0] = dp[i][0] * 2 + s[i]; if (dp[i][1] > 0) dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] * 2 + max(N - s[i], s[i])); } cout << max(dp[50][0], dp[50][1]) << endl; return 0; }
[ "control_flow.branch.if.condition.change" ]
939,707
939,708
u335104842
cpp
p03138
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define REPO(i, n) for (int i = 1; i <= n; i++) #define ll long long #define INF 1999999999 #define MINF -1999999999 #define INF64 1999999999999999999 #define ALL(n) n.begin(), n.end() ll N, K, s[60], dp1[60], dp2[60], p = 1; int main() { cin >> N >> K; REP(i, N) { ll a; cin >> a; REP(j, 50) if (a & (1ll << j)) s[j]++; } REP(i, 50) { dp1[i + 1] = dp1[i] + max(s[i], N - s[i]); if (K & (1ll << i)) dp2[i + 1] = max((N - s[i]) * p + dp2[i], s[i] * p + dp1[i]); else dp2[i + 1] = s[i] * p + dp2[i]; p *= 2; } cout << dp2[50] << endl; }
#include <algorithm> #include <cmath> #include <cstdlib> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <utility> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define FORR(i, m, n) for (int i = m; i >= n; i--) #define REPO(i, n) for (int i = 1; i <= n; i++) #define ll long long #define INF 1999999999 #define MINF -1999999999 #define INF64 1999999999999999999 #define ALL(n) n.begin(), n.end() ll N, K, s[60], dp1[60], dp2[60], p = 1; int main() { cin >> N >> K; REP(i, N) { ll a; cin >> a; REP(j, 50) if (a & (1ll << j)) s[j]++; } REP(i, 50) { dp1[i + 1] = dp1[i] + max(s[i], N - s[i]) * p; if (K & (1ll << i)) dp2[i + 1] = max((N - s[i]) * p + dp2[i], s[i] * p + dp1[i]); else dp2[i + 1] = s[i] * p + dp2[i]; p *= 2; } cout << dp2[50] << endl; }
[ "assignment.change" ]
939,721
939,722
u196497077
cpp
p03138
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; const long long INF = LLONG_MAX / 2; int main() { int n; long long m; cin >> n >> m; vector<long long> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector<long long> dp(2, -INF); dp[0] = 0; for (int i = 50; i >= 0; --i) { vector<long long> nextDp(2, -INF); int cnt = 0; for (int j = 0; j < n; ++j) { if (a[j] & (1LL << i)) ++cnt; } for (int j = 0; j < 2; ++j) { for (int x = 0; x < 2; ++x) { if (j == 0 && x == 1 && !(m & (1LL << i))) continue; int k = j; if (x == 1 && !(m & (1LL << i))) k = 1; nextDp[k] = max(nextDp[k], dp[j] + (1LL << i) * (x ? n - cnt : cnt)); } } dp = move(nextDp); } long long ans = *max_element(dp.begin(), dp.end()); cout << ans << endl; return 0; }
#define _USE_MATH_DEFINES #include <algorithm> #include <array> #include <bitset> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <fstream> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <memory> #include <numeric> #include <queue> #include <regex> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; const long long INF = LLONG_MAX / 2; int main() { int n; long long m; cin >> n >> m; vector<long long> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector<long long> dp(2, -INF); dp[0] = 0; for (int i = 40; i >= 0; --i) { vector<long long> nextDp(2, -INF); int cnt = 0; for (int j = 0; j < n; ++j) { if (a[j] & (1LL << i)) ++cnt; } for (int j = 0; j < 2; ++j) { for (int x = 0; x < 2; ++x) { if (j == 0 && x == 1 && !(m & (1LL << i))) continue; int k = j; if (x == 0 && (m & (1LL << i))) k = 1; nextDp[k] = max(nextDp[k], dp[j] + (1LL << i) * (x ? n - cnt : cnt)); } } dp = move(nextDp); } long long ans = *max_element(dp.begin(), dp.end()); cout << ans << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "control_flow.branch.if.condition.change", "expression.operation.unary.logical.remove" ]
939,729
939,728
u917944707
cpp
p03138
#include <bits/stdc++.h> using namespace std; int n; long long int k; long long int sum; int cnt[40]; long long int dfs(int i, int f, long long int d) { if (i < 0) { return sum + d; } if (f) { return dfs(i - 1, 1, d + max(0LL, (1LL << i) * (n - cnt[i] - cnt[i]))); } else { if (k >> i & 1) { return max(dfs(i - 1, 1, d), dfs(i - 1, 0, (1LL << i) * (n - cnt[i] - cnt[i]))); } else { return dfs(i - 1, 0, d); } } return 0LL; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { long long int a; cin >> a; sum += a; for (int j = 0; j < 40; j++) { cnt[j] += a >> j & 1; } } cout << dfs(41, 0, 0) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int n; long long int k; long long int sum; int cnt[40]; long long int dfs(int i, int f, long long int d) { if (i < 0) { return sum + d; } if (f) { return dfs(i - 1, 1, d + max(0LL, (1LL << i) * (n - cnt[i] - cnt[i]))); } else { if (k >> i & 1) { return max(dfs(i - 1, 1, d), dfs(i - 1, 0, d + (1LL << i) * (n - cnt[i] - cnt[i]))); } else { return dfs(i - 1, 0, d); } } return 0LL; } int main() { cin >> n >> k; for (int i = 0; i < n; i++) { long long int a; cin >> a; sum += a; for (int j = 0; j < 40; j++) { cnt[j] += a >> j & 1; } } cout << dfs(41, 0, 0) << endl; return 0; }
[ "expression.operation.binary.add" ]
939,739
939,740
u810067372
cpp
p03138
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<long long int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> cnt(40, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < 40; j++) { cnt[j] += a[i] >> j & 1; } } long long int sum = 0LL; for (int i = 0; i < n; i++) { sum += a[i]; } long long int ans = 0LL; long long int now = 0LL; for (int i = 40; i >= 0; i--) { int bit = k >> i & 1; if (bit) { long long int d = 0LL; for (int j = i - 1; j >= 0; j--) { d += max(0LL, (1LL << j) * (n - cnt[i] - cnt[i])); } ans = max(ans, sum + now + d); now += (1LL << i) * (n - cnt[i] - cnt[i]); } } ans = max(ans, sum + now); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<long long int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> cnt(40, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < 40; j++) { cnt[j] += a[i] >> j & 1; } } long long int sum = 0LL; for (int i = 0; i < n; i++) { sum += a[i]; } long long int ans = 0LL; long long int now = 0LL; for (int i = 40; i >= 0; i--) { int bit = k >> i & 1; if (bit) { long long int d = 0LL; for (int j = i - 1; j >= 0; j--) { d += max(0LL, (1LL << j) * (n - cnt[j] - cnt[j])); } ans = max(ans, sum + now + d); now += (1LL << i) * (n - cnt[i] - cnt[i]); } } ans = max(ans, sum + now); cout << ans << endl; return 0; }
[ "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
939,741
939,742
u810067372
cpp
p03138
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<long long int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> cnt(40, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < 40; j++) { cnt[j] += a[i] >> j & 1; } } long long int sum = 0LL; for (int i = 0; i < n; i++) { sum += a[i]; } long long int ans = 0LL; long long int now = 0LL; for (int i = 40; i >= 0; i--) { int bit = k >> i & 1; if (bit) { long long int d = 0LL; for (int j = i - 1; j >= 0; j--) { d += max(0LL, (1 << j) * (n - cnt[i] - cnt[i])); } ans = max(ans, sum + now + d); now += (1 << i) * (n - cnt[i] - cnt[i]); } } ans = max(ans, sum + now); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int n, k; cin >> n >> k; vector<long long int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } vector<int> cnt(40, 0); for (int i = 0; i < n; i++) { for (int j = 0; j < 40; j++) { cnt[j] += a[i] >> j & 1; } } long long int sum = 0LL; for (int i = 0; i < n; i++) { sum += a[i]; } long long int ans = 0LL; long long int now = 0LL; for (int i = 40; i >= 0; i--) { int bit = k >> i & 1; if (bit) { long long int d = 0LL; for (int j = i - 1; j >= 0; j--) { d += max(0LL, (1LL << j) * (n - cnt[j] - cnt[j])); } ans = max(ans, sum + now + d); now += (1LL << i) * (n - cnt[i] - cnt[i]); } } ans = max(ans, sum + now); cout << ans << endl; return 0; }
[ "call.arguments.change", "assignment.value.change", "identifier.change", "variable_access.subscript.index.change", "expression.operation.binary.change", "literal.number.type.widen.change" ]
939,743
939,742
u810067372
cpp
p03138
#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; constexpr ld EPS = 1e-12; constexpr int INF = numeric_limits<int>::max() / 2; constexpr int MOD = 1e9 + 7; template <typename T> void printv(const vector<T> &v) { int sz = v.size(); for (int i = 0; i < sz; i++) { cout << v[i] << " \n"[i == sz - 1]; } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; vector<ll> a(N), cnt(60, 0); ll res = 0; for (int i = 0; i < N; i++) { cin >> a[i]; res += a[i]; for (int j = 0; j < 50; j++) { if ((a[i] >> j) & 1) cnt[j]++; } } for (int i = 0; (1LL << i) <= K; i++) { ll mask = 0; for (int j = i; j >= 0; j--) { if ((mask | ((1LL << j) <= K)) && 2 * cnt[j] < N) { mask |= (1LL << j); } } ll sum = 0; for (int j = 0; j < N; j++) sum += (a[j] ^ mask); res = max(res, sum); } cout << res << endl; }
#include "bits/stdc++.h" using namespace std; using ll = long long; using ld = long double; using P = pair<int, int>; constexpr ld EPS = 1e-12; constexpr int INF = numeric_limits<int>::max() / 2; constexpr int MOD = 1e9 + 7; template <typename T> void printv(const vector<T> &v) { int sz = v.size(); for (int i = 0; i < sz; i++) { cout << v[i] << " \n"[i == sz - 1]; } } int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; vector<ll> a(N), cnt(60, 0); ll res = 0; for (int i = 0; i < N; i++) { cin >> a[i]; res += a[i]; for (int j = 0; j < 50; j++) { if ((a[i] >> j) & 1) cnt[j]++; } } for (int i = 0; (1LL << i) <= K; i++) { ll mask = 0; for (int j = i; j >= 0; j--) { if ((mask | (1LL << j)) <= K && 2 * cnt[j] < N) { mask |= (1LL << j); } } ll sum = 0; for (int j = 0; j < N; j++) sum += (a[j] ^ mask); res = max(res, sum); } cout << res << endl; }
[ "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
939,758
939,759
u968834127
cpp
p03138
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, k, a; cin >> n >> k; int j; vector<int> t; int y = 1; for (int i = 0; i < n; i++) { cin >> a; j = 0; while (a != 0 && j < t.size()) { t[j] += a % 2; a = a / 2; j++; } while (a != 0) { t.push_back(a % 2); a = a / 2; y *= 2; } } while ((k / y) != 0) { t.push_back(0); y *= 2; } int an[t.size()]; an[0] = max(t[0], n - t[0]); y = 2; for (int i = 1; i < t.size(); i++) { an[i] = an[i - 1] + max(t[i] * y, (n - t[0]) * y); y *= 2; } int p = 0, ans = 0; y /= 2; for (int i = t.size() - 1; i > 0; i--) { // cerr << ans << ' '; if ((k % (2 * y)) / y != 0) { ans = max(ans, p + t[i] * y + an[i - 1]); p += (n - t[i]) * y; } else p += t[i] * y; y /= 2; } // cerr << ans << ' '; if (k % 2 != 0) ans = max(ans, p + (n - t[0])); // cerr << ans << ' '; ans = max(ans, p + t[0]); cout << ans; return 0; }
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { int n, k, a; cin >> n >> k; int j; vector<int> t; int y = 1; for (int i = 0; i < n; i++) { cin >> a; j = 0; while (a != 0 && j < t.size()) { t[j] += a % 2; a = a / 2; j++; } while (a != 0) { t.push_back(a % 2); a = a / 2; y *= 2; } } while ((k / y) != 0) { t.push_back(0); y *= 2; } int an[t.size()]; an[0] = max(t[0], n - t[0]); y = 2; for (int i = 1; i < t.size(); i++) { an[i] = an[i - 1] + max(t[i] * y, (n - t[i]) * y); y *= 2; } int p = 0, ans = 0; y /= 2; for (int i = t.size() - 1; i > 0; i--) { // cerr << ans << ' '; if ((k % (2 * y)) / y != 0) { ans = max(ans, p + t[i] * y + an[i - 1]); p += (n - t[i]) * y; } else p += t[i] * y; y /= 2; } // cerr << ans << ' '; if (k % 2 != 0) ans = max(ans, p + (n - t[0])); // cerr << ans << ' '; ans = max(ans, p + t[0]); cout << ans; return 0; }
[ "assignment.value.change", "identifier.replace.add", "literal.replace.remove", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
939,762
939,763
u651317892
cpp
p03138
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long K; cin >> K; vector<long long> A(N); for (auto &a : A) cin >> a; long long best = 0; for (long long bit = 1LL << 40; bit; bit >>= 1) { int cnt = 0; for (auto a : A) if (a & bit) cnt++; if (cnt <= N / 2) best |= bit; } // cout<<"best"<<best<<"\n"; long long ans = 0; for (auto a : A) ans += a ^ K; // X == K for (long long bit = 1LL << 40; bit; bit >>= 1) { if (K & bit) { long long X = (K & ~(bit - 1) & ~bit) | (best ^ (bit - 1)); long long f = 0; for (auto a : A) f += a ^ X; ans = max(ans, f); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long K; cin >> K; vector<long long> A(N); for (auto &a : A) cin >> a; long long best = 0; for (long long bit = 1LL << 40; bit; bit >>= 1) { int cnt = 0; for (auto a : A) if (a & bit) cnt++; if (cnt <= N / 2) best |= bit; } // cout<<"best"<<best<<"\n"; long long ans = 0; for (auto a : A) ans += a ^ K; // X == K for (long long bit = 1LL << 40; bit; bit >>= 1) { if (K & bit) { long long X = (K & ~(bit - 1) & ~bit) | (best & (bit - 1)); long long f = 0; for (auto a : A) f += a ^ X; ans = max(ans, f); } } cout << ans << endl; return 0; }
[ "expression.operation.binary.change" ]
939,768
939,769
u207685829
cpp
p03138
#include <bits/stdc++.h> #define f(i, p, q) for (int i = p; i < q; i++) using namespace std; typedef long long ll; long long int ar[64]; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); long long int n, k; cin >> n >> k; long long int t; int l = 0; long long int m = n; vector<long long int> v; for (int i = 0; i < n; i++) { long long int x; cin >> x; v.push_back(x); t = x; long long int index = 0; while (t != 0) { if ((t & 1) == 1) ar[index]++; index++; t = t >> 1; } } long long int ans = 0; for (int i = 40; i >= 0; i--) { long long int u = (1ll << i); if (m - ar[i] > ar[i] && (ans | u <= k)) ans = ans | u; // cout<<i<<" "<<ar[i]<<" "<<ans<<"\n"; } long long int res = 0; for (int i = 0; i < m; i++) res += ans ^ v[i]; cout << res; }
#include <bits/stdc++.h> #define f(i, p, q) for (int i = p; i < q; i++) using namespace std; typedef long long ll; long long int ar[64]; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); long long int n, k; cin >> n >> k; long long int t; int l = 0; long long int m = n; vector<long long int> v; for (int i = 0; i < n; i++) { long long int x; cin >> x; v.push_back(x); t = x; long long int index = 0; while (t != 0) { if ((t & 1) == 1) ar[index]++; index++; t = t >> 1; } } long long int ans = 0; for (int i = 40; i >= 0; i--) { long long int u = (1ll << i); if (m - ar[i] > ar[i] && ((ans ^ u) <= k)) ans = ans ^ u; // cout<<i<<" "<<ar[i]<<" "<<ans<<"\n"; } long long int res = 0; for (int i = 0; i < m; i++) res += ans ^ v[i]; cout << res; }
[ "control_flow.branch.if.condition.change", "assignment.value.change", "expression.operation.binary.change" ]
939,774
939,775
u207685829
cpp
p03138
#include <bits/stdc++.h> #define f(i, p, q) for (int i = p; i < q; i++) using namespace std; typedef long long ll; int ar[64]; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); long long int n, k; cin >> n >> k; long long int t; int l = 0; long long int m = n; vector<long long int> v; for (int i = 0; i < n; i++) { int x; cin >> x; v.push_back(x); t = x; long long int index = 0; while (t != 0) { if ((t & 1) == 1) ar[index]++; index++; t = t >> 1; } } long long int ans = 0; for (int i = 40; i >= 0; i--) { long long int u = (1 << i); if (m - ar[i] > ar[i] && (ans + u <= k)) ans = ans + u; // cout<<i<<" "<<ar[i]<<" "<<ans<<"\n"; } long long int res = 0; for (int i = 0; i < m; i++) res += ans ^ v[i]; cout << res; }
#include <bits/stdc++.h> #define f(i, p, q) for (int i = p; i < q; i++) using namespace std; typedef long long ll; long long int ar[64]; int main() { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); long long int n, k; cin >> n >> k; long long int t; int l = 0; long long int m = n; vector<long long int> v; for (int i = 0; i < n; i++) { long long int x; cin >> x; v.push_back(x); t = x; long long int index = 0; while (t != 0) { if ((t & 1) == 1) ar[index]++; index++; t = t >> 1; } } long long int ans = 0; for (int i = 40; i >= 0; i--) { long long int u = (1ll << i); if (m - ar[i] > ar[i] && (ans + u <= k)) ans = ans + u; // cout<<i<<" "<<ar[i]<<" "<<ans<<"\n"; } long long int res = 0; for (int i = 0; i < m; i++) res += ans ^ v[i]; cout << res; }
[ "variable_declaration.type.widen.change" ]
939,779
939,778
u207685829
cpp
p03138
#include <bits/stdc++.h> using namespace std; #define lint long long #define P pair<int, int> int main() { lint N, K; cin >> N >> K; vector<lint> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } int bits = 0; const lint INF = -1E18; while (((lint)1 << bits) < K) { bits++; } lint cnt[50]; for (int i = 0; i < 50; ++i) { cnt[i] = 0; for (int j = 0; j < N; ++j) { cnt[i] += (A[j] >> i) & 1; } } lint dp[50][2]; dp[49][0] = 0; dp[49][1] = INF; for (int i = 49; i > 0; --i) { if ((K >> (i - 1)) & 1) { dp[i - 1][0] = dp[i][0] + ((lint)1 << (i - 1)) * (N - cnt[i - 1]); dp[i - 1][1] = max(dp[i][1] + ((lint)1 << (i - 1)) * (cnt[i - 1]), dp[i][0] + ((lint)1 << (i - 1)) * max(cnt[i - 1], N - cnt[i - 1])); // cerr << 1 << " " << cnt[i -1] << " " << dp[i- 1][0] << " " // << dp[i - 1][1] << endl; } else { dp[i - 1][0] = dp[i][0] + ((lint)1 << (i - 1)) * cnt[i - 1]; if (dp[i][1] > INF) { dp[i - 1][1] = dp[i][1] + ((lint)1 << (i - 1)) * max(cnt[i - 1], N - cnt[i - 1]); } else { dp[i - 1][1] = dp[i][1]; } // cerr << 0 << " " << cnt[i -1] << " " << dp[i- 1][0] << " " // << dp[i - 1][1] << endl; } } cout << max(dp[0][0], dp[0][1]) << endl; }
#include <bits/stdc++.h> using namespace std; #define lint long long #define P pair<int, int> int main() { lint N, K; cin >> N >> K; vector<lint> A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } int bits = 0; const lint INF = -1E18; while (((lint)1 << bits) < K) { bits++; } lint cnt[50]; for (int i = 0; i < 50; ++i) { cnt[i] = 0; for (int j = 0; j < N; ++j) { cnt[i] += (A[j] >> i) & 1; } } lint dp[50][2]; dp[49][0] = 0; dp[49][1] = INF; for (int i = 49; i > 0; --i) { if ((K >> (i - 1)) & 1) { dp[i - 1][0] = dp[i][0] + ((lint)1 << (i - 1)) * (N - cnt[i - 1]); dp[i - 1][1] = max(dp[i][0] + ((lint)1 << (i - 1)) * (cnt[i - 1]), dp[i][1] + ((lint)1 << (i - 1)) * max(cnt[i - 1], N - cnt[i - 1])); // cerr << 1 << " " << cnt[i -1] << " " << dp[i- 1][0] << " " // << dp[i - 1][1] << endl; } else { dp[i - 1][0] = dp[i][0] + ((lint)1 << (i - 1)) * cnt[i - 1]; if (dp[i][1] > INF) { dp[i - 1][1] = dp[i][1] + ((lint)1 << (i - 1)) * max(cnt[i - 1], N - cnt[i - 1]); } else { dp[i - 1][1] = dp[i][1]; } // cerr << 0 << " " << cnt[i -1] << " " << dp[i- 1][0] << " " // << dp[i - 1][1] << endl; } } cout << max(dp[0][0], dp[0][1]) << endl; }
[ "literal.number.change", "assignment.value.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change" ]
939,782
939,783
u432456012
cpp
p03138
#include <algorithm> #include <iostream> #include <set> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; ll n, k; vector<ll> a; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { ll x; cin >> x; a.push_back(x); } ll num = 0; for (int i = 42; i >= 0; i--) { int one_sum = 0, zero_sum = 0; for (int j = 0; j < n; j++) { if (((a[i] >> i) & 1ll)) one_sum++; else zero_sum++; } if (zero_sum > one_sum && (num + (1ll << i)) <= k) num += (1ll << i); } ll ans = 0; for (int i = 0; i < n; i++) ans += (num ^ a[i]); cout << ans << endl; return 0; }
#include <algorithm> #include <iostream> #include <set> #include <unordered_set> #include <vector> using namespace std; typedef long long ll; ll n, k; vector<ll> a; int main() { cin >> n >> k; for (int i = 0; i < n; i++) { ll x; cin >> x; a.push_back(x); } ll num = 0; for (ll i = 42; i >= 0; i--) { int one_sum = 0, zero_sum = 0; for (int j = 0; j < n; j++) { if (((a[j] >> i) & 1ll)) one_sum++; else zero_sum++; } if (zero_sum > one_sum && (num + (1ll << i)) <= k) num += (1ll << i); } ll ans = 0; for (int i = 0; i < n; i++) ans += (num ^ a[i]); cout << ans << endl; return 0; }
[ "control_flow.loop.for.initializer.change", "variable_declaration.type.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
939,784
939,785
u656732735
cpp
p03138
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <string> #include <vector> using namespace std; using ll = long long int; ll n, k; ll calcBit(ll target) { ll count = 1; while (target > 1) { target /= 2; count++; } return count; } ll calcCount(vector<ll> &x, ll offset, ll target) { ll count = 0; ll index = 1ll << offset; for (ll i = 0; i < x.size(); i++) { if (x[i] & index) { count++; } } if (target == 0) { return x.size() - count; } else { return count; } } void dfs(vector<vector<ll>> &dp, vector<vector<bool>> &flag, vector<ll> x, ll index, int smaller) { /* * 桁DP用のDFS関数 * smaller=0のときkに忠実に探索 * samller=1のとき以降どんな値でも良い * indexは桁数 */ //最初に到達済みか判断 //到達済みならdp[index][smaller]の値を返す if (flag[index][smaller]) return; flag[index][smaller] = true; // 0,1の増加分を計算 ll count0 = calcCount(x, index, 0); ll count1 = calcCount(x, index, 1); ll plus0 = count1 << index; ll plus1 = count0 << index; // index == 0のときはdfsを呼ばずに結果を返す ll result = 0; if (index == 0) { if (smaller == 0) { //忠実なので自身の桁を選んだ増加分を返す if (k & (1ll << index)) { result = max(plus1, plus0); } else { result = plus0; } } else { //自由なのでplus0とplus1の大きい方を返す result = max(plus0, plus1); } dp[index][smaller] = result; // cout << "index = " << index << " smaller = " << smaller << " result = " // << result << endl; return; } //忠実に探索するパターンと自由に探索するパターンを呼び出し dfs(dp, flag, x, index - 1, 0); dfs(dp, flag, x, index - 1, 1); // dpの更新 if (smaller == 0) { // exactly -> smaller //忠実から自由なので1桁小さいsmallerに今の桁の数字を選んだときの増加分を足す if (k & (1ll << index)) { result = max(result, dp[index - 1][1] + plus1); } // exactly -> exactly //忠実から忠実なので1桁小さいexactlyに今の桁の数字を選んだときの増加分を足す if (k & (1ll << index)) { result = max(result, dp[index - 1][0] + plus1); } else { result = max(result, dp[index - 1][0] + plus0); } } else { // smaller -> smaller //自由に配置できるため1桁小さいsmallerにplus0とplus1の大きい方を足す result = max(result, dp[index - 1][1] + max(plus0, plus1)); } dp[index][smaller] = result; // cout << "index = " << index << " smaller = " << smaller << " result = " << // result << endl; } int main() { cin >> n >> k; vector<ll> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } //桁をDFSしながら辿っていく ll bits = calcBit(k); vector<vector<ll>> dp(41, vector<ll>(2, 0)); vector<vector<bool>> flag(41, vector<bool>(2, false)); dfs(dp, flag, x, 40, 0); cout << dp[40][0] << endl; }
#include <algorithm> #include <iostream> #include <map> #include <math.h> #include <string> #include <vector> using namespace std; using ll = long long int; ll n, k; ll calcBit(ll target) { ll count = 1; while (target > 1) { target /= 2; count++; } return count; } ll calcCount(vector<ll> &x, ll offset, ll target) { ll count = 0; ll index = 1ll << offset; for (ll i = 0; i < x.size(); i++) { if (x[i] & index) { count++; } } if (target == 0) { return x.size() - count; } else { return count; } } void dfs(vector<vector<ll>> &dp, vector<vector<bool>> &flag, vector<ll> x, ll index, int smaller) { /* * 桁DP用のDFS関数 * smaller=0のときkに忠実に探索 * samller=1のとき以降どんな値でも良い * indexは桁数 */ //最初に到達済みか判断 //到達済みならdp[index][smaller]の値を返す if (flag[index][smaller]) return; flag[index][smaller] = true; // 0,1の増加分を計算 ll count0 = calcCount(x, index, 0); ll count1 = calcCount(x, index, 1); ll plus0 = count1 << index; ll plus1 = count0 << index; // index == 0のときはdfsを呼ばずに結果を返す ll result = 0; if (index == 0) { if (smaller == 0) { //忠実なので自身の桁を選んだ増加分を返す if (k & (1ll << index)) { result = max(plus1, plus0); } else { result = plus0; } } else { //自由なのでplus0とplus1の大きい方を返す result = max(plus0, plus1); } dp[index][smaller] = result; // cout << "index = " << index << " smaller = " << smaller << " result = " // << result << endl; return; } //忠実に探索するパターンと自由に探索するパターンを呼び出し dfs(dp, flag, x, index - 1, 0); dfs(dp, flag, x, index - 1, 1); // dpの更新 if (smaller == 0) { // exactly -> smaller //忠実から自由なので1桁小さいsmallerに今の桁の数字を選んだときの増加分を足す if (k & (1ll << index)) { result = max(result, dp[index - 1][1] + plus0); } // exactly -> exactly //忠実から忠実なので1桁小さいexactlyに今の桁の数字を選んだときの増加分を足す if (k & (1ll << index)) { result = max(result, dp[index - 1][0] + plus1); } else { result = max(result, dp[index - 1][0] + plus0); } } else { // smaller -> smaller //自由に配置できるため1桁小さいsmallerにplus0とplus1の大きい方を足す result = max(result, dp[index - 1][1] + max(plus0, plus1)); } dp[index][smaller] = result; // cout << "index = " << index << " smaller = " << smaller << " result = " << // result << endl; } int main() { cin >> n >> k; vector<ll> x(n); for (int i = 0; i < n; i++) { cin >> x[i]; } //桁をDFSしながら辿っていく ll bits = calcBit(k); vector<vector<ll>> dp(41, vector<ll>(2, 0)); vector<vector<bool>> flag(41, vector<bool>(2, false)); dfs(dp, flag, x, 40, 0); cout << dp[40][0] << endl; }
[ "assignment.value.change", "identifier.change", "call.arguments.change", "expression.operation.binary.change" ]
939,786
939,787
u432897824
cpp
p03138
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--) #define rrep(i, n) RFOR(i, n, 0) using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; ll A[N]; rep(i, N) cin >> A[i]; // 各ビットごとの1の個数を調べる ll b[61] = {}; for (int i = 60; i >= 0; i--) { ll y = 1LL << i; int cnt = 0; rep(i, N) { if (A[i] & y) cnt++; } b[i] = cnt; } // for(int i = 60; i >= 0; i--) cout << b[i]; // cout << endl; // Xを探す // XとKとで初めてビットが異なる箇所で場合分け // X <= K なので、初めてビットが異なればその箇所ではXのビットは0、Kのビットは1 // それ以降は何でもよいので貪欲 ll ans = 0; for (int i = 60; i >= -1; i--) { ll t = 0; if (i != -1 && !(K & (1LL << i))) continue; for (int j = 60; j >= 0; j--) { ll y = 1LL << j; if (j > i) { if (K & y) t += (N - b[j]) * y; else t += b[j] * y; } else if (j == i) { t += (N - b[j]) * y; } else { t += max(b[j] * y, (N - b[j]) * y); } } // cout << i << " " << t << endl; ans = max(ans, t); } cout << ans << endl; }
#include <bits/stdc++.h> #define FOR(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, n) FOR(i, 0, n) #define RFOR(i, a, b) for (int i = (a)-1; i >= (b); i--) #define rrep(i, n) RFOR(i, n, 0) using namespace std; typedef long long ll; typedef unsigned long long ull; int main() { cin.tie(0); ios::sync_with_stdio(false); ll N, K; cin >> N >> K; ll A[N]; rep(i, N) cin >> A[i]; // 各ビットごとの1の個数を調べる ll b[61] = {}; for (int i = 60; i >= 0; i--) { ll y = 1LL << i; int cnt = 0; rep(i, N) { if (A[i] & y) cnt++; } b[i] = cnt; } // for(int i = 60; i >= 0; i--) cout << b[i]; // cout << endl; // Xを探す // XとKとで初めてビットが異なる箇所で場合分け // X <= K なので、初めてビットが異なればその箇所ではXのビットは0、Kのビットは1 // それ以降は何でもよいので貪欲 ll ans = 0; for (int i = 60; i >= -1; i--) { ll t = 0; if (i != -1 && !(K & (1LL << i))) continue; for (int j = 60; j >= 0; j--) { ll y = 1LL << j; if (j > i) { if (K & y) t += (N - b[j]) * y; else t += b[j] * y; } else if (j == i) { t += b[j] * y; // (N - b[j]) * y; } else { t += max(b[j] * y, (N - b[j]) * y); } } // cout << i << " " << t << endl; ans = max(ans, t); } cout << ans << endl; }
[]
939,788
939,789
u755830696
cpp
p03138
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <vector> int main(void) { long long n, k; std::cin >> n >> k; std::vector<long long> v(n); long long bit[64] = {0}; for (size_t i = 0; i < n; i++) { std::cin >> v[i]; long long tmp = v[i]; long long j = 0; while (tmp != 0) { bit[j] += tmp % 2; tmp /= 2; j++; } } long long a = 1099511627776LL; long long aa = 0; long long i = 40; while (a != 0) { if (k >= a) { if (bit[i] <= (n + 1) / 2) { aa += a; } k -= a; } i--; a /= 2; } long long ans = 0LL; for (size_t i = 0; i < n; i++) { v[i] ^= aa; ans += v[i]; } std::cout << ans << std::endl; return 0; }
#include <algorithm> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <string> #include <vector> int main(void) { long long n, k; std::cin >> n >> k; std::vector<long long> v(n); long long bit[64] = {0}; for (size_t i = 0; i < n; i++) { std::cin >> v[i]; long long tmp = v[i]; long long j = 0; while (tmp != 0) { bit[j] += tmp % 2; tmp /= 2; j++; } } long long a = 1099511627776LL; long long aa = 0; long long i = 40; while (a != 0) { if (k >= a) { if (bit[i] < (n + 1) / 2) { aa += a; k -= a; } } i--; a /= 2; } long long ans = 0LL; for (size_t i = 0; i < n; i++) { v[i] ^= aa; ans += v[i]; } std::cout << ans << std::endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
939,790
939,791
u914739916
cpp
p03138
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long K; cin >> K; vector<long long> A(N); for (auto &a : A) cin >> a; long long best = 0; for (long long bit = 1LL << 40; bit; bit >>= 1) { int cnt = 0; for (auto a : A) if (a & bit) cnt++; if (cnt <= N / 2) best |= bit; } long long ans = 0; for (auto a : A) ans += a; // X == 0 for (long long bit = 1LL << 40; bit; bit >>= 1) { if (K & bit) { long long X = (K & ~(bit - 1) & ~bit) | (best & (bit - 1)); long long f = 0; for (auto a : A) f += a ^ X; ans = max(ans, f); } } cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; long long K; cin >> K; vector<long long> A(N); for (auto &a : A) cin >> a; long long best = 0; for (long long bit = 1LL << 40; bit; bit >>= 1) { int cnt = 0; for (auto a : A) if (a & bit) cnt++; if (cnt <= N / 2) best |= bit; } long long ans = 0; for (auto a : A) ans += a ^ K; // X == K for (long long bit = 1LL << 40; bit; bit >>= 1) { if (K & bit) { long long X = (K & ~(bit - 1) & ~bit) | (best & (bit - 1)); long long f = 0; for (auto a : A) f += a ^ X; ans = max(ans, f); } } cout << ans << endl; return 0; }
[ "assignment.change" ]
939,794
939,795
u449722246
cpp
p03138
//#include "bits/stdc++.h" #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define int long long #define REP(i, l, r) REPEAT(i, l, r, true) // [l, r) #define rep(i, n) REP(i, 0, n) // [0, n) #define REPEAT(i, l, r, condition) \ for (int i = (condition) ? l : r - 1; (condition) ? i < r : i >= l; \ (condition) ? ++i : --i) // false<-[l, r)->true #define all(e) e.begin(), e.end() #define rall(e) e.rbegin(), e.rend() #define pb push_back #define fs first #define sc second #define show(...) \ cerr << #__VA_ARGS__ << " = "; \ _DEBUG(__VA_ARGS__) #define showlr(n, l, r) \ cerr << #n << " = "; \ for (int i = l; i < r; i++) { \ cerr << n[i] << ", "; \ } \ cerr << endl // [l, r) #define yes puts("Yes") #define no puts("No") #define case (i) printf("Case #%lld: ", i) using namespace std; using vi = vector<int>; using pint = pair<int, int>; struct io { io() { cin.tie(0); ios::sync_with_stdio(false); cout.tie(0); cout << fixed << setprecision(20); } } io; template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &e : v) is >> e; return is; } template <class T> ostream &operator<<(ostream &os, vector<T> v) { os << "{"; for (T &e : v) os << e << (v.size() - (int)(&e - &v[0]) > 1 ? ", " : ""); os << "}"; return os; } void _DEBUG() {} template <typename H, typename... T> void _DEBUG(H a, T... b) { cerr << a << (sizeof...(b) ? "," : "\n"); _DEBUG(b...); } inline void in() {} template <typename H, typename... T> void in(H &a, T &...b) { cin >> a; in(b...); } inline void out() {} template <typename H, typename... T> void out(H a, T... b) { cout << a << (sizeof...(b) ? " " : "\n"); out(b...); } template <class T> void resz(int n, T &v) { v.resize(n); } template <class H, class... T> void resz(int n, H &a, T &...b) { a.resize(n); resz(n, b...); } const int INF = 1LL << 55; const int MOD = 1000000007; const double EPS = 1e-8; int n, k; vi a; vi one(60); int ans; int l; signed main() { in(n, k); resz(n, a); in(a); rep(i, n) { rep(j, 60) { if ((1LL << j) & a[i]) one[j]++; } } // show(one); REPEAT(i, 0, 60, false) { if (one[i] != max(one[i], n - one[i])) { if (l + (1LL << i) <= k) { one[i] = max(one[i], n - one[i]); l += (1LL + i); } } ans += one[i] * (1LL << i); } out(ans); return 0; }
//#include "bits/stdc++.h" #include <algorithm> #include <bitset> #include <cmath> #include <complex> #include <cstdio> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <regex> #include <set> #include <stack> #include <tuple> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #define int long long #define REP(i, l, r) REPEAT(i, l, r, true) // [l, r) #define rep(i, n) REP(i, 0, n) // [0, n) #define REPEAT(i, l, r, condition) \ for (int i = (condition) ? l : r - 1; (condition) ? i < r : i >= l; \ (condition) ? ++i : --i) // false<-[l, r)->true #define all(e) e.begin(), e.end() #define rall(e) e.rbegin(), e.rend() #define pb push_back #define fs first #define sc second #define show(...) \ cerr << #__VA_ARGS__ << " = "; \ _DEBUG(__VA_ARGS__) #define showlr(n, l, r) \ cerr << #n << " = "; \ for (int i = l; i < r; i++) { \ cerr << n[i] << ", "; \ } \ cerr << endl // [l, r) #define yes puts("Yes") #define no puts("No") #define case (i) printf("Case #%lld: ", i) using namespace std; using vi = vector<int>; using pint = pair<int, int>; struct io { io() { cin.tie(0); ios::sync_with_stdio(false); cout.tie(0); cout << fixed << setprecision(20); } } io; template <class T> istream &operator>>(istream &is, vector<T> &v) { for (T &e : v) is >> e; return is; } template <class T> ostream &operator<<(ostream &os, vector<T> v) { os << "{"; for (T &e : v) os << e << (v.size() - (int)(&e - &v[0]) > 1 ? ", " : ""); os << "}"; return os; } void _DEBUG() {} template <typename H, typename... T> void _DEBUG(H a, T... b) { cerr << a << (sizeof...(b) ? "," : "\n"); _DEBUG(b...); } inline void in() {} template <typename H, typename... T> void in(H &a, T &...b) { cin >> a; in(b...); } inline void out() {} template <typename H, typename... T> void out(H a, T... b) { cout << a << (sizeof...(b) ? " " : "\n"); out(b...); } template <class T> void resz(int n, T &v) { v.resize(n); } template <class H, class... T> void resz(int n, H &a, T &...b) { a.resize(n); resz(n, b...); } const int INF = 1LL << 55; const int MOD = 1000000007; const double EPS = 1e-8; int n, k; vi a; vi one(60); int ans; int l; signed main() { in(n, k); resz(n, a); in(a); rep(i, n) { rep(j, 60) { if ((1LL << j) & a[i]) one[j]++; } } // show(one); REPEAT(i, 0, 60, false) { if (one[i] != max(one[i], n - one[i])) { if (l + (1LL << i) <= k) { one[i] = max(one[i], n - one[i]); l += (1LL << i); } } ans += one[i] * (1LL << i); } // show(l); out(ans); return 0; }
[ "assignment.value.change", "expression.operation.binary.change" ]
939,798
939,799
u810724221
cpp
p03138
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <string> #include <vector> using namespace std; #define int long long signed main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int X = 0; for (int i = 30; i >= 0; i--) { int bit = (int)1 << i; int n1 = 0; for (int j = 0; j < N; j++) { if (A[j] & bit) { n1++; } } if (n1 < N - n1) { X += bit; } } int res = 0; for (int i = 0; i < N; i++) { res += A[i]; } int z = 0; for (int i = 30; i >= 0; i--) { int bit = (int)1 << i; if (K & bit) { int Y = (X & (bit - 1)) + z; int ans = 0; for (int j = 0; j < N; j++) { ans += A[j] ^ Y; } res = max(res, ans); } z += (K & bit); } cout << res << endl; return 0; }
#include <algorithm> #include <cmath> #include <fstream> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stdio.h> #include <string> #include <vector> using namespace std; #define int long long signed main() { int N, K; cin >> N >> K; vector<int> A(N); for (int i = 0; i < N; i++) { cin >> A[i]; } int X = 0; for (int i = 50; i >= 0; i--) { int bit = (int)1 << i; int n1 = 0; for (int j = 0; j < N; j++) { if (A[j] & bit) { n1++; } } if (n1 < N - n1) { X += bit; } } int res = 0; for (int i = 0; i < N; i++) { res += A[i] ^ K; } int z = 0; for (int i = 50; i >= 0; i--) { int bit = (int)1 << i; if (K & bit) { int Y = (X & (bit - 1)) + z; int ans = 0; for (int j = 0; j < N; j++) { ans += A[j] ^ Y; } res = max(res, ans); } z += (K & bit); } cout << res << endl; return 0; }
[ "literal.number.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change", "assignment.change" ]
939,800
939,801
u864888234
cpp
p03138
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k_size; const int maxbits = 40; long long k, ans[maxbits][2], a_max = -1, result[2]; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; // a[i] = i; if (a_max < a[i]) { a_max = a[i]; } } if (k < 2) { long long onebit_res = 0; for (int i = 0; i < n; ++i) { onebit_res += a[i] ^ k; } cout << onebit_res << endl; return 0; } memset(ans, -1, sizeof(ans)); long long two_pow_n[maxbits]; two_pow_n[0] = 1; for (int i = 1; i < maxbits; ++i) { two_pow_n[i] = two_pow_n[i - 1] * 2; } for (int x = 0; x < 2; ++x) { bool flag_switch = false; for (int i = maxbits - 1; i >= 0; --i) { long long mask = 1LL << i; if (k & mask) { for (int j = i; j >= 0; --j) { int count = 0; mask = 1LL << j; for (int l = 0; l < n; ++l) { if (a[l] & mask) { ++count; } } ans[j][x] = two_pow_n[j] * (x == 0 ? count : n - count); } result[x] = ans[i][x]; k_size = i; break; } else if (a_max & mask || flag_switch) { flag_switch = true; int count = 0; for (int l = 0; l < n; ++l) { if (a[l] & mask) { ++count; } } ans[i][x] = two_pow_n[i] * count; } } } for (int j = maxbits - 1; j >= 0; --j) { if (ans[j][0] == -1 || j == k_size) { continue; } else { result[0] += max(ans[j][0], ans[j][1]); } } bool fdp = false; for (int j = maxbits - 1; j >= 0; --j) { if (ans[j][1] == -1 || j == k_size) { continue; } else { long long mask = 1LL << j; if (fdp) { result[1] += max(ans[j][0], ans[j][1]); } else if (k & mask) { long long temp[2] = {ans[j][0], ans[j][1]}; for (int x = j - 1; x >= 0; --x) { temp[0] += max(ans[x][0], ans[x][1]); } for (int x = j - 1; x >= 0; --x) { mask = 1LL << x; temp[1] += (k & mask ? max(ans[x][0], ans[x][1]) : ans[x][0]); } if (temp[0] >= temp[1]) { result[1] += ans[j][0]; fdp = true; } else { result[1] += ans[j][1]; } } else { result[1] += ans[j][1]; } } } cout << max(result[0], result[1]) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, k_size; const int maxbits = 40; long long k, ans[maxbits][2], a_max = -1, result[2]; cin >> n >> k; vector<long long> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; if (a_max < a[i]) { a_max = a[i]; } } if (k < 2) { long long onebit_res = 0; for (int i = 0; i < n; ++i) { onebit_res += a[i] ^ k; } cout << onebit_res << endl; return 0; } memset(ans, -1, sizeof(ans)); long long two_pow_n[maxbits]; two_pow_n[0] = 1; for (int i = 1; i < maxbits; ++i) { two_pow_n[i] = two_pow_n[i - 1] * 2; } for (int x = 0; x < 2; ++x) { bool flag_switch = false; for (int i = maxbits - 1; i >= 0; --i) { long long mask = 1LL << i; if (k & mask) { for (int j = i; j >= 0; --j) { int count = 0; mask = 1LL << j; for (int l = 0; l < n; ++l) { if (a[l] & mask) { ++count; } } ans[j][x] = two_pow_n[j] * (x == 0 ? count : n - count); } result[x] = ans[i][x]; k_size = i; break; } else if (a_max & mask || flag_switch) { flag_switch = true; int count = 0; for (int l = 0; l < n; ++l) { if (a[l] & mask) { ++count; } } ans[i][x] = two_pow_n[i] * count; } } } for (int j = maxbits - 1; j >= 0; --j) { if (ans[j][0] == -1 || j == k_size) { continue; } else { result[0] += max(ans[j][0], ans[j][1]); } } bool fdp = false; for (int j = maxbits - 1; j >= 0; --j) { if (ans[j][1] == -1 || j == k_size) { continue; } else { long long mask = 1LL << j; if (fdp) { result[1] += max(ans[j][0], ans[j][1]); } else if (k & mask) { long long temp[2] = {ans[j][0], ans[j][1]}; for (int x = j - 1; x >= 0; --x) { temp[0] += max(ans[x][0], ans[x][1]); } for (int x = j - 1; x >= 0; --x) { mask = 1LL << x; temp[1] += (k & mask ? max(ans[x][0], ans[x][1]) : ans[x][0]); } if (temp[0] >= temp[1]) { result[1] += ans[j][0]; fdp = true; } else { result[1] += ans[j][1]; } } else { result[1] += ans[j][0]; } } } cout << max(result[0], result[1]) << endl; }
[ "literal.number.change", "assignment.value.change", "variable_access.subscript.index.change" ]
939,802
939,803
u647474992
cpp
p03138
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; ll K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<ll> cnt(61, 0); for (int i = 0; i < N; i++) { int j = 0; ll a = A[i]; while (a > 0) { if (a % 2 == 1) cnt[j]++; a /= 2; j++; } } ll X = 0; for (ll i = 60; i >= 0; i--) { if ((N % 2 == 0 && cnt[i] < N / 2) || (N % 2 == 1 && cnt[i] <= N / 2)) { ll p = 1; ll ind = i; while (ind > 0) { p *= 2; ind--; } if (X + p < K) { X += p; } } } ll ans = 0; for (int i = 0; i < N; i++) { ans += X ^ A[i]; } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { int N; ll K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; vector<int> cnt(61, 0); for (int i = 0; i < N; i++) { int j = 0; ll a = A[i]; while (a > 0) { if (a % 2 == 1) cnt[j]++; a /= 2; j++; } } ll X = 0; for (ll i = 60; i >= 0; i--) { if ((N % 2 == 0 && cnt[i] < N / 2) || (N % 2 == 1 && cnt[i] <= N / 2)) { ll p = 1; ll ind = i; while (ind > 0) { p *= 2; ind--; } if (X + p <= K) { X += p; } } } ll ans = 0; for (int i = 0; i < N; i++) { ans += X ^ A[i]; } cout << ans << endl; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
939,807
939,808
u119098168
cpp
p03138
#include <algorithm> #include <assert.h> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using int64 = long long; using int128 = __int128; #define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; int64 K; cin >> N >> K; vector<int64> A(N); repeat(i, N) { cin >> A[i]; } int64 ans = 0; repeat(i, N) ans += A[i] ^ K; int64 mask = (1LL << 62) - 1, sum = 0; for (int i = 0; i <= 60; i++) { if ((K >> i) & 1) { int64 value = sum; repeat(j, N) { value += (K & (mask ^ (1LL << i))) ^ (A[j] & mask); } ans = max(ans, value); } int cnt = 0; repeat(j, N) if ((A[i] >> j) & 1) cnt++; sum += (1LL << i) * max(cnt, N - cnt); mask -= (1LL << i); } cout << ans << endl; return 0; }
#include <algorithm> #include <assert.h> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using int64 = long long; using int128 = __int128; #define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; int64 K; cin >> N >> K; vector<int64> A(N); repeat(i, N) { cin >> A[i]; } int64 ans = 0; repeat(i, N) ans += A[i] ^ K; int64 mask = (1LL << 41) - 1, sum = 0; for (int i = 0; i <= 40; i++) { if ((K >> i) & 1) { int64 value = sum; repeat(j, N) { value += (K & (mask ^ (1LL << i))) ^ (A[j] & mask); } ans = max(ans, value); } int cnt = 0; repeat(j, N) if ((A[j] >> i) & 1) cnt++; sum += (1LL << i) * max(cnt, N - cnt); mask -= (1LL << i); } cout << ans << endl; return 0; }
[ "literal.number.change", "expression.operation.binary.change", "control_flow.loop.for.condition.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
939,824
939,825
u602850810
cpp
p03138
#include <algorithm> #include <assert.h> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using int64 = long long; using int128 = __int128; #define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; int64 K; cin >> N >> K; vector<int64> A(N); repeat(i, N) { cin >> A[i]; } int64 ans = 0; repeat(i, N) ans += A[i] ^ K; int64 mask = (1LL << 61) - 1, sum = 0; for (int i = 0; i <= 60; i++) { if ((K >> i) & 1) { int64 value = sum; repeat(j, N) { value += (K & (mask ^ (1LL << i))) ^ (A[j] & mask); } ans = max(ans, value); } int cnt = 0; repeat(j, N) if ((A[i] >> j) & 1) cnt++; sum += (1LL << i) * max(cnt, N - cnt); mask -= (1LL << i); } cout << ans << endl; return 0; }
#include <algorithm> #include <assert.h> #include <cmath> #include <cstring> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <vector> using namespace std; using int64 = long long; using int128 = __int128; #define repeat(i, n) for (auto i = decltype(n)(); (i) < (n); (i)++) int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N; int64 K; cin >> N >> K; vector<int64> A(N); repeat(i, N) { cin >> A[i]; } int64 ans = 0; repeat(i, N) ans += A[i] ^ K; int64 mask = (1LL << 41) - 1, sum = 0; for (int i = 0; i <= 40; i++) { if ((K >> i) & 1) { int64 value = sum; repeat(j, N) { value += (K & (mask ^ (1LL << i))) ^ (A[j] & mask); } ans = max(ans, value); } int cnt = 0; repeat(j, N) if ((A[j] >> i) & 1) cnt++; sum += (1LL << i) * max(cnt, N - cnt); mask -= (1LL << i); } cout << ans << endl; return 0; }
[ "literal.number.change", "expression.operation.binary.change", "control_flow.loop.for.condition.change", "identifier.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
939,826
939,825
u602850810
cpp
p03138
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = a; i < b; i++) #define REP(i, b) FOR(i, 0, b) #define RFOR(i, a, b) for (int i = a - 1; i >= b; i--) #define RREP(i, a) RFOR(i, a, 0) #define REPALL(i, v) for (int i = 0; i < v.size(); i++) #define SORT(v) sort(v.begin(), v.end()) #define MIN_ELEMENT(v) min_element(v.begin(), v.end()) #define MAX_ELEMENT(v) max_element(v.begin(), v.end()) #define COUNT(v, n) count(v.begin(), v.end(), n); typedef long long ll; typedef unsigned long long ull; const int INF = 1e7; const ll MOD = 1e9 + 7; vector<ll> a; int b[100]; ll n, k, sum; int maxbit; void f(ll a) { for (ll i = 0; (a >> i) > 0; i++) { b[i] += (a >> i) & 1; if (maxbit < i) maxbit = i; } } ll g(ll num, int i) { if (num > k) { return static_cast<ll>(-1e12); } else if ((1ll << i) > k) { return 0; } else { // ll tmp1 = b[i] * (1<<i); // ll tmp2 = (n - b[i]) * (1<<i); ll tmp = (n - b[i] * 2) * (1ll << i); if (tmp >= 0) return max(g(num, i + 1), g(num + (1ll << i), i + 1) + tmp); else return g(num, i + 1); } } ll h() { ll r = 0ll, kk = 0ll; for (int i = 62; i > -1; i--) { if (kk + (1ll << i) < k && n - b[i] > n / 2) { r += (n - b[i]) * (1ll << i); kk += (1 << i); } else { r += b[i] * (1ll << i); } } return r; } int main() { cin >> n >> k; REP(i, n) { ll ta; cin >> ta; a.push_back(ta); sum += ta; f(ta); } // cout<<g(0ll, 0) + sum<<endl; cout << h() << endl; return 0; }
#include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = a; i < b; i++) #define REP(i, b) FOR(i, 0, b) #define RFOR(i, a, b) for (int i = a - 1; i >= b; i--) #define RREP(i, a) RFOR(i, a, 0) #define REPALL(i, v) for (int i = 0; i < v.size(); i++) #define SORT(v) sort(v.begin(), v.end()) #define MIN_ELEMENT(v) min_element(v.begin(), v.end()) #define MAX_ELEMENT(v) max_element(v.begin(), v.end()) #define COUNT(v, n) count(v.begin(), v.end(), n); typedef long long ll; typedef unsigned long long ull; const int INF = 1e7; const ll MOD = 1e9 + 7; vector<ll> a; int b[100]; ll n, k, sum; int maxbit; void f(ll a) { for (ll i = 0; (a >> i) > 0; i++) { b[i] += (a >> i) & 1; if (maxbit < i) maxbit = i; } } ll g(ll num, int i) { if (num > k) { return static_cast<ll>(-1e12); } else if ((1ll << i) > k) { return 0; } else { // ll tmp1 = b[i] * (1<<i); // ll tmp2 = (n - b[i]) * (1<<i); ll tmp = (n - b[i] * 2) * (1ll << i); if (tmp >= 0) return max(g(num, i + 1), g(num + (1ll << i), i + 1) + tmp); else return g(num, i + 1); } } ll h() { ll r = 0ll, kk = 0ll; for (int i = 62; i > -1; i--) { if (kk + (1ll << i) <= k && n - b[i] > b[i]) { r += (n - b[i]) * (1ll << i); kk += (1ll << i); } else { r += b[i] * (1ll << i); } } return r; } int main() { cin >> n >> k; REP(i, n) { ll ta; cin >> ta; a.push_back(ta); sum += ta; f(ta); } // cout<<g(0ll, 0) + sum<<endl; cout << h() << endl; return 0; }
[ "expression.operator.compare.change", "control_flow.branch.if.condition.change", "control_flow.loop.for.condition.change" ]
939,842
939,840
u007637377
cpp
p03138
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 40; i++) { long n = (long)1 << i; // cout << i << ':' << n << endl; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += A[i]; } if (X >= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 40; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 40; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 40; i++) { long n = (long)1 << i; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += K ^ A[i]; } if (X <= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 40; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 40; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
[ "assignment.change", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
939,845
939,846
u693133807
cpp
p03138
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 40; i++) { long n = (long)1 << i; // cout << i << ':' << n << endl; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += (K ^ A[i]); } if (X >= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 40; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 40; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 40; i++) { long n = (long)1 << i; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += K ^ A[i]; } if (X <= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 40; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 40; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
939,847
939,846
u693133807
cpp
p03138
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 50; i++) { long n = (long)1 << i; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += A[i]; } if (X <= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 50; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 50; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 40; i++) { long n = (long)1 << i; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += K ^ A[i]; } if (X <= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 40; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 40; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "assignment.change", "control_flow.branch.if.condition.change" ]
939,848
939,846
u693133807
cpp
p03138
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 50; i++) { long n = (long)1 << i; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += A[i]; } if (X >= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 50; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 50; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
#include <iostream> using namespace std; int main() { int N; long K; long A[100000]; long X = 0; cin >> N >> K; for (int i = 0; i < N; i++) { cin >> A[i]; } for (int i = 0; i <= 40; i++) { long n = (long)1 << i; if (n > K) break; int cnt1 = 0; int cnt0 = 0; for (int j = 0; j < N; j++) { if (n & A[j]) cnt1++; else cnt0++; // cout << n << ' ' << A[i] << endl; } if (cnt0 > cnt1) { X = X | n; } } // cout << X << endl; long long ans = 0; long long tmp = 0; for (int i = 0; i < N; i++) { ans += K ^ A[i]; } if (X <= K) { for (int i = 0; i < N; i++) { tmp += (X ^ A[i]); } } ans = max(tmp, ans); for (int j = 0; j <= 40; j++) { tmp = 0; long n = (long)1 << j; if (K & n) { // cout << "j " << j << endl; long long X1 = 0; for (int k = 0; k < j; k++) { X1 += X & ((long)1 << k); // cout << X1 << endl; } for (int k = j + 1; k <= 40; k++) { // if((1<< k) > K) break; // cout << k << endl; X1 += K & ((long)1 << k); } for (int i = 0; i < N; i++) { tmp += (X1 ^ A[i]); } // cout << X1 << endl; ans = max(tmp, ans); } } cout << ans << endl; }
[ "literal.number.change", "control_flow.loop.for.condition.change", "expression.operation.binary.change", "assignment.change", "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
939,849
939,846
u693133807
cpp
p03138
#include "bits/stdc++.h" #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define BUGAVOID(x) x #define rep(...) \ BUGAVOID(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define sz(c) (int)(c.size()) #define all(c) c.begin(), c.end() #define ms(a, v) memset(a, v, sizeof(a)) #define unq(v) v.erase(unique(v.begin(), v.end()), v.end()); #define mp make_pair #define write(x) cout << (x) << endl using namespace std; typedef long long ll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const int INF = 1 << 28; const ll LINF = 1ll << 60; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6; const int dy[4] = {0, 1, 0, -1}; const int dx[4] = {1, 0, -1, 0}; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; } aaaa; int N; ll K; ll A[MAX]; int bsum[45]; ll dp[45][2]; ll ans; int main() { cin >> N >> K; rep(i, N) cin >> A[i]; rep(d, 40) { int cnt = 0; rep(i, N) { if ((A[i] >> d) % 2) cnt++; } bsum[d] = cnt; } for (int d = 39; d >= 0; --d) { if ((K >> d) % 2) { ll cnt = 0; for (int e = d - 1; e >= 0; --e) { cnt += (1ll << e) * (bsum[e] * 2 < N ? N - bsum[e] * 2 : bsum[e]); } dp[d][0] = dp[d + 1][1] + cnt + (1ll << d) * bsum[d]; dp[d][1] = dp[d + 1][1] + (1ll << d) * (N - bsum[d]); } else { dp[d][1] = dp[d + 1][1] + (1ll << d) * bsum[d]; } } rep(i, 40) chmax(ans, dp[i][0]); chmax(ans, dp[0][1]); write(ans); }
#include "bits/stdc++.h" #define _overload3(_1, _2, _3, name, ...) name #define _rep(i, n) repi(i, 0, n) #define repi(i, a, b) for (int i = int(a), i##_len = (b); i < i##_len; ++i) #define BUGAVOID(x) x #define rep(...) \ BUGAVOID(_overload3(__VA_ARGS__, repi, _rep, _rep)(__VA_ARGS__)) #define sz(c) (int)(c.size()) #define all(c) c.begin(), c.end() #define ms(a, v) memset(a, v, sizeof(a)) #define unq(v) v.erase(unique(v.begin(), v.end()), v.end()); #define mp make_pair #define write(x) cout << (x) << endl using namespace std; typedef long long ll; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } const int INF = 1 << 28; const ll LINF = 1ll << 60; const int MAX = 1e5 + 5; const int MOD = 1e9 + 7; const double EPS = 1e-6; const int dy[4] = {0, 1, 0, -1}; const int dx[4] = {1, 0, -1, 0}; struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; } aaaa; int N; ll K; ll A[MAX]; int bsum[45]; ll dp[45][2]; ll ans; int main() { cin >> N >> K; rep(i, N) cin >> A[i]; rep(d, 40) { int cnt = 0; rep(i, N) { if ((A[i] >> d) % 2) cnt++; } bsum[d] = cnt; } for (int d = 39; d >= 0; --d) { if ((K >> d) % 2) { ll cnt = 0; for (int e = d - 1; e >= 0; --e) { cnt += (1ll << e) * (bsum[e] * 2 < N ? N - bsum[e] : bsum[e]); } dp[d][0] = dp[d + 1][1] + cnt + (1ll << d) * bsum[d]; dp[d][1] = dp[d + 1][1] + (1ll << d) * (N - bsum[d]); } else { dp[d][1] = dp[d + 1][1] + (1ll << d) * bsum[d]; } } rep(i, 40) chmax(ans, dp[i][0]); chmax(ans, dp[0][1]); write(ans); }
[ "expression.operation.binary.remove" ]
939,857
939,858
u751488284
cpp
p03138
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF (1 << (4 * 4 - 1)) #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll n = max(K, *max_element(rng(A))); if (n == 0) n = 1; else n = log2(n) + 1; vector<ll> memo(n); for (int i = 0; i < n; i++) { ll sum = 0; for (int j = 0; j < N; j++) { if (1 & (A[j] >> i)) sum++; } memo[i] = sum; } vector<ll> cost0(n, 0), cost1(n, 0); for (int i = 0; i < n; i++) { cost0[i] = memo[i] * pow(2, i); cost1[i] = (N - memo[i]) * pow(2, i); } // for(int i=0;i<n;i++)cout<<memo[i]<<" "<< // cost0[i]<<" "<<N-memo[i]<<" "<<cost1[i]<<endl; vector<vector<ll>> dp(n + 1, vector<ll>(2, -1)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { int x = j ? 1 : (1 & (K >> i)); for (int k = 0; k <= x; k++) { if (dp[i][j] != -1) dp[i + 1][j || k < x] = max(dp[i + 1][j || k < x], dp[i][j] + (k ? cost1[n - i - 1] : cost0[n - i - 1])); } } } /* for(int i=0;i<=n;i++){ for(int j=0;j<2;j++){ cout<<dp[i][j]<<" "; } cout<<endl; } */ cout << max(dp[n][0], dp[n][1]) << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; #define INF (1 << (4 * 4 - 1)) #define MOD 1000000007 #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() int main() { ios::sync_with_stdio(false); cin.tie(0); ll N, K; cin >> N >> K; vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i]; ll n = max(K, *max_element(rng(A))); if (n == 0) n = 1; else n = log2(n) + 1; vector<ll> memo(n); for (int i = 0; i < n; i++) { ll sum = 0; for (int j = 0; j < N; j++) { if (1 & (A[j] >> i)) sum++; } memo[i] = sum; } vector<ll> cost0(n, 0), cost1(n, 0); for (int i = 0; i < n; i++) { cost0[i] = memo[i] * pow(2, i); cost1[i] = (N - memo[i]) * pow(2, i); } // for(int i=0;i<n;i++)cout<<memo[i]<<" "<< // cost0[i]<<" "<<N-memo[i]<<" "<<cost1[i]<<endl; vector<vector<ll>> dp(n + 1, vector<ll>(2, -1)); dp[0][0] = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < 2; j++) { int x = j ? 1 : (1 & (K >> (n - i - 1))); for (int k = 0; k <= x; k++) { if (dp[i][j] != -1) dp[i + 1][j || k < x] = max(dp[i + 1][j || k < x], dp[i][j] + (k ? cost1[n - i - 1] : cost0[n - i - 1])); } } } /* for(int i=0;i<=n;i++){ for(int j=0;j<2;j++){ cout<<dp[i][j]<<" "; } cout<<endl; } */ cout << max(dp[n][0], dp[n][1]) << endl; return 0; }
[]
939,866
939,867
u864171425
cpp
p03138
#include <bits/stdc++.h> using namespace std; // define #define int long long #define UNIQUE(v) v.erase(unique(all(v)), v.end()); #define ZIP(v) sort(all(v)), UNIQUE(v) #define ADD(a, b) a = (a + b) % mod #define SUB(a, b) a = (a + mod - b) % mod #define MUL(a, b) a = (a * b) % mod #define rollcall cout << "I'm Sucu." << endl; #define repi(i, m, n) for (int i = m; i < n; i++) #define drep(i, n, m) for (int i = n; i >= m; i--) #define rep(i, n) repi(i, 0, n) #define rrep(i, n) repi(i, 1, n + 1) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define dmp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define pf(x) push_front(x) #define fi first #define se second // debug template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << " "; os << *it; } return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp) { for (auto x : mp) os << "(" << x.first << "," << x.second << ")" << endl; return os; } template <typename T, int SIZE> int array_length(const T (&)[SIZE]) { return SIZE; } template <typename T, int N> void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true) { if (t == -1) { rep(i, s) { if (i) cout << " "; cout << a[i]; } } else repi(i, s, t) { if (i != s) cout << " "; cout << a[i]; } if (f) cout << "\n"; } template <typename T, int N1, int N2> void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2) { rep(i, h) { rep(j, w) { cout << a[i][j] << " \n"[j == w - 1]; } } } string substr(const string &str, int S1, int S2 = -1) { if (S2 == -1) return str.substr(S1); return str.substr(S1, S2 - S1); } // typedef typedef complex<double> Point; typedef pair<int, int> P; typedef pair<int, P> PP; typedef pair<P, int> Pi; typedef vector<int> vi; typedef deque<int> dq; const int inf = 1e9 + 7; const int INF = 1e18 + 7; int a[200000], fac[50], cnt[50], num[50], dp[50][2]; string to_binary(int n) { string str = ""; vector<int> v; while (n) { v.pb(n % 2); n /= 2; } if (v.size() == 0) return "0"; drep(i, v.size() - 1, 0) str.pb(v[i] + '0'); return str; } void init(int d) { fac[d - 1] = 1; drep(i, d - 1, 1) fac[i - 1] = fac[i] * 2; } int calc(int n, int d) { int ans = 0, tmp = 1; drep(i, d - 1, 0) { cnt[i] += n % 2; n = n / 2; tmp *= 2; } return n * tmp; } signed main() { int n, k; scanf("%lld%lld", &n, &k); rep(i, n) scanf("%lld", &a[i]); string str = to_binary(k); int d = str.size(); int ans = 0; init(d); rep(i, n) ans += calc(a[i], d); rep(i, d) { if (i == 0) { dp[0][0] = cnt[0] * fac[0]; if (str[i] == '1') dp[0][1] = (n - cnt[0]) * fac[0]; continue; } if (str[i] == '0') { dp[i][0] = dp[i - 1][0] + max(cnt[i], n - cnt[i]) * fac[i]; dp[i][1] = dp[i - 1][1] + cnt[i] * fac[i]; } else { dp[i][1] = dp[i - 1][1] + (n - cnt[i]) * fac[i]; dp[i][0] = dp[i - 1][1] + cnt[i] * fac[i]; chmax(dp[i][0], dp[i - 1][0] + max(cnt[i], n - cnt[i]) * fac[i]); } } printf("%lld\n", ans + max(dp[n - 1][0], dp[n - 1][1])); return 0; }
#include <bits/stdc++.h> using namespace std; // define #define int long long #define UNIQUE(v) v.erase(unique(all(v)), v.end()); #define ZIP(v) sort(all(v)), UNIQUE(v) #define ADD(a, b) a = (a + b) % mod #define SUB(a, b) a = (a + mod - b) % mod #define MUL(a, b) a = (a * b) % mod #define rollcall cout << "I'm Sucu." << endl; #define repi(i, m, n) for (int i = m; i < n; i++) #define drep(i, n, m) for (int i = n; i >= m; i--) #define rep(i, n) repi(i, 0, n) #define rrep(i, n) repi(i, 1, n + 1) #define chmin(x, y) x = min(x, y) #define chmax(x, y) x = max(x, y) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() #define dmp(x, y) make_pair(x, y) #define pb(x) push_back(x) #define pf(x) push_front(x) #define fi first #define se second // debug template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << "(" << p.first << "," << p.second << ")"; return os; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { for (auto it = v.begin(); it != v.end(); ++it) { if (it != v.begin()) os << " "; os << *it; } return os; } template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp) { for (auto x : mp) os << "(" << x.first << "," << x.second << ")" << endl; return os; } template <typename T, int SIZE> int array_length(const T (&)[SIZE]) { return SIZE; } template <typename T, int N> void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true) { if (t == -1) { rep(i, s) { if (i) cout << " "; cout << a[i]; } } else repi(i, s, t) { if (i != s) cout << " "; cout << a[i]; } if (f) cout << "\n"; } template <typename T, int N1, int N2> void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2) { rep(i, h) { rep(j, w) { cout << a[i][j] << " \n"[j == w - 1]; } } } string substr(const string &str, int S1, int S2 = -1) { if (S2 == -1) return str.substr(S1); return str.substr(S1, S2 - S1); } // typedef typedef complex<double> Point; typedef pair<int, int> P; typedef pair<int, P> PP; typedef pair<P, int> Pi; typedef vector<int> vi; typedef deque<int> dq; const int inf = 1e9 + 7; const int INF = 1e18 + 7; int a[200000], fac[50], cnt[50], num[50], dp[50][2]; string to_binary(int n) { string str = ""; vector<int> v; while (n) { v.pb(n % 2); n /= 2; } if (v.size() == 0) return "0"; drep(i, v.size() - 1, 0) str.pb(v[i] + '0'); return str; } void init(int d) { fac[d - 1] = 1; drep(i, d - 1, 1) fac[i - 1] = fac[i] * 2; } int calc(int n, int d) { int ans = 0, tmp = 1; drep(i, d - 1, 0) { cnt[i] += n % 2; n = n / 2; tmp *= 2; } return n * tmp; } signed main() { int n, k; scanf("%lld%lld", &n, &k); rep(i, n) scanf("%lld", &a[i]); string str = to_binary(k); int d = str.size(); int ans = 0; init(d); rep(i, n) ans += calc(a[i], d); rep(i, d) { if (i == 0) { dp[0][0] = cnt[0] * fac[0]; if (str[i] == '1') dp[0][1] = (n - cnt[0]) * fac[0]; continue; } if (str[i] == '0') { dp[i][0] = dp[i - 1][0] + max(cnt[i], n - cnt[i]) * fac[i]; dp[i][1] = dp[i - 1][1] + cnt[i] * fac[i]; } else { dp[i][1] = dp[i - 1][1] + (n - cnt[i]) * fac[i]; dp[i][0] = dp[i - 1][1] + cnt[i] * fac[i]; chmax(dp[i][0], dp[i - 1][0] + max(cnt[i], n - cnt[i]) * fac[i]); } } // rep(i,d)printf("%lld ", cnt[i]);printf("\n"); printf("%lld\n", ans + max(dp[d - 1][0], dp[d - 1][1])); return 0; }
[ "identifier.change", "variable_access.subscript.index.change", "call.arguments.change", "expression.operation.binary.change", "io.output.change" ]
939,868
939,869
u691493208
cpp
p03138
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9 + 7; template <typename T> using vector2 = vector<vector<T>>; template <typename T> vector2<T> initVec2(size_t n0, size_t n1, T e = T()) { return vector2<T>(n0, vector<T>(n1, e)); } template <typename T> using vector3 = vector<vector<vector<T>>>; template <typename T> vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()) { return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e))); } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> cnt(40); rep(i, n) { int x = a[i]; rep(j, 40) { cnt[j] += (x >> j) % 2; } } vector<int> pow(41); pow[0] = 1; rep(i, 40) pow[i + 1] = pow[i] * 2; auto dp = initVec3<int>(41, 2, 2, -1); dp[40][0][1] = 0; for (int i = 40; i > 0; i--) { rep(j, 2) { if (dp[i][j][0] != -1) { dp[i - 1][0][0] = max(dp[i - 1][j][0], dp[i][j][0] + cnt[i - 1] * pow[i - 1]); dp[i - 1][1][0] = max(dp[i - 1][j][0], dp[i][j][0] + (n - cnt[i - 1]) * pow[i - 1]); } if (dp[i][j][1] != -1) { if ((k >> (i - 1)) % 2 == 0) { dp[i - 1][0][1] = max(dp[i - 1][0][1], dp[i][j][1] + cnt[i - 1] * pow[i - 1]); } else { dp[i - 1][1][1] = max(dp[i - 1][1][1], dp[i][j][1] + (n - cnt[i - 1]) * pow[i - 1]); dp[i - 1][0][0] = max(dp[i - 1][0][0], dp[i][j][1] + cnt[i - 1] * pow[i - 1]); } } } } cout << max(dp[0][0][0], max(dp[0][1][0], dp[0][k % 2][1])) << endl; return 0; }
#include <algorithm> #include <bitset> #include <cmath> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <utility> #include <vector> #define int long long int #define rep(i, n) for (int i = 0; i < (n); ++i) #define ALL(x) (x).begin(), (x).end() #define SZ(x) ((int)(x).size()) #define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) using namespace std; typedef pair<int, int> P; const int INF = 1e15; const int MOD = 1e9 + 7; template <typename T> using vector2 = vector<vector<T>>; template <typename T> vector2<T> initVec2(size_t n0, size_t n1, T e = T()) { return vector2<T>(n0, vector<T>(n1, e)); } template <typename T> using vector3 = vector<vector<vector<T>>>; template <typename T> vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()) { return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e))); } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, k; cin >> n >> k; vector<int> a(n); rep(i, n) cin >> a[i]; vector<int> cnt(40); rep(i, n) { int x = a[i]; rep(j, 40) { cnt[j] += (x >> j) % 2; } } vector<int> pow(41); pow[0] = 1; rep(i, 40) pow[i + 1] = pow[i] * 2; auto dp = initVec3<int>(41, 2, 2, -1); dp[40][0][1] = 0; for (int i = 40; i > 0; i--) { rep(j, 2) { if (dp[i][j][0] != -1) { dp[i - 1][0][0] = max(dp[i - 1][0][0], dp[i][j][0] + cnt[i - 1] * pow[i - 1]); dp[i - 1][1][0] = max(dp[i - 1][1][0], dp[i][j][0] + (n - cnt[i - 1]) * pow[i - 1]); } if (dp[i][j][1] != -1) { if ((k >> (i - 1)) % 2 == 0) { dp[i - 1][0][1] = max(dp[i - 1][0][1], dp[i][j][1] + cnt[i - 1] * pow[i - 1]); } else { dp[i - 1][1][1] = max(dp[i - 1][1][1], dp[i][j][1] + (n - cnt[i - 1]) * pow[i - 1]); dp[i - 1][0][0] = max(dp[i - 1][0][0], dp[i][j][1] + cnt[i - 1] * pow[i - 1]); } } } } cout << max(dp[0][0][0], max(dp[0][1][0], dp[0][k % 2][1])) << endl; return 0; }
[ "assignment.value.change", "identifier.replace.remove", "literal.replace.add", "variable_access.subscript.index.change", "call.arguments.change" ]
939,872
939,873
u558092537
cpp
p03138
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long int ll; #define all(x) x.begin(), x.end() const ll mod = 1e9 + 7; const ll INF = 1e9; const ll MAXN = 1e9; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll ans = -1; vector<ll> cnt(42); for (int i = 41; i >= 0; i--) { ll mask = 1LL << i; for (int j = 0; j < n; j++) { if (mask & a[j]) cnt[i]++; } } // for(int i = 0; i <= 41; i++){ // cout << cnt[i] << endl; // } ll now = 0; for (int i = 41; i >= 0; i--) { ll mask = 1LL << i; if (k & mask) { now += (mask); ll res = now - (mask); for (int j = i - 1; j >= 0; j--) { if (cnt[j] > n - cnt[j]) res += 1LL << j; } ll res_ans = 0; for (int j = 0; j < n; j++) { res_ans += (a[j] ^ res); } ans = max(res_ans, ans); // cout << "now = " << now << endl; res_ans = 0; for (int j = 0; j < n; j++) { res_ans += (a[j] ^ now); // cout << (a[j]^now) << " "; } // printf("\n"); ans = max(res_ans, ans); } // cout << now << " " << ans << endl; } if (k == 0) ans = accumulate(all(a), (ll)0); cout << ans << endl; return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <string> #include <vector> using namespace std; typedef long long int ll; #define all(x) x.begin(), x.end() const ll mod = 1e9 + 7; const ll INF = 1e9; const ll MAXN = 1e9; int main() { ll n, k; cin >> n >> k; vector<ll> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } ll ans = -1; vector<ll> cnt(42); for (int i = 41; i >= 0; i--) { ll mask = 1LL << i; for (int j = 0; j < n; j++) { if (mask & a[j]) cnt[i]++; } } // for(int i = 0; i <= 41; i++){ // cout << cnt[i] << endl; // } ll now = 0; for (int i = 41; i >= 0; i--) { ll mask = 1LL << i; if (k & mask) { now += (mask); ll res = now - (mask); for (int j = i - 1; j >= 0; j--) { if (cnt[j] < n - cnt[j]) res += 1LL << j; } ll res_ans = 0; for (int j = 0; j < n; j++) { res_ans += (a[j] ^ res); } ans = max(res_ans, ans); // cout << "now = " << now << endl; res_ans = 0; for (int j = 0; j < n; j++) { res_ans += (a[j] ^ now); // cout << (a[j]^now) << " "; } // printf("\n"); ans = max(res_ans, ans); } // cout << now << " " << ans << endl; } if (k == 0) ans = accumulate(all(a), (ll)0); cout << ans << endl; return 0; }
[ "misc.opposites", "expression.operator.compare.change", "control_flow.branch.if.condition.change" ]
939,878
939,879
u700986952
cpp
p03138
#include <bits/stdc++.h> using namespace std; using int64 = int64_t; #define int int64 // dp[i][j] := ibit目まで見てそこまでの値がk未満で(0:ない, 1:ある)時の最大値 int dp[60][2]; signed main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; memset(dp, -1, sizeof(dp)); dp[45][0] = 0; for (int bi = 44; bi >= 0; --bi) { int on_bit_num = 0; for (int ai = 0; ai < n; ++ai) { if ((a[ai] >> bi) & 1) ++on_bit_num; } int digit = (1LL << bi); if (dp[bi + 1][1] >= 0) { dp[bi][1] = max(dp[bi][1], dp[bi + 1][1] + digit * max(on_bit_num, n - on_bit_num)); } if (dp[bi + 1][1] >= 0) { if ((k >> bi) & 1) { dp[bi][1] = max(dp[bi][1], dp[bi + 1][0] + digit * on_bit_num); dp[bi][0] = max(dp[bi][0], dp[bi + 1][0] + digit * (n - on_bit_num)); } else { dp[bi][0] = max(dp[bi][0], dp[bi + 1][0] + digit * on_bit_num); } } } int ans = max(dp[0][0], dp[0][1]); cout << ans << endl; return 0; }
#include <bits/stdc++.h> using namespace std; using int64 = int64_t; #define int int64 // dp[i][j] := ibit目まで見てそこまでの値がk未満で(0:ない, 1:ある)時の最大値 int dp[60][2]; signed main() { int n, k; cin >> n >> k; vector<int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; memset(dp, -1, sizeof(dp)); dp[45][0] = 0; for (int bi = 44; bi >= 0; --bi) { int on_bit_num = 0; for (int ai = 0; ai < n; ++ai) { if ((a[ai] >> bi) & 1) ++on_bit_num; } int digit = (1LL << bi); if (dp[bi + 1][1] >= 0) { dp[bi][1] = max(dp[bi][1], dp[bi + 1][1] + digit * max(on_bit_num, n - on_bit_num)); } if (dp[bi + 1][0] >= 0) { if ((k >> bi) & 1) { dp[bi][1] = max(dp[bi][1], dp[bi + 1][0] + digit * on_bit_num); dp[bi][0] = max(dp[bi][0], dp[bi + 1][0] + digit * (n - on_bit_num)); } else { dp[bi][0] = max(dp[bi][0], dp[bi + 1][0] + digit * on_bit_num); } } } int ans = max(dp[0][0], dp[0][1]); cout << ans << endl; return 0; }
[ "literal.number.change", "variable_access.subscript.index.change", "control_flow.branch.if.condition.change" ]
939,884
939,885
u258009780
cpp
p03138
//{ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double lf; typedef pair<ll, ll> ii; #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (ll i = 1; i <= n; i++) #define FILL(i, n) memset(i, n, sizeof i) #define X first #define Y second #define SZ(_a) (int)_a.size() #define ALL(_a) _a.begin(), _a.end() #define pb push_back #ifdef brian #define debug(...) \ do { \ fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, \ #__VA_ARGS__); \ _do(__VA_ARGS__); \ } while (0) template <typename T> void _do(T &&_x) { cerr << _x << endl; } template <typename T, typename... S> void _do(T &&_x, S &&..._t) { cerr << _x << " ,"; _do(_t...); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, const pair<_a, _b> &_p) { return _s << "(" << _p.X << "," << _p.Y << ")"; } template <typename It> ostream &_OUTC(ostream &_s, It _ita, It _itb) { _s << "{"; for (It _it = _ita; _it != _itb; _it++) { _s << (_it == _ita ? "" : ",") << *_it; } _s << "}"; return _s; } template <typename _a> ostream &operator<<(ostream &_s, vector<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a> ostream &operator<<(ostream &_s, set<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, map<_a, _b> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _t> void pary(_t _a, _t _b) { _OUTC(cerr, _a, _b); cerr << endl; } #define IOS() #else #define debug(...) #define pary(...) #define endl '\n' #define IOS() \ ios_base::sync_with_stdio(0); \ cin.tie(0); #endif // brian //} const ll MAXn = 1e5 + 5, MAXlg = __lg(MAXn) + 2; const ll MOD = 1000000007; const ll INF = ll(8e18); ll d[MAXn]; ll dp[60][2]; ll n, k; ll ct(ll t) { ll tt = 0; REP(i, n) if (t & d[i]) tt++; return tt; } int main() { IOS(); cin >> n >> k; REP(i, n) cin >> d[i]; dp[59][0] = -INF; for (int i = 58; i >= 0; i--) { ll t = ct((1LL << i)); if ((1LL << i) & k) { dp[i][0] = max(max(dp[i + 1][0], dp[i + 1][1]) + t * (1LL << i), dp[i + 1][0] + (n - t) * (1LL << i)); dp[i][1] = dp[i + 1][1] + (n - t) * (1LL << i); } else { dp[i][0] = max(dp[i + 1][0] + t * (1LL << i), dp[i + 1][0] + (n - t) * (1LL << i)); dp[i][1] = dp[i + 1][1] + t * (1LL << i); } } cout << max(dp[0][0], dp[0][1]) << endl; }
//{ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double lf; typedef pair<ll, ll> ii; #define REP(i, n) for (ll i = 0; i < n; i++) #define REP1(i, n) for (ll i = 1; i <= n; i++) #define FILL(i, n) memset(i, n, sizeof i) #define X first #define Y second #define SZ(_a) (int)_a.size() #define ALL(_a) _a.begin(), _a.end() #define pb push_back #ifdef brian #define debug(...) \ do { \ fprintf(stderr, "%s - %d (%s) = ", __PRETTY_FUNCTION__, __LINE__, \ #__VA_ARGS__); \ _do(__VA_ARGS__); \ } while (0) template <typename T> void _do(T &&_x) { cerr << _x << endl; } template <typename T, typename... S> void _do(T &&_x, S &&..._t) { cerr << _x << " ,"; _do(_t...); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, const pair<_a, _b> &_p) { return _s << "(" << _p.X << "," << _p.Y << ")"; } template <typename It> ostream &_OUTC(ostream &_s, It _ita, It _itb) { _s << "{"; for (It _it = _ita; _it != _itb; _it++) { _s << (_it == _ita ? "" : ",") << *_it; } _s << "}"; return _s; } template <typename _a> ostream &operator<<(ostream &_s, vector<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a> ostream &operator<<(ostream &_s, set<_a> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _a, typename _b> ostream &operator<<(ostream &_s, map<_a, _b> &_c) { return _OUTC(_s, ALL(_c)); } template <typename _t> void pary(_t _a, _t _b) { _OUTC(cerr, _a, _b); cerr << endl; } #define IOS() #else #define debug(...) #define pary(...) #define endl '\n' #define IOS() \ ios_base::sync_with_stdio(0); \ cin.tie(0); #endif // brian //} const ll MAXn = 1e5 + 5, MAXlg = __lg(MAXn) + 2; const ll MOD = 1000000007; const ll INF = ll(8e18); ll d[MAXn]; ll dp[60][2]; ll n, k; ll ct(ll t) { ll tt = 0; REP(i, n) if (t & d[i]) tt++; return tt; } int main() { IOS(); cin >> n >> k; REP(i, n) cin >> d[i]; dp[41][0] = -INF; for (int i = 40; i >= 0; i--) { ll t = ct((1LL << i)); if ((1LL << i) & k) { dp[i][0] = max(max(dp[i + 1][0], dp[i + 1][1]) + t * (1LL << i), dp[i + 1][0] + (n - t) * (1LL << i)); dp[i][1] = dp[i + 1][1] + (n - t) * (1LL << i); } else { dp[i][0] = max(dp[i + 1][0] + t * (1LL << i), dp[i + 1][0] + (n - t) * (1LL << i)); dp[i][1] = dp[i + 1][1] + t * (1LL << i); } } cout << max(dp[0][0], dp[0][1]) << endl; }
[ "literal.number.change", "assignment.variable.change", "variable_access.subscript.index.change", "variable_declaration.value.change", "control_flow.loop.for.initializer.change" ]
939,888
939,889
u882946280
cpp
p03138
#include <iostream> using namespace std; int main(void) { long long N, K, k, M, S, T, i; cin >> N >> K; long long A[N]; S = 0; for (i = 0; i < N; i++) { cin >> A[i]; S += A[i]; } M = 1; while (M < K) { M *= 2; } M /= 2; k = 0; while (M > 0) { k += M; T = 0; for (i = 0; i < N; i++) { T += A[i] ^ k; } if (T > S && k < K + 1) { S = T; } else { k -= M; } M /= 2; } cout << S << endl; }
#include <iostream> using namespace std; int main(void) { long long N, K, k, M, S, T, i; cin >> N >> K; long long A[N]; S = 0; for (i = 0; i < N; i++) { cin >> A[i]; S += A[i]; } M = 1; while (M < K + 1) { M *= 2; } M /= 2; k = 0; while (M > 0) { k += M; T = 0; for (i = 0; i < N; i++) { T += A[i] ^ k; } if (T > S && k < K + 1) { S = T; } else { k -= M; } M /= 2; } cout << S << endl; }
[ "control_flow.loop.condition.change" ]
939,894
939,895
u965103758
cpp
p03138
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define mp make_pair #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define PI 3.14159265358979323846 using namespace std; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> pii; typedef long double ld; typedef string st; const ll MOD = 1e9 + 7; const ll INF = 1e14; ll mpow(ll a, ll b, ll p = MOD) { a = a % p; ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b = b >> 1; } return res % p; } const ll N = 500020; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll ans = 0; ford(x, 40) { ll cnt1 = 0, cnt2 = 0; forn(i, n) { if ((a[i] >> x) & 1) cnt1++; else cnt2++; } // cout<<cnt1<<" "<<cnt2<<"\n"; if (cnt1 >= cnt2) { } else { if (ans + (1LL << x) < k) { ans += (1LL << x); } } } ll an = 0; forn(i, n) an += (a[i] ^ ans); cout << an; }
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> using namespace std; using namespace __gnu_pbds; typedef tree<pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; #define mp make_pair #define fi first #define se second #define pb push_back #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define forn(i, n) for (int i = 0; i < (int)(n); ++i) #define for1(i, n) for (int i = 1; i <= (int)(n); ++i) #define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i) #define PI 3.14159265358979323846 using namespace std; typedef long long ll; typedef vector<ll> vi; typedef vector<vi> vvi; typedef pair<ll, ll> pii; typedef long double ld; typedef string st; const ll MOD = 1e9 + 7; const ll INF = 1e14; ll mpow(ll a, ll b, ll p = MOD) { a = a % p; ll res = 1; while (b > 0) { if (b & 1) res = (res * a) % p; a = (a * a) % p; b = b >> 1; } return res % p; } const ll N = 500020; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; ll a[n]; forn(i, n) cin >> a[i]; ll ans = 0; ford(x, 40) { ll cnt1 = 0, cnt2 = 0; forn(i, n) { if ((a[i] >> x) & (1LL)) cnt1++; else cnt2++; } // cout<<cnt1<<" "<<cnt2<<"\n"; if (cnt1 >= cnt2) { } else { if (ans + (1LL << x) <= k) { ans += (1LL << x); } } } ll an = 0; forn(i, n) an += (a[i] ^ ans); cout << an; }
[ "control_flow.branch.if.condition.change", "expression.operator.compare.change" ]
939,896
939,897
u862316882
cpp
p03138
#include <bits/stdc++.h> using namespace std; const long long NMAX = 1e5; const long long BMAX = 60; long long v[NMAX + 2], N, K; long long ans = 0; long long nr[BMAX + 2], sp_nr[BMAX + 2], best_sp[BMAX + 2]; int main() { cin >> N >> K; for (long long i = 1; i <= N; ++i) { cin >> v[i]; for (long long j = 0; j <= BMAX; ++j) { nr[j] += (((1LL << j) & v[i]) != 0); } } sp_nr[0] = nr[0]; best_sp[0] = max(nr[0], N - nr[0]); for (long long i = 1; i <= BMAX; ++i) sp_nr[i] = sp_nr[i - 1] + (1LL << i) * nr[i], best_sp[i] = best_sp[i - 1] + (1LL << i) * max(nr[i], N - nr[i]); for (long long pre_sum = 0, b = BMAX; b >= 0; --b) { if (((1LL << b) & K) != 0) { if (b > 0) { ans = max(ans, pre_sum + (N - nr[b]) * (1LL << b) + best_sp[b - 1]); } } long long coef = nr[b]; if (((1LL << b) & K) != 0) coef = N - nr[b]; pre_sum += (1LL << b) * coef; ans = max(ans, pre_sum); } cout << ans << '\n'; return 0; }
#include <bits/stdc++.h> using namespace std; const long long NMAX = 1e5; const long long BMAX = 60; long long v[NMAX + 2], N, K; long long ans = 0; long long nr[BMAX + 2], sp_nr[BMAX + 2], best_sp[BMAX + 2]; int main() { cin >> N >> K; for (long long i = 1; i <= N; ++i) { cin >> v[i]; for (long long j = 0; j <= BMAX; ++j) { nr[j] += (((1LL << j) & v[i]) != 0); } } sp_nr[0] = nr[0]; best_sp[0] = max(nr[0], N - nr[0]); for (long long i = 1; i <= BMAX; ++i) sp_nr[i] = sp_nr[i - 1] + (1LL << i) * nr[i], best_sp[i] = best_sp[i - 1] + (1LL << i) * max(nr[i], N - nr[i]); for (long long pre_sum = 0, b = BMAX; b >= 0; --b) { if (((1LL << b) & K) != 0) { if (b > 0) { ans = max(ans, pre_sum + nr[b] * (1LL << b) + best_sp[b - 1]); } } long long coef = nr[b]; if (((1LL << b) & K) != 0) coef = N - nr[b]; pre_sum += (1LL << b) * coef; ans = max(ans, pre_sum); } cout << ans << '\n'; return 0; }
[ "expression.operation.binary.remove", "call.arguments.change" ]
939,907
939,908
u781135700
cpp
p03138
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define MOD 1000000007 #define f(i, n) for (long long i = 0; i < (long long)(n); i++) #define N 200000 int main() { long long a[50]; long long b[50]; f(i, N) a[i] = 0; long long k; long long n, m; long long x, y, z; bool v = true; x = 0; y = 0; scanf("%lld %lld", &n, &k); f(i, n) { scanf("%lld", &x); m = 0; while (x > 0) { if (x % 2 == 1) a[m]++; x /= 2; m++; } } z = 0; long long ans = 0; b[0] = 1; f(i, 49) b[i + 1] = b[i] * 2; for (int i = 49; i >= 0; i--) { if ((a[i] * 2) >= n) ans += (a[i] * b[i]); else { if (z + b[i] <= k) { ans += ((n - a[i]) * b[i]); z += b[i]; } else ans += (a[i] * b[i]); } } printf("%lld\n", ans); return 0; }
#include <algorithm> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <map> #include <queue> #include <set> #include <stack> #include <vector> using namespace std; #define MOD 1000000007 #define f(i, n) for (long long i = 0; i < (long long)(n); i++) #define N 200000 int main() { long long a[50]; long long b[50]; f(i, 50) a[i] = 0; long long k; long long n, m; long long x, y, z; bool v = true; x = 0; y = 0; scanf("%lld %lld", &n, &k); f(i, n) { scanf("%lld", &x); m = 0; while (x > 0) { if (x % 2 == 1) a[m]++; x /= 2; m++; } } z = 0; long long ans = 0; b[0] = 1; f(i, 49) b[i + 1] = b[i] * 2; for (int i = 49; i >= 0; i--) { if ((a[i] * 2) >= n) ans += (a[i] * b[i]); else { if (z + b[i] <= k) { ans += ((n - a[i]) * b[i]); z += b[i]; } else ans += (a[i] * b[i]); } } printf("%lld\n", ans); return 0; }
[ "assignment.variable.change", "identifier.replace.remove", "literal.replace.add", "call.arguments.change" ]
939,909
939,910
u527748649
cpp
p03138
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < ll(n); ++i) #define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < ll(n); ++i) #define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i) #define ALL(v) (v).begin(), (v).end() #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vl v(n); REP(i, n) cin >> v[i]; ll x = 0; RREP(i, 50) { int cnt0 = 0, cnt1 = 0; REP(j, n) { if ((1ll << i) & v[j]) cnt1++; else cnt0++; } if (cnt0 > cnt1) { if ((x | (1ll << i) <= k)) x |= (1ll << i); } } ll ans = 0; REP(i, n) { ans += x ^ v[i]; } cout << ans << endl; }
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < ll(n); ++i) #define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < ll(n); ++i) #define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i) #define ALL(v) (v).begin(), (v).end() #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vl v(n); REP(i, n) cin >> v[i]; ll x = 0; RREP(i, 50) { int cnt0 = 0, cnt1 = 0; REP(j, n) { if ((1ll << i) & v[j]) cnt1++; else cnt0++; } if (cnt0 > cnt1) { if ((x | (1ll << i)) <= k) x |= (1ll << i); } } ll ans = 0; REP(i, n) { ans += x ^ v[i]; } cout << ans << endl; }
[ "control_flow.branch.if.condition.change" ]
939,911
939,912
u918357423
cpp
p03138
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < ll(n); ++i) #define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < ll(n); ++i) #define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i) #define ALL(v) (v).begin(), (v).end() #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vl v(n); REP(i, n) cin >> v[i]; ll x = 0; RREP(i, 50) { int cnt0 = 0, cnt1 = 0; REP(j, n) { if ((1 << i) & v[j]) cnt1++; else cnt0++; } if (cnt0 > cnt1) { if ((x | (1ll << i) <= k)) x |= (1ll << i); } } ll ans = 0; REP(i, n) { ans += x ^ v[i]; } cout << ans << endl; }
#include "bits/stdc++.h" #define REP(i, n) for (ll i = 0; i < ll(n); ++i) #define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i) #define FOR(i, m, n) for (ll i = m; i < ll(n); ++i) #define RFOR(i, m, n) for (ll i = ll(n) - 1; i >= ll(m); --i) #define ALL(v) (v).begin(), (v).end() #define UNIQUE(v) v.erase(unique(ALL(v)), v.end()); #define INF 1000000001ll #define MOD 1000000007ll #define EPS 1e-9 constexpr int dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; constexpr int dy[8] = {0, 1, 1, 1, 0, -1, -1, -1}; using namespace std; using ll = long long; using vi = vector<int>; using vl = vector<ll>; using vvi = vector<vi>; using vvl = vector<vl>; using pii = pair<int, int>; using pll = pair<ll, ll>; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } int main() { cin.tie(0); ios::sync_with_stdio(false); ll n, k; cin >> n >> k; vl v(n); REP(i, n) cin >> v[i]; ll x = 0; RREP(i, 50) { int cnt0 = 0, cnt1 = 0; REP(j, n) { if ((1ll << i) & v[j]) cnt1++; else cnt0++; } if (cnt0 > cnt1) { if ((x | (1ll << i)) <= k) x |= (1ll << i); } } ll ans = 0; REP(i, n) { ans += x ^ v[i]; } cout << ans << endl; }
[ "control_flow.branch.if.condition.change" ]
939,913
939,912
u918357423
cpp
p03139
#include <iostream> #include <stdio.h> //#include <bits/stdc++.h> #include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdint> #include <cstring> #include <float.h> #include <iomanip> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define INF 1e9 #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++) #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define vec(type, n) vector<type>(n) #define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n)) #define ALL(a) (a).begin(), (a).end() #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) #define Vl vector<ll> using namespace std; using ll = long long; using Graph = vector<vector<ll>>; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll ZER = 0; int main() { int n, a, b; cin >> n >> a >> b; int ma = min(a, b), mi = min(0, a + b - n); cout << ma << " " << mi << endl; }
#include <iostream> #include <stdio.h> //#include <bits/stdc++.h> #include <algorithm> #include <array> #include <cassert> #include <cmath> #include <cstdint> #include <cstring> #include <float.h> #include <iomanip> #include <map> #include <math.h> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <vector> #define INF 1e9 #define rep(i, n) for (int i = 0; (i) < (int)(n); i++) #define REP(i, a, b) for (int i = (int)(a); (i) <= (int)(b); i++) #define VEC(type, c, n) \ std::vector<type> c(n); \ for (auto &i : c) \ std::cin >> i; #define vec(type, n) vector<type>(n) #define vvec(m, n) vector<vector<int>>(int(m), vector<int>(n)) #define ALL(a) (a).begin(), (a).end() #define chmin(a, b) a = min(a, b) #define chmax(a, b) a = max(a, b) #define Vl vector<ll> using namespace std; using ll = long long; using Graph = vector<vector<ll>>; using P = pair<ll, ll>; const ll MOD = 1e9 + 7; const ll ZER = 0; int main() { int n, a, b; cin >> n >> a >> b; int ma = min(a, b), mi = max(0, a + b - n); cout << ma << " " << mi << endl; }
[ "misc.opposites", "identifier.change", "call.function.change" ]
939,920
939,921
u516525290
cpp
p03139
#include <bits/stdc++.h> //#include<atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; // dijkstra  struct edge { ll to, cost; }; typedef pair<ll, ll> P; struct graph { ll V; vector<vector<edge>> G; vector<ll> d; graph(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } }; // dijkstra end class UnionFind { public: ll par[200005]; ll depth[200005]; ll nGroup[200005]; UnionFind(ll n) { init(n); } void init(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; depth[i] = 0; nGroup[i] = 1; } } ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } bool same(ll x, ll y) { return root(x) == root(y); } void unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (depth[x] < depth[y]) { par[x] = y; nGroup[y] += nGroup[x]; nGroup[x] = 0; } else { par[y] = x; nGroup[x] += nGroup[y]; nGroup[y] = 0; if (depth[x] == depth[y]) depth[x]++; } } }; // unionfind end // nCr const ll MAX = 500010; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // nCr end // tree DP vector<ll> depth; vector<ll> f; vector<ll> g; void dfs(const Graph &G, ll v, ll p, ll d) { depth[v] = d; for (auto nv : G[v]) { if (nv == p) continue; dfs(G, nv, v, d + 1); } f[v] = 1; g[v] = 1; for (auto c : G[v]) { if (c == p) continue; f[v] *= g[c]; f[v] %= MOD; g[v] *= f[c]; g[v] %= MOD; } f[v] += g[v]; f[v] %= MOD; } // tree DP end template <ll MOD> struct Fp { ll val; constexpr Fp(ll v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr ll getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { ll a = r.val, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, ll n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; mint calc(ll N, ll K) { mint res = 1; for (ll n = 0; n < K; ++n) { res *= (N - n); res /= (n + 1); } return res; } mint COM(ll n, ll k) { if (k == 0) return 1; if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << min(a + b - n, (ll)0) << endl; }
#include <bits/stdc++.h> //#include<atcoder/all> using namespace std; // using namespace atcoder; #define rep(i, n) for (ll i = 0; i < n; i++) #define repl(i, l, r) for (ll i = (l); i < (r); i++) #define per(i, n) for (ll i = n - 1; i >= 0; i--) #define perl(i, r, l) for (ll i = r - 1; i >= l; i--) #define fi first #define se second #define pb push_back #define ins insert #define all(x) (x).begin(), (x).end() using ll = long long; using vl = vector<ll>; using vvl = vector<vector<ll>>; const ll MOD = 1000000007; const ll MOD9 = 998244353; const int inf = 1e9 + 10; const ll INF = 4e18; const ll dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const ll dx[8] = {0, -1, 0, 1, 1, -1, 1, -1}; using Graph = vector<vector<int>>; // dijkstra  struct edge { ll to, cost; }; typedef pair<ll, ll> P; struct graph { ll V; vector<vector<edge>> G; vector<ll> d; graph(ll n) { init(n); } void init(ll n) { V = n; G.resize(V); d.resize(V); rep(i, V) { d[i] = INF; } } void add_edge(ll s, ll t, ll cost) { edge e; e.to = t, e.cost = cost; G[s].push_back(e); } void dijkstra(ll s) { rep(i, V) { d[i] = INF; } d[s] = 0; priority_queue<P, vector<P>, greater<P>> que; que.push(P(0, s)); while (!que.empty()) { P p = que.top(); que.pop(); ll v = p.second; if (d[v] < p.first) continue; for (auto e : G[v]) { if (d[e.to] > d[v] + e.cost) { d[e.to] = d[v] + e.cost; que.push(P(d[e.to], e.to)); } } } } }; // dijkstra end class UnionFind { public: ll par[200005]; ll depth[200005]; ll nGroup[200005]; UnionFind(ll n) { init(n); } void init(ll n) { for (ll i = 0; i < n; i++) { par[i] = i; depth[i] = 0; nGroup[i] = 1; } } ll root(ll x) { if (par[x] == x) { return x; } else { return par[x] = root(par[x]); } } bool same(ll x, ll y) { return root(x) == root(y); } void unite(ll x, ll y) { x = root(x); y = root(y); if (x == y) return; if (depth[x] < depth[y]) { par[x] = y; nGroup[y] += nGroup[x]; nGroup[x] = 0; } else { par[y] = x; nGroup[x] += nGroup[y]; nGroup[y] = 0; if (depth[x] == depth[y]) depth[x]++; } } }; // unionfind end // nCr const ll MAX = 500010; ll fac[MAX], finv[MAX], inv[MAX]; void COMinit() { fac[0] = fac[1] = 1; finv[0] = finv[1] = 1; inv[1] = 1; for (ll i = 2; i < MAX; i++) { fac[i] = fac[i - 1] * i % MOD; inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD; finv[i] = finv[i - 1] * inv[i] % MOD; } } // nCr end // tree DP vector<ll> depth; vector<ll> f; vector<ll> g; void dfs(const Graph &G, ll v, ll p, ll d) { depth[v] = d; for (auto nv : G[v]) { if (nv == p) continue; dfs(G, nv, v, d + 1); } f[v] = 1; g[v] = 1; for (auto c : G[v]) { if (c == p) continue; f[v] *= g[c]; f[v] %= MOD; g[v] *= f[c]; g[v] %= MOD; } f[v] += g[v]; f[v] %= MOD; } // tree DP end template <ll MOD> struct Fp { ll val; constexpr Fp(ll v = 0) noexcept : val(v % MOD) { if (val < 0) val += MOD; } constexpr ll getmod() { return MOD; } constexpr Fp operator-() const noexcept { return val ? MOD - val : 0; } constexpr Fp operator+(const Fp &r) const noexcept { return Fp(*this) += r; } constexpr Fp operator-(const Fp &r) const noexcept { return Fp(*this) -= r; } constexpr Fp operator*(const Fp &r) const noexcept { return Fp(*this) *= r; } constexpr Fp operator/(const Fp &r) const noexcept { return Fp(*this) /= r; } constexpr Fp &operator+=(const Fp &r) noexcept { val += r.val; if (val >= MOD) val -= MOD; return *this; } constexpr Fp &operator-=(const Fp &r) noexcept { val -= r.val; if (val < 0) val += MOD; return *this; } constexpr Fp &operator*=(const Fp &r) noexcept { val = val * r.val % MOD; return *this; } constexpr Fp &operator/=(const Fp &r) noexcept { ll a = r.val, b = MOD, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } val = val * u % MOD; if (val < 0) val += MOD; return *this; } constexpr bool operator==(const Fp &r) const noexcept { return this->val == r.val; } constexpr bool operator!=(const Fp &r) const noexcept { return this->val != r.val; } friend constexpr ostream &operator<<(ostream &os, const Fp<MOD> &x) noexcept { return os << x.val; } friend constexpr Fp<MOD> modpow(const Fp<MOD> &a, ll n) noexcept { if (n == 0) return 1; auto t = modpow(a, n / 2); t = t * t; if (n & 1) t = t * a; return t; } }; using mint = Fp<MOD>; mint calc(ll N, ll K) { mint res = 1; for (ll n = 0; n < K; ++n) { res *= (N - n); res /= (n + 1); } return res; } mint COM(ll n, ll k) { if (k == 0) return 1; if (n < k) return 0; if (n < 0 || k < 0) return 0; return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD; } int main() { ll n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << max(a + b - n, (ll)0) << endl; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change" ]
939,922
939,923
u722640678
cpp
p03139
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { int N, A, B; cin >> N >> A >> B; cout << min(A, B) << " " << min(0, A + B - N) << endl; return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; using ll = long long; int main() { int N, A, B; cin >> N >> A >> B; cout << min(A, B) << " " << max(0, A + B - N) << endl; return 0; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change" ]
939,926
939,927
u629603666
cpp
p03139
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B; cin >> N >> A >> B; // int X=max(A,B); int Y = min(A, B); if (A + B <= N) cout << Y << " " << 0 << endl; else cout << Y << " " << N - A - B << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int N, A, B; cin >> N >> A >> B; // int X=max(A,B); int Y = min(A, B); if (A + B <= N) cout << Y << " " << 0 << endl; else cout << Y << " " << A + B - N << endl; }
[ "expression.operation.binary.remove", "misc.opposites", "expression.operator.arithmetic.change", "io.output.change" ]
939,935
939,936
u430394202
cpp
p03139
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { int A, B, C; cin >> A >> B >> C; cout << min(A, B) << " "; if (A >= B + C) { cout << 0 << endl; } else { cout << B + C - A << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) int main() { int A, B, C; cin >> A >> B >> C; cout << min(C, B) << " "; if (A >= B + C) { cout << 0 << endl; } else { cout << B + C - A << endl; } }
[ "identifier.change", "io.output.change" ]
939,939
939,940
u025773431
cpp
p03139
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge { ll to, cost; }; struct edge2 { ll from, to, cost; }; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, a, b; cin >> n >> a >> b; cout << min(a + b, n) << " " << max((ll)0, a + b - n) << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge { ll to, cost; }; struct edge2 { ll from, to, cost; }; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << max((ll)0, a + b - n) << endl; }
[ "expression.operation.binary.remove", "identifier.change", "io.output.change" ]
939,946
939,947
u328811800
cpp
p03139
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge { ll to, cost; }; struct edge2 { ll from, to, cost; }; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, a, b; cin >> n >> a >> b; cout << max(a + b, n) << " " << max((ll)0, a + b - n) << endl; }
#define _GLIBCXX_DEBUG #include <bits/stdc++.h> #define FOR(i, a, b) for (ll i = a; i < b; i++) #define rep(i, n) FOR(i, 0, n) #define ROF(i, a, b) for (ll i = a; i >= b; i--) #define per(i, a) ROF(i, a, 0) #define pb push_back using namespace std; using ll = long long; using ld = long double; using ch = char; typedef pair<ll, ll> P; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<P> vP; typedef vector<ch> vc; typedef vector<vc> vvc; const ll MOD = 1000000007; const ll MOD2 = 998244353; const ld PI = acos(-1); const ll INF = 1e18; struct edge { ll to, cost; }; struct edge2 { ll from, to, cost; }; template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << max((ll)0, a + b - n) << endl; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change", "expression.operation.binary.remove" ]
939,948
939,947
u328811800
cpp
p03139
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { int n, a, b; scanf("%d%d%d", &n, &a, &b); printf("%d %d\n", max(a, b), max(a + b - n, 0)); return 0; }
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { int n, a, b; scanf("%d%d%d", &n, &a, &b); printf("%d %d\n", min(a, b), max(a + b - n, 0)); return 0; }
[ "misc.opposites", "identifier.change", "call.function.change", "call.arguments.change", "io.output.change" ]
939,949
939,950
u781095600
cpp
p03139
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << ' ' << b - (n - a) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << ' ' << max(b - (n - a), 0) << endl; }
[ "call.add", "call.arguments.add" ]
939,951
939,952
u691380397
cpp
p03139
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0)->sync_with_stdio(false); int n, a, b; cin >> n >> a >> b; cout << min(a, b) << ' ' << min(0, a + b - n) << '\n'; // cout << min(a, b) << ' ' << min(a - (n - b), b - (n -a)) << '\n'; return 0; }
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) using namespace std; int main() { cin.tie(0)->sync_with_stdio(false); int n, a, b; cin >> n >> a >> b; cout << min(a, b) << ' ' << max(0, a + b - n) << '\n'; // cout << min(a, b) << ' ' << min(a - (n - b), b - (n -a)) << '\n'; return 0; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change" ]
939,966
939,967
u596385287
cpp
p03139
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; cout << min(B, C) << " " << B + C - A << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int A, B, C; cin >> A >> B >> C; cout << min(B, C) << " " << max(B + C - A, 0) << endl; }
[ "call.add", "call.arguments.add" ]
939,974
939,975
u237390401
cpp
p03139
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define all(x) x.begin(), x.end() #define lscan(x) scanf("%I64d", &x) #define lprint(x) printf("%I64d", x) ll gcd(ll a, ll b) { int c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return b; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } struct UnionFind { vector<int> data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; ll M = 1000000007; vector<ll> fac(2000011); // n!(mod M) vector<ll> ifac(2000011); // k!^{M-2} (mod M) ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll mpow2(ll x, ll n, ll mod) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n = n >> 1; } return ans; } void setcomb() { fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < 2000010; i++) { fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M) } ifac[2000010] = mpow(fac[2000010], M - 2); for (ll i = 2000010; i > 0; i--) { ifac[i - 1] = ifac[i] * i % M; } } ll comb(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll perm(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; return fac[a] * ifac[a - b] % M; } long long modinv(long long a) { long long b = M, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= M; if (u < 0) u += M; return u; } ll modinv2(ll a, ll mod) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) { int i, j, k, t; vector<vector<ll>> c(n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { t = 0; for (k = 0; k < n; k++) t = (t + a[i][k] * b[k][j] % M) % M; c[i].push_back(t); } } return c; } template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; template <unsigned mod> struct RollingHash { vector<unsigned> hashed, power; inline unsigned mul(unsigned a, unsigned b) const { unsigned long long x = (unsigned long long)a * b; unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod)); return m; } RollingHash(const string &s, unsigned base = 10007) { int sz = (int)s.size(); hashed.assign(sz + 1, 0); power.assign(sz + 1, 0); power[0] = 1; for (int i = 0; i < sz; i++) { power[i + 1] = mul(power[i], base); hashed[i + 1] = mul(hashed[i], base) + s[i]; if (hashed[i + 1] >= mod) hashed[i + 1] -= mod; } } unsigned get(int l, int r) const { unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]); if (ret >= mod) ret -= mod; return ret; } unsigned connect(unsigned h1, int h2, int h2len) const { unsigned ret = mul(h1, power[h2len]) + h2; if (ret >= mod) ret -= mod; return ret; } int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) { int len = min(r1 - l1, r2 - l2); int low = -1, high = len + 1; while (high - low > 1) { int mid = (low + high) / 2; if (get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid; else high = mid; } return (low); } }; using RH = RollingHash<1000000007>; template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; template <typename G> struct DoublingLowestCommonAncestor { const int LOG; vector<int> dep; const G &g; vector<vector<int>> table; DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) { table.assign(LOG, vector<int>(g.size(), -1)); } void dfs(int idx, int par, int d) { table[0][idx] = par; dep[idx] = d; for (auto &to : g[idx]) { if (to != par) dfs(to, idx, d + 1); } } void build() { dfs(0, -1, 0); for (int k = 0; k + 1 < LOG; k++) { for (int i = 0; i < table[k].size(); i++) { if (table[k][i] == -1) table[k + 1][i] = -1; else table[k + 1][i] = table[k][table[k][i]]; } } } int query(int u, int v) { if (dep[u] > dep[v]) swap(u, v); for (int i = LOG - 1; i >= 0; i--) { if (((dep[v] - dep[u]) >> i) & 1) v = table[i][v]; } if (u == v) return u; for (int i = LOG - 1; i >= 0; i--) { if (table[i][u] != table[i][v]) { u = table[i][u]; v = table[i][v]; } } return table[0][u]; } }; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << min(0, a + b - n) << endl; }
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb(x) push_back(x) #define mp(a, b) make_pair(a, b) #define all(x) x.begin(), x.end() #define lscan(x) scanf("%I64d", &x) #define lprint(x) printf("%I64d", x) ll gcd(ll a, ll b) { int c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return b; } long long extGCD(long long a, long long b, long long &x, long long &y) { if (b == 0) { x = 1; y = 0; return a; } long long d = extGCD(b, a % b, y, x); y -= a / b * x; return d; } struct UnionFind { vector<int> data; UnionFind(int sz) { data.assign(sz, -1); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return (false); if (data[x] > data[y]) swap(x, y); data[x] += data[y]; data[y] = x; return (true); } int find(int k) { if (data[k] < 0) return (k); return (data[k] = find(data[k])); } int size(int k) { return (-data[find(k)]); } }; ll M = 1000000007; vector<ll> fac(2000011); // n!(mod M) vector<ll> ifac(2000011); // k!^{M-2} (mod M) ll mpow(ll x, ll n) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % M; x = x * x % M; n = n >> 1; } return ans; } ll mpow2(ll x, ll n, ll mod) { ll ans = 1; while (n != 0) { if (n & 1) ans = ans * x % mod; x = x * x % mod; n = n >> 1; } return ans; } void setcomb() { fac[0] = 1; ifac[0] = 1; for (ll i = 0; i < 2000010; i++) { fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M) } ifac[2000010] = mpow(fac[2000010], M - 2); for (ll i = 2000010; i > 0; i--) { ifac[i - 1] = ifac[i] * i % M; } } ll comb(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; ll tmp = ifac[a - b] * ifac[b] % M; return tmp * fac[a] % M; } ll perm(ll a, ll b) { if (a == 0 && b == 0) return 1; if (a < b || a < 0) return 0; return fac[a] * ifac[a - b] % M; } long long modinv(long long a) { long long b = M, u = 1, v = 0; while (b) { long long t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= M; if (u < 0) u += M; return u; } ll modinv2(ll a, ll mod) { ll b = mod, u = 1, v = 0; while (b) { ll t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) { int i, j, k, t; vector<vector<ll>> c(n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { t = 0; for (k = 0; k < n; k++) t = (t + a[i][k] * b[k][j] % M) % M; c[i].push_back(t); } } return c; } template <typename Monoid> struct SegmentTree { using F = function<Monoid(Monoid, Monoid)>; int sz; vector<Monoid> seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while (sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for (int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while (k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) L = f(L, seg[a++]); if (b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } template <typename C> int find_subtree(int a, const C &check, Monoid &M, bool type) { while (a < sz) { Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]); if (check(nxt)) a = 2 * a + type; else M = nxt, a = 2 * a + 1 - type; } return a - sz; } template <typename C> int find_first(int a, const C &check) { Monoid L = M1; if (a <= 0) { if (check(f(L, seg[1]))) return find_subtree(1, check, L, false); return -1; } int b = sz; for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if (a & 1) { Monoid nxt = f(L, seg[a]); if (check(nxt)) return find_subtree(a, check, L, false); L = nxt; ++a; } } return -1; } template <typename C> int find_last(int b, const C &check) { Monoid R = M1; if (b >= sz) { if (check(f(seg[1], R))) return find_subtree(1, check, R, true); return -1; } int a = sz; for (b += sz; a < b; a >>= 1, b >>= 1) { if (b & 1) { Monoid nxt = f(seg[--b], R); if (check(nxt)) return find_subtree(b, check, R, true); R = nxt; } } return -1; } }; template <unsigned mod> struct RollingHash { vector<unsigned> hashed, power; inline unsigned mul(unsigned a, unsigned b) const { unsigned long long x = (unsigned long long)a * b; unsigned xh = (unsigned)(x >> 32), xl = (unsigned)x, d, m; asm("divl %4; \n\t" : "=a"(d), "=d"(m) : "d"(xh), "a"(xl), "r"(mod)); return m; } RollingHash(const string &s, unsigned base = 10007) { int sz = (int)s.size(); hashed.assign(sz + 1, 0); power.assign(sz + 1, 0); power[0] = 1; for (int i = 0; i < sz; i++) { power[i + 1] = mul(power[i], base); hashed[i + 1] = mul(hashed[i], base) + s[i]; if (hashed[i + 1] >= mod) hashed[i + 1] -= mod; } } unsigned get(int l, int r) const { unsigned ret = hashed[r] + mod - mul(hashed[l], power[r - l]); if (ret >= mod) ret -= mod; return ret; } unsigned connect(unsigned h1, int h2, int h2len) const { unsigned ret = mul(h1, power[h2len]) + h2; if (ret >= mod) ret -= mod; return ret; } int LCP(const RollingHash<mod> &b, int l1, int r1, int l2, int r2) { int len = min(r1 - l1, r2 - l2); int low = -1, high = len + 1; while (high - low > 1) { int mid = (low + high) / 2; if (get(l1, l1 + mid) == b.get(l2, l2 + mid)) low = mid; else high = mid; } return (low); } }; using RH = RollingHash<1000000007>; template <typename T> struct edge { int src, to; T cost; edge(int to, T cost) : src(-1), to(to), cost(cost) {} edge(int src, int to, T cost) : src(src), to(to), cost(cost) {} edge &operator=(const int &x) { to = x; return *this; } operator int() const { return to; } }; template <typename T> using Edges = vector<edge<T>>; template <typename T> using WeightedGraph = vector<Edges<T>>; using UnWeightedGraph = vector<vector<int>>; template <typename T> using Matrix = vector<vector<T>>; template <typename G> struct DoublingLowestCommonAncestor { const int LOG; vector<int> dep; const G &g; vector<vector<int>> table; DoublingLowestCommonAncestor(const G &g) : g(g), dep(g.size()), LOG(32 - __builtin_clz(g.size())) { table.assign(LOG, vector<int>(g.size(), -1)); } void dfs(int idx, int par, int d) { table[0][idx] = par; dep[idx] = d; for (auto &to : g[idx]) { if (to != par) dfs(to, idx, d + 1); } } void build() { dfs(0, -1, 0); for (int k = 0; k + 1 < LOG; k++) { for (int i = 0; i < table[k].size(); i++) { if (table[k][i] == -1) table[k + 1][i] = -1; else table[k + 1][i] = table[k][table[k][i]]; } } } int query(int u, int v) { if (dep[u] > dep[v]) swap(u, v); for (int i = LOG - 1; i >= 0; i--) { if (((dep[v] - dep[u]) >> i) & 1) v = table[i][v]; } if (u == v) return u; for (int i = LOG - 1; i >= 0; i--) { if (table[i][u] != table[i][v]) { u = table[i][u]; v = table[i][v]; } } return table[0][u]; } }; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << max(0, a + b - n) << endl; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change" ]
939,976
939,977
u933068010
cpp
p03139
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << min(a + b - n, 0) << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << max(a + b - n, 0) << endl; }
[ "misc.opposites", "identifier.change", "call.function.change", "io.output.change" ]
939,978
939,979
u732578115
cpp
p03139
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << a + b - n << endl; }
#include <bits/stdc++.h> using namespace std; int main() { int n, a, b; cin >> n >> a >> b; cout << min(a, b) << " " << max(a + b - n, 0) << endl; }
[ "call.add", "call.arguments.add" ]
939,980
939,979
u732578115
cpp
p03139
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; cout << min(x, y) << " "; if (x + y <= 10) { cout << 0 << endl; } else { cout << x + y - 10 << endl; } }
#include <algorithm> #include <cmath> #include <iostream> using namespace std; int main() { int n, x, y; cin >> n >> x >> y; cout << min(x, y) << " "; if (x + y <= n) { cout << 0 << endl; } else { cout << x + y - n << endl; } }
[ "identifier.replace.add", "literal.replace.remove", "control_flow.branch.if.condition.change", "io.output.change" ]
939,981
939,982
u401900157
cpp
p03139
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll mod = 1000000007; ll r(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0) return r(x, y / 2) * r(x, y / 2) % mod; else return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod; } int main() { int n, a, b; cin >> n >> a >> b; int m = min(a, b); int s = a + b; cout << m << ' '; ; if (s > m) { cout << s - n << endl; } else { cout << 0 << endl; } }
#include <bits/stdc++.h> using namespace std; typedef long long int ll; ll mod = 1000000007; ll r(ll x, ll y) { if (y == 0) return 1; else if (y % 2 == 0) return r(x, y / 2) * r(x, y / 2) % mod; else return x * r(x, (y - 1) / 2) % mod * r(x, (y - 1) / 2) % mod; } int main() { int n, a, b; cin >> n >> a >> b; int m = min(a, b); int s = a + b; cout << m << ' '; ; if (s > n) { cout << s - n << endl; } else { cout << 0 << endl; } }
[ "identifier.change", "control_flow.branch.if.condition.change" ]
939,985
939,986
u985686845
cpp
p03139
#include <iostream> using namespace std; int main(void) { int n, a, b; cin >> n >> a >> b; if (n >= a + b) { cout << min(a, b) << " " << 0 << endl; } else { cout << min(a, b) << a + b - n << endl; } }
#include <iostream> using namespace std; int main(void) { int n, a, b; cin >> n >> a >> b; if (n >= a + b) { cout << min(a, b) << " " << 0 << endl; } else { cout << min(a, b) << " " << a + b - n << endl; } }
[ "io.output.change" ]
939,987
939,988
u163874353
cpp