QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#701898 | #5542. Doubled GCD | MeatInTheMiddle# | TL | 18ms | 7524kb | C++17 | 1.2kb | 2024-11-02 14:53:02 | 2024-11-02 14:53:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fastio (ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL))
typedef long long ll;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
const int MAXSIZE = 2000000;
const long long INF = 1e18 + 5;
const double EPSILON = 1e-14;
const ll DIV = 2000003;
const long double pi = 3.14159265358979323846264338327950288419716939937510L;
int n;
ll gcd(ll a, ll b)
{
if (b == 0)
return a;
return gcd(b, a % b);
}
pair<ll, ll> arr[200005];
int get(int a)
{
int ret = 0;
while (a % 2 == 0)
ret++, a /= 2;
return ret;
}
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<>> pq;
int main()
{
fastio;
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> arr[i].second;
arr[i].first = get(arr[i].second);
pq.push(arr[i]);
}
while (pq.size() > 1)
{
pair<ll, ll> a = pq.top();
pq.pop();
pair<ll, ll> b = pq.top();
pq.pop();
ll d = 2 * gcd(a.second, b.second);
pq.push({get(d), d});
}
cout << pq.top().second;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
3 2 4 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 3 5 7
output:
2
result:
ok single line: '2'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3708kb
input:
4 9 9 9 9
output:
36
result:
ok single line: '36'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3668kb
input:
5 10 100 1000 10000 100000
output:
160
result:
ok single line: '160'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5680kb
input:
8 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
output:
8000000000
result:
ok single line: '8000000000'
Test #6:
score: 0
Accepted
time: 18ms
memory: 7524kb
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
Time Limit Exceeded
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...