Submission #4167649
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define step(i, s, n, d) for(int i=s; i<n; i+=d)
#define FOR(i,s,n) step(i,s,n,1)
#define rep(i,n) FOR(i,0,n)
#define ll long long
typedef pair<int, int> P;
int main(){
ll N, K, res = 0;
cin >> N >> K;
ll a[N], sum[45];
string nisinsuu[N], s;
rep(i, 45) {
sum[i] = 0;
}
rep(i, N) {
cin >> a[i];
stringstream ss;
ss << bitset<45>(a[i]);
s = ss.str();
nisinsuu[i] = s;
}
rep(i, N) {
rep(j, 45) {
if (nisinsuu[i][j] == '1') {
sum[j] += 1;
}
}
// cout << nisinsuu[i] << endl;
}
//sumが求まった。
string ans = "";
for (int i = 44; i >= 0; i--) {
if (sum[i] >= N/2) {
ans.insert(0, "0");
}else {
ans.insert(0, "1");
}
}
// 値を計算
for (int i = 44; i >= 0; i--) {
if (ans[i] == '1') {
res += pow(2, (45-i-1));
}
if (res > K) {
if (res - pow(2, (45-i-1)) == 0) {
res = pow(2, (45-i-2));
}else {
res -= pow(2, (45-i-1));
}
break;
}
}
// cout << res << endl;
ll result = 0;
rep(i, N) {
result += res ^ a[i];
}
cout << result << endl;
}
Submission Info
| Submission Time |
|
| Task |
D - XXOR |
| User |
KeitaKishida0811 |
| Language |
C++14 (GCC 5.4.1) |
| Score |
0 |
| Code Size |
1236 Byte |
| Status |
WA |
| Exec Time |
172 ms |
| Memory |
9600 KiB |
Judge Result
| Set Name |
All |
Sample |
| Score / Max Score |
0 / 400 |
0 / 0 |
| Status |
|
|
| Set Name |
Test Cases |
| All |
0_normal_1, 0_normal_2, 0_normal_3, 0_normal_4, 0_normal_5, 0_normal_6, 0_normal_7, 0_normal_8, 0_normal_9, 1_max_1, 1_max_2, 1_max_3, 1_max_4, 1_max_5, 1_max_6, 1_max_7, 1_max_8, 2_beki_1, 2_beki_2, 3_hand_1, 3_hand_2, 3_hand_3, sample_01, sample_02, sample_03 |
| Sample |
sample_01, sample_02, sample_03 |
| Case Name |
Status |
Exec Time |
Memory |
| 0_normal_1 |
WA |
103 ms |
5888 KiB |
| 0_normal_2 |
WA |
15 ms |
1024 KiB |
| 0_normal_3 |
WA |
125 ms |
7168 KiB |
| 0_normal_4 |
WA |
71 ms |
4096 KiB |
| 0_normal_5 |
WA |
93 ms |
5376 KiB |
| 0_normal_6 |
WA |
132 ms |
7552 KiB |
| 0_normal_7 |
WA |
136 ms |
7808 KiB |
| 0_normal_8 |
AC |
133 ms |
7552 KiB |
| 0_normal_9 |
AC |
85 ms |
4992 KiB |
| 1_max_1 |
WA |
172 ms |
9600 KiB |
| 1_max_2 |
AC |
169 ms |
9600 KiB |
| 1_max_3 |
WA |
170 ms |
9600 KiB |
| 1_max_4 |
WA |
169 ms |
9600 KiB |
| 1_max_5 |
WA |
169 ms |
9600 KiB |
| 1_max_6 |
WA |
169 ms |
9600 KiB |
| 1_max_7 |
AC |
172 ms |
9600 KiB |
| 1_max_8 |
AC |
169 ms |
9600 KiB |
| 2_beki_1 |
AC |
138 ms |
7936 KiB |
| 2_beki_2 |
AC |
129 ms |
7424 KiB |
| 3_hand_1 |
AC |
142 ms |
9600 KiB |
| 3_hand_2 |
WA |
123 ms |
9600 KiB |
| 3_hand_3 |
AC |
143 ms |
9600 KiB |
| sample_01 |
AC |
1 ms |
256 KiB |
| sample_02 |
AC |
1 ms |
256 KiB |
| sample_03 |
AC |
1 ms |
256 KiB |