QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#277481 | #5542. Doubled GCD | NYCU_template# | RE | 8ms | 3868kb | C++14 | 1.0kb | 2023-12-06 19:18:36 | 2023-12-06 19:18:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
int pow2(ll n){
int cnt = 0;
while(n%2 == 0){
cnt++;
n/=2;
}
return cnt;
}
bool solve()
{
int n;
if (!(cin >> n))
return false;
vector<ll> a(n);
for(auto &x : a) cin >> x;
ll cnt[35]{0}, g;
for(int i = 0; i < n; ++i){
int c = 0;
while(a[i] % 2 == 0){
a[i]/=2;
c++;
}
cnt[c]++;
if(i == 0) g = a[i];
else g = __gcd(g,a[i]);
}
int p1 = 0, p2 = 0; ll mx = 0;
while(p1 < 35){
if(cnt[p1] == 0) p1++;
else {
mx = p1; cnt[p1]--;
while(p2 < 35 && cnt[p2] == 0) p2++;
if(p2 == 35) {
mx = p1;
break;
}
cnt[p2]--;
cnt[p1+1]++;
}
}
// cerr << "MAX : " << mx << '\n';
ll ans = g;
while(mx > 0){
mx--;
ans *= 2;
}
cout << ans << '\n';
return true;
}
int main()
{
ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
while (solve())
;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
input:
3 2 4 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
3 3 5 7
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3556kb
input:
4 9 9 9 9
output:
36
result:
ok single line: '36'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3612kb
input:
5 10 100 1000 10000 100000
output:
160
result:
ok single line: '160'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
8 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
8000000000
result:
ok single line: '8000000000'
Test #6:
score: 0
Accepted
time: 8ms
memory: 3868kb
input:
100000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000...
output:
65536000000000
result:
ok single line: '65536000000000'
Test #7:
score: -100
Runtime Error
input:
20000 33554432 131072 512 128 16777216 524288 64 2 1 32 65536 256 268435456 67108864 262144 2097152 8192 1024 8 128 262144 8388608 32 65536 32 128 256 512 4194304 1024 65536 2 4 4 65536 1 2048 524288 134217728 16 262144 524288 16777216 33554432 1 32768 262144 268435456 2048 4 32 536870912 2 16777216...