QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#678569#5465. Maximum GCDA_R_AdnanWA 0ms3736kbC++147.7kb2024-10-26 15:23:362024-10-26 15:23:38

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 15:23:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3736kb
  • [2024-10-26 15:23:36]
  • 提交

answer

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define pbds tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>
// A.order_of_key(x)   *A.find_by_order(x)
// less->sorted in ascending order and unique, greater->sorted in descending order and unique
// less_equal-> it will work as multiset and in ascending order, greater_equal->same as multiset in descending order
typedef unsigned long long ull;
#define ld long double
typedef long long ll;
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define F first
#define S second
#define CY cout << "YES\n";
#define CN cout << "NO\n";
#define forr(v, n)             \
   vll v(n);                   \
   for (int i = 0; i < n; i++) \
   {                           \
      cin >> v[i];             \
   }
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define sz(s) ((int)((s).size()))
#define torad(x) (x) * ((2 * acos(0)) / 180.0)
#define ite vector<int>::iterator
#define print(a)        \
   for (auto v : a)     \
      cout << v << " "; \
   cout << "\n";
#define ASSALAMU_ALAIKOM         \
   ios_base::sync_with_stdio(0); \
   cin.tie(0);                   \
   cout.tie(0);
#define pb push_back
const ll inf = 1e18;
const ll minf = -1e18;
const ll mod = 1e9 + 7;
#define eps 1e-12
const double PI = acos(-1);
#define fit for (auto u : (x))
#define Max(x) *max_element(all(x))
#define Min(x) *min_element(all(x))
#define PI 2 * acos(0)
#define pob pop_back
#define set_bits(n) __builtin_popcountll(n)
// set_intersection(all(v1), all(v2), back_inserter(v));
// set_union(all(v1), all(v2), back_inserter(v));
// set_difference(all(v1), all(v2), back_inserter(v));
#define endl '\n'
// a%m is equivalent to ((a%m)+m)%m -->(it will work for both negative and positive value)
ll modulo(ll a, ll b)
{
   return ((a % b) + b) % b;
}
ll log_a_to_base_b(ll a, ll b)
{
   return log2(a) / log2(b);
}
void printBinary(ll num)
{
   for (ll i = 63; i >= 0; i--)
      cout << ((num >> i) & 1);
   cout << endl;
}
bool power_of_2(ll x)
{
   return x && !(x & (x - 1));
}
#define endl '\n'
ll GCD(ll x, ll y)
{
   if (y == 0)
      return x;
   else
      return GCD(y, x % y);
}
ll LCM(ll x, ll y)
{
   return (x * y / (GCD(x, y)));
}
ll power(ll a, ll n)
{
   ll ans = 1;
   while (n)
   {
      if (n & 1)
      {
         ans = ans * a;
         n--;
      }
      a *= a;
      n /= 2;
   }
   return ans;
}
ll modpower(ll a, ll n, ll mod)
{
   ll ans = 1;
   while (n)
   {
      if (n & 1)
      {
         ans = ((ans % mod) * (a % mod)) % mod;
         n--;
      }
      a = ((a % mod) * (a % mod)) % mod;
      n /= 2;
   }
   return ans;
}
ll inverse(ll a, ll p)
{
   return modpower(a, p - 2, p);
}
vector<bool> Sieve(ll n)
{
   vector<bool> prime(n + 1, true);
   for (ll p = 2; p * p <= n; p++)
   {
      if (prime[p] == true)
      {
         for (ll i = p * p; i <= n; i += p)
            prime[i] = false;
      }
   }
   return prime;
}
vll p_list;
vector<ll> sieve(ll n)
{
   vector<bool> prime(n + 1, true);
   for (ll p = 2; p * p <= n; p++)
   {
      if (prime[p] == true)
      {
         for (ll i = p * p; i <= n; i += p)
            prime[i] = false;
      }
   }
   for (ll i = 2; i <= n; i++)
   {
      if (prime[i])
         p_list.pb(i);
   }
   return p_list;
}
vector<vll> adj;
vll vis, color;
void dfs(ll node)
{
   vis[node] = 1;
   cout << node << " ";
   for (auto child : adj[node])
   {
      if (!vis[child])
         dfs(child);
   }
}
bool Is_Bipartite(ll node, ll clr)
{
   vis[node] = 1;
   color[node] = clr;
   for (auto child : adj[node])
   {
      if (!vis[child] && Is_Bipartite(child, clr ^ 1) == false)
         return false;
      else if (color[node] == color[child])
         return false;
   }
   return true;
}
bool Cycle(ll node, ll par)
{
   vis[node] = 1;
   for (auto child : adj[node])
   {
      if (!vis[child] && Cycle(child, node))
         return true;
      else if (child != par)
         return true;
   }
   return false;
}
vll Sub_sz;
ll Sub_Tree_Sz(ll node)
{
   ll curr_sz = 1;
   vis[node] = 1;
   for (auto child : adj[node])
   {
      if (!vis[child])
         curr_sz += Sub_Tree_Sz(child);
   }
   Sub_sz[node] = curr_sz;
   return curr_sz;
}
void bfs(ll s)
{
   queue<ll> q;
   vis[s] = 1;
   q.push(s);
   while (!q.empty())
   {
      ll x = q.front();
      cout << x << " ";
      q.pop();
      for (auto child : adj[x])
      {
         if (!vis[child])
         {
            vis[child] = 1;
            q.push(child);
         }
      }
   }
}

