Submission #41790029
Source Code Expand
#include <stdio.h>
int popcount(long long N)
{
int ans = 0;
while (N > 0) {
ans++;
N ^= (N & -N);
}
return ans;
}
long long solve(long long N)
{
if (N < 7) return -1;
int k = popcount(N);
if (k >= 3) {
while (k > 3) {
k--;
N ^= (N & -N);
}
return N;
} else if (k == 1) return N / 8 * 7;
else {
if ((N & -N) <= 2) return N / 8 * 7;
else return (N ^ (N & -N)) + (N & -N) / 4 * 3;
}
}
int main()
{
int i, j, k, l, T;
long long N;
scanf("%d", &T);
while (T--) {
scanf("%lld", &N);
printf("%lld\n", solve(N));
}
fflush(stdout);
return 0;
}
Submission Info
| Submission Time | |
|---|---|
| Task | B - Exactly Three Bits |
| User | ygussany |
| Language | C (GCC 9.2.1) |
| Score | 400 |
| Code Size | 621 Byte |
| Status | AC |
| Exec Time | 45 ms |
| Memory | 2212 KiB |
Compile Error
./Main.c: In function ‘main’:
./Main.c:35:2: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
35 | scanf("%d", &T);
| ^~~~~~~~~~~~~~~
./Main.c:37:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
37 | scanf("%lld", &N);
| ^~~~~~~~~~~~~~~~~
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-sample-001.txt |
| All | 00-sample-001.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-sample-001.txt | AC | 4 ms | 1676 KiB |
| 01-001.txt | AC | 45 ms | 2100 KiB |
| 01-002.txt | AC | 45 ms | 2120 KiB |
| 01-003.txt | AC | 45 ms | 2148 KiB |
| 01-004.txt | AC | 30 ms | 1652 KiB |
| 01-005.txt | AC | 34 ms | 1708 KiB |
| 01-006.txt | AC | 44 ms | 2212 KiB |
| 01-007.txt | AC | 44 ms | 2148 KiB |
| 01-008.txt | AC | 34 ms | 1736 KiB |
| 01-009.txt | AC | 37 ms | 1784 KiB |
| 01-010.txt | AC | 39 ms | 1796 KiB |
| 01-011.txt | AC | 44 ms | 2124 KiB |
| 01-012.txt | AC | 45 ms | 2148 KiB |