Submission #57054172


Source Code Expand

/*By Ashok_Zayn اشکنزی-------------------------------------------------------------------
----------------------------------------------------------------------------------------*/
#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 ll long long
#define dbl double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ff first
#define ss second
#define ins insert
#define vll vector <ll>
#define vvll vector <vll>
#define vbool vector <bool>
#define pll pair <ll,ll>
#define vpll vector <pll>
#define allin(v) v.begin(), v.end()
#define allinr(v) v.rbegin(), v.rend()
#define desc() greater <ll>()
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mll map<ll,ll>
#define umll unorder_map<ll,ll>
#define erase_duplicates(x)             x.erase(unique(allin(x)),x.end());
#define endl "\n"
#define rtn return;
#define ppc(n) __builtin_popcount(n)

vll dx = {1, 0, -1, 0};
vll dy = {0, 1, 0, -1};
vll dirx = { -1, 0, 0, 1, -1, -1, 1, 1 };
vll diry = { 0, 1, -1, 0, -1, 1, -1, 1 };
#define loop(i,a,b,k) for(ll i=a;i<b;i+=k)
#define rloop(i,a,b,k) for(ll i=a;i>=b;i-=k)
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
/*------------------Policy based data structures------------------------------------------*/
template<class T> using oset = tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;
//template<class key, class value> using omap = tree <key,value,less<key>,rb_tree_tag,tree_order_statistics_node_update>;
/*find_by_order(k) -> returns iterator to kth element from start 0
order_of_key(k) -> returns count of elements < k */
 
template<typename T> istream& operator >>(istream &in,vector<T> &v){ for(auto &x:v) in>>x; return in;}
template<typename T> ostream& operator <<(ostream &out,const vector<T> &v){ for(auto &x:v) out<<x<<' '; return out;}
template<typename T1,typename T2> istream& operator >>(istream &in,pair<T1,T2> &p){ in>>p.first>>p.second; return in;}
template<typename T1,typename T2> ostream& operator <<(ostream &out,const pair<T1,T2> &p) {out<<p.first<<' '<<p.second;return out;}
 
/*-----------------Useful Values----------------------------------------------------------*/
const int ebl = 1e9+7;
const int newebl = 998244353;
const int local_n = 1e5+7;
const int global_n = 1e7+5;
const int max_prime = 1e6+3;
const ll inf = 1e18;
const ll eps = 1e-9;
#define pi 3.141592653589793238462
double PI = acos(-1);
#define modinv2 500000004
 
/*----------------Useful Functions-------------------------------------------------------*/
ll gcd(ll a, ll b) { while (b) {a %= b; swap(a,b);} return a; }
ll lcm(ll a, ll b) { ll g=gcd(a,b); ll res=a*(b/g); return res; }
ll extnd_gcd(ll a,ll b,ll &x,ll &y){if (a==0){ x=0;y=1;return b;}ll x1,y1;ll g=extnd_gcd(b%a,a,x1,y1);x=y1-(b/a)*x1;y=x1;return g; }
ll binexp2(ll a, ll b){ll res=1; while(b>0){if(b&1) res=res*a; a=a*a; b>>=1;}return res;}
ll binExp(ll a, ll b, ll m) { a = a % m; ll res = 1; while (b) { if (b&1) { res=(res * a) % m; } a=(a * a) % m; b>>=1; } return res; }
ll phi_n(ll n){ll res=1;for(ll i=2;i*i<=n;i++){ll a=0;if(n%i==0){while(n%i==0){a++;n/=i;}}if(a>0){ll sm=binexp2(i,a-1)*(i-1);res*=sm;}}if(n>1){res*=(n-1);}return res;}
ll mod_inv(ll a, ll m) { a = a % m; return binExp(a,m-2,m); }
ll mod_add(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; }
ll mod_sub(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; }
ll mod_mul(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; }
ll mod_div(ll a, ll b, ll m) { a = a % m; ll binv = mod_inv(b,m); return (((a * binv) % m) + m) % m; }
ll mod(ll n){if(n>=0)return n%ebl;else{ll x=abs(n)/ebl;return (ebl*(x+1)+n)%ebl; }}
ll sqrtll(ll n){ll lo=0,hi=1e9+7; while(hi-lo>1){ll m=(hi+lo)/2;if(m*m<=n){lo=m;}else{hi=m-1;}}if(hi*hi<=n){return hi;}
return lo;}
dbl sqrtld(ll n) { dbl lo=0,hi=1e9+7; while (hi-lo>eps) { dbl m=(hi+lo)/2; if ((n-m*m)>eps) { lo=m; } else { hi=m-eps; }} return lo; }
ll doceil(ll a, ll b){return (a/b)+(a%b==0?0:1);}
 