#ifndef ONLINE_JUDGE
#define dbg(x)        \
   cerr << #x << " "; \
   _print(x);         \
   cerr << endl;
#else
#define dbg(x)
#endif

void _print(ll t) { cerr << t; }
void _print(int t) { cerr << t; }
void _print(string t) { cerr << t; }
void _print(char t) { cerr << t; }
void _print(ld t) { cerr << t; }
void _print(double t) { cerr << t; }
void _print(ull t) { cerr << t; }

template <class T, class V>
void _print(pair<T, V> p);
template <class T>
void _print(vector<T> v);
template <class T>
void _print(set<T> v);
template <class T, class V>
void _print(map<T, V> v);
template <class T>
void _print(multiset<T> v);
template <class T, class V>
void _print(pair<T, V> p)
{
   cerr << "{";
   _print(p.F);
   cerr << ",";
   _print(p.S);
   cerr << "}";
}
template <class T>
void _print(vector<T> v)
{
   cerr << "[ ";
   for (T i : v)
   {
      _print(i);
      cerr << " ";
   }
   cerr << "]";
}
template <class T>
void _print(set<T> v)
{
   cerr << "[ ";
   for (T i : v)
   {
      _print(i);
      cerr << " ";
   }
   cerr << "]";
}
template <class T>
void _print(multiset<T> v)
{
   cerr << "[ ";
   for (T i : v)
   {
      _print(i);
      cerr << " ";
   }
   cerr << "]";
}
template <class T, class V>
void _print(map<T, V> v)
{
   cerr << "[ ";
   for (auto i : v)
   {
      _print(i);
      cerr << " ";
   }
   cerr << "]";
}
int double_comp(double a, double b)
{
   if (fabs(a - b) <= eps)
      return 0;
   else
      return a < b ? -1 : 1;
}
int main()
{
// #ifndef ONLINE_JUDGE
//    freopen("E:\\VS_C++\\input.txt", "r", stdin);
//    freopen("E:\\VS_C++\\output.txt", "w+", stdout);
//    freopen("E:\\VS_C++\\Erron.txt", "w", stderr);
// #endif
   ASSALAMU_ALAIKOM
   ll t,i,j,ans,f=0,x;
   vll div;
   cin >> t;
   forr(v, t);
   sort(all(v));
   x = v[0];
   for (i = 1; i <= sqrt(x); i++)
   {
      if (x % i == 0)
         div.pb(x / i);
   }
   for (i = 0; i < sz(div); i++)
   {
      ans = div[i];
      for (j=1; j < t; j++)
      {
         if (v[j] % ans == 0)
            continue;
         if (v[j] >= ans * ans)
         {
            f = 1;
            break;
         }
         else
          break;
      }
      if (f || j >= t)
         break;
   }
   if (f || j >= t)
      cout << ans << endl;
   else
   {
      x = ceil(v[0] / 2.0);
      for (i = x; i > 1; i--)
      {
         for (; j < t; j++)
         {
            if (v[j] >= i * i)
            {
               f = 1;
               break;
            }
            if (v[j] % i == 0)
               continue;
            else
            {
               x = v[j] % (v[j] - i);
               if (x == i)
                  continue;
               else
                  break;
            }
         }
         if (f || j >= t)
            break;
      }
      cout << i << endl;
   }
   return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3736kb

input:

3
3 10 7

output:

2

result:

wrong answer 1st numbers differ - expected: '3', found: '2'