/*---------------Custom HashMap----------------------------------------------------------*/
struct custom_hash{static uint64_t splitmix64(uint64_t x){x+=0x9e3779b97f4a7c15;x=(x^(x>>30))* 0xbf58476d1ce4e5b9;
x=(x^(x>>27))* 0x94d049bb133111eb;return x^(x>>31);}size_t operator()(uint64_t x)const{
static const uint64_t FIXED_RANDOM=chrono::steady_clock::now().time_since_epoch().count();return splitmix64(x+FIXED_RANDOM);}};
/*unordered_map<ll,ll,custom_hash>uchm;*/

#define op(n) cout<<n<<endl;
#define ip(n) cin>>n;
#define acy cout<<"Yes"<<endl;
#define acn cout<<"No"<<endl;
#define cfy cout<<"YES"<<endl;
#define cfn cout<<"NO"<<endl;
#define sy  cout<<"yes"<<endl;
#define sn  cout<<"no"<<endl;

void do_it()
{
    ll n; cin>>n;
    vll v(n); for(auto &it : v) cin>>it;
    
    ll pc=0;
    for(auto it : v) pc+=(it>0);
    ll sol=0;
    while(pc>1)
    {
        sort(allin(v));
        reverse(allin(v));
        if(v[0]>=1) v[0]-=1;
        if(v[1]>=1) v[1]-=1;
        sol+=1;
        if(v[0]<=0) pc-=1;
        if(v[1]<=0) pc-=1;
        if(pc<=1) break;
    }
    cout<<sol<<endl;
}

int32_t main(int argc, char const *argv[]){
    rapido
        // #ifndef ONLINE_JUDGE
        //     freopen("input.txt","r",stdin);
        //     freopen("output.txt","w",stdout);
        // #endif
    //precompute

    ll kin=1; //cin>>kin;
    for(ll i=1; i<=kin ;i++){
         //cout<<"Case #"<<i<<":"<<" ";  
         do_it();
    }
    cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl; 
    return 0;
}

Submission Info

Submission Time
Task B - Decrease 2 max elements
User onlycoding143
Language C++ 20 (gcc 12.2)
Score 200
Code Size 5827 Byte
Status AC
Exec Time 2 ms
Memory 3948 KiB

Compile Error

Main.cpp: In function ‘int32_t main(int, const char**)’:
Main.cpp:121:18: warning: unused parameter ‘argc’ [-Wunused-parameter]
  121 | int32_t main(int argc, char const *argv[]){
      |              ~~~~^~~~
Main.cpp:121:36: warning: unused parameter ‘argv’ [-Wunused-parameter]
  121 | int32_t main(int argc, char const *argv[]){
      |                        ~~~~~~~~~~~~^~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 200 / 200
Status
AC × 2
AC × 15
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_internal_00.txt, 01_internal_01.txt, 01_internal_02.txt, 01_internal_03.txt, 01_internal_04.txt, 01_internal_05.txt, 01_internal_06.txt, 01_internal_07.txt, 01_internal_08.txt, 01_internal_09.txt, 01_internal_10.txt, 01_internal_11.txt, 01_internal_12.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 1 ms 3724 KiB
00_sample_01.txt AC 1 ms 3784 KiB
01_internal_00.txt AC 1 ms 3864 KiB
01_internal_01.txt AC 2 ms 3692 KiB
01_internal_02.txt AC 1 ms 3876 KiB
01_internal_03.txt AC 2 ms 3880 KiB
01_internal_04.txt AC 2 ms 3852 KiB
01_internal_05.txt AC 2 ms 3828 KiB
01_internal_06.txt AC 2 ms 3880 KiB
01_internal_07.txt AC 2 ms 3740 KiB
01_internal_08.txt AC 2 ms 3828 KiB
01_internal_09.txt AC 2 ms 3880 KiB
01_internal_10.txt AC 1 ms 3840 KiB
01_internal_11.txt AC 1 ms 3948 KiB
01_internal_12.txt AC 1 ms 3652 KiB