Submission #23006456


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define asc(v) sort(v.begin(),v.end())
#define dsc(v) sort(v.begin(),v.end(),greater<int>())
#define mp make_pair
#define ff first
#define ss second
#define setBits(x) _builtin_popcount(x)
#define parity(x) _builtin_parity(x)
#define leadZero(x) __builtin_clz(x)
#define trailZero(x) __builtin_ctz(x)
const double PI = acos(-1);
#define M1 1000000007
#define M3 1000000009
#define M2 998244353
#define endl "\n"
typedef complex<double> point;
# define xc real()
# define yc imag()
#define PI 3.1415926535897932384626433832
#define iter(s) for(auto it:s)
#define pqs priority_queue<int, vector<int>, greater<int>>
#define pq priority_queue<int>

#define forl(i,n) for(int i=0;i<n;i++)
#define fore(i,n) for(int i=1;i<=n;i++)
#define forn(i,n) for(int i=n-1;i>=0;i--)
#define forls(i,l,r) for(int i=l;i<r;i++)
#define forns(i,l,r) for(int i=r-1;i>=l;i--)
#define all(v) v.begin(),v.end()
#define inc(ar,n) sort(ar,ar+n)
#define rall(v) v.rbegin(),v.rend()
#define RSORT(ar,n) sort(ar,ar+n,greater<int>())
void chmax(double& a, double b){ if(a < b) a = b; }

#define pat int n;cin>>n;
#define wq int q;cin>>q;fore(_,q)
#define tak(s) string s;cin>>s;int n=s.LEN;
#define nf if(f) cout<<"YES\n";else cout<<"NO\n";
#define pat1 int n;cin>>n;int a[n];forl(i,n) cin>>a[i];
#define pat2 int n,k;cin>>n>>k;int a[n];forl(i,n) cin>>a[i];
//#pragma GCC optimize "trapv"
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}
unsigned int fac(unsigned int n,int x)
{
    int res = 1, i;
    for (i = 2; i <= n; i++)
    {
        res *= i;
        res%=x;
    }

    return res%x;
}
int powM(int x,int y,int m)
{
    int ans=1,r=1;
    x%=m;
    while(r>0&&r<=y)
    {
        if(r&y)
        {
            ans*=x;
            ans%=m;
        }
        r<<=1;
        x*=x;
        x%=m;
    }
    return ans;
}
bool isSubseq(vector<int>v,vector<int>w){
    int x=v.size(),y=w.size();
    int j,i;
    for (j=0,i=0 ; i<x && j<y ; i++) {
        if (w[j] == v[i]){
            j++;
        }
    }
    if(j<y){
        return 0;
    }
    else{
        return 1;
    }
}
bool opp(int x, int y)
{
    return ((x ^ y) < 0);
}
bool isPowerOfTwo(int x)
    {
    return (x && !(x & (x - 1)));
    }
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0)
            return false;

    return true;
}
int gcd(int v, int b)
{
    if (b == 0)
        return v;
    return gcd(b, v % b);

}
int maxSubArraySum(int v[], int size)
{
   int max_so_far = v[0];
   int curr_max = v[0];

   for (int i = 1; i < size; i++)
   {
        curr_max = max(v[i], curr_max+v[i]);
        max_so_far = max(max_so_far, curr_max);
   }
   return max_so_far;
}
int sum(int n){
    int v=0;
    while(n!=0){
        v+=(n%10);
        n/=10;
    }
    return v;
}
int findSubarraySum(int arr[], int n, int sum)
{
    // STL map to store number of subarrays
    // starting from index zero having
    // particular value of sum.
    unordered_map<int, int> prevSum;

    int res = 0;

    // Sum of elements so far.
    int currsum = 0;

    for (int i = 0; i < n; i++) {

        // Add current element to sum so far.
        currsum += arr[i];
        // If currsum is equal to desired sum,
        // then a new subarray is found. So
        // increase count of subarrays.
        if (currsum == sum)
            res++;

        // currsum exceeds given sum by currsum
        //  - sum. Find number of subarrays having
        // this sum and exclude those subarrays
        // from currsum by increasing count by
        // same amount.
        if (prevSum.find(currsum - sum) !=
                                  prevSum.end())
            res += (prevSum[currsum - sum]);


        // Add currsum value to count of
        // different values of sum.
        prevSum[currsum]++;
    }
    return res;
}
int ncr(int n, int r)
{

    // p holds the value of n*(n-1)*(n-2)...,
    // k holds the value of r*(r-1)...
    long long p = 1, k = 1;

    // C(n, r) == C(n, n-r),
    // choosing the smaller value
    if (n - r < r)
        r = n - r;

    if (r != 0) {
        while (r) {
            p *= n;
            k *= r;

            // gcd of p, k
            long long m = __gcd(p, k);

            // dividing by gcd, to simplify
            // product division by their gcd
            // saves from the overflow
            p /= m;
            k /= m;

            n--;
            r--;
        }

        // k should be simplified to 1
        // as C(n, r) is a natural number
        // (denominator should be 1 ) .
    }

    else
        p = 1;

    // if our approach is correct p = ans and k =1
    return p;
}
/*vector<int>a[200001];
int vis[200001]={0};
int dis[200001]={0};*/
//int col[100001]={0};
//int cc=0;
/*bool bprt(int x, int c){
    vis[x]=1;
    col[x]=c;
    for(int y:a[x]){
        if(!vis[y]){
            if(!(bprt(y,c^1))){
                return false;
            }
        }
        else{
            if(col[x]==col[y]){
                return false;
            }
        }
    }
    return true;
}
void bfs(int x){
    queue<int>q;
    q.push(x);
    vis[x]=1;dis[x]=0;
    while(!q.empty()){
        int z=q.front();
        q.pop();
        for(int y:a[z]){
            if(!vis[y]){
                q.push(y);
                dis[y]=dis[z]+1;vis[y]=1;
            }
        }
    }
}
bool checkPal(string s){
    string ts = s;
    reverse(s.begin(), s.end());
    return (ts == s);
}*/
void ans(){
    vector<int>r,g,b;
    int n;cin>>n;
    forl(i,2*n){
        int x;char c;cin>>x>>c;
        if(c=='R'){
            r.pb(x);
        }
        else if(c=='G'){
            g.pb(x);
        }
        else{
            b.pb(x);
        }
    }
    int rr=r.size();int bb=b.size();int gg=g.size();
    asc(r);asc(g);asc(b);
    if(rr%2==0 && bb%2==0 && gg%2==0){
        cout<<0;
    }
    else{
        map<int,int>mr,mg,mb;
        vector<pair<int,pair<int,int>>>rb,rg,gb;
        forl(i,rr){
            mr[r[i]]++;
        }
        forl(i,bb){
            mb[b[i]]++;
        }
        forl(i,gg){
            mg[g[i]]++;
        }
        int i=0;int j=0;
        int x=INT_MAX;
        while(i<bb && j<gg){
            int y=abs(b[i]-g[j]);
            if(y<x){
                x=y;
                gb.pb({y,{g[j],b[i]}});
            }
            if(b[i]<g[j]){
                i++;
            }
            else{
                j++;
            }
        }
        i=0;j=0;
        x=INT_MAX;
        while(i<bb && j<rr){
            int y=abs(b[i]-r[j]);
            if(y<x){
                x=y;
                rb.pb({y,{r[j],b[i]}});
            }
            if(b[i]<r[j]){
                i++;
            }
            else{
                j++;
            }
        }
        i=0;j=0;
        x=INT_MAX;
        while(i<gg && j<rr){
            int y=abs(g[i]-r[j]);
            if(y<x){
                x=y;
                rg.pb({y,{r[j],g[i]}});
            }
            if(g[i]<r[j]){
                i++;
            }
            else{
                j++;
            }
        }
        asc(rb);asc(rg);asc(gb);
        if(rr%2==0){
            int z=gb[0].ff;
            if(rb.size()>0 && rg.size()>0){
                int zz=rb[0].ff;int zzz=rg[0].ff;
                if(z<=zz+zzz){
                    cout<<z;
                }
                else{
                    if(rb[0].ss.ff!=rg[0].ss.ff){
                        cout<<zz+zzz;
                    }
                    else if(mr[rb[0].ss.ff]>1){
                        cout<<zz+zzz;
                    }
                    else{
                        int dd=1e7;
                        rb.pb({dd,{0,0}});
                        rg.pb({dd,{0,0}});
                        int t=rg[1].ff;int u=rb[1].ff;
                        z=min({z,zz+t,zzz+u});
                        cout<<z;
                    }
                }
            }
            else{
                cout<<z;
            }
        }
        else if(gg%2==0){
            int z=rb[0].ff;
            if(gb.size()>0 && rg.size()>0){
                int zz=gb[0].ff;int zzz=rg[0].ff;
                if(z<=zz+zzz){
                    cout<<z;
                }
                else{
                    if(gb[0].ss.ff!=rg[0].ss.ss){
                        cout<<zz+zzz;
                    }
                    else if(mg[gb[0].ss.ff]>1){
                        cout<<zz+zzz;
                    }
                    else{
                        int dd=1e7;
                        gb.pb({dd,{0,0}});
                        rg.pb({dd,{0,0}});
                        int t=rg[1].ff;int u=gb[1].ff;
                        z=min({z,zz+t,zzz+u});
                        cout<<z;
                    }
                }
            }
            else{
                cout<<z;
            }
        }
        else{
            int z=rg[0].ff;
            if(gb.size()>0 && rb.size()>0){
                int zz=gb[0].ff;int zzz=rb[0].ff;
                if(z<=zz+zzz){
                    cout<<z;
                }
                else{
                    if(gb[0].ss.ss!=rb[0].ss.ss){
                        cout<<zz+zzz;
                    }
                    else if(mr[gb[0].ss.ss]>1){
                        cout<<zz+zzz;
                    }
                    else{
                        int dd=1e7;
                        gb.pb({dd,{0,0}});
                        rb.pb({dd,{0,0}});
                        int t=rb[1].ff;int u=gb[1].ff;
                        z=min({z,zz+t,zzz+u});
                        cout<<z;
                    }
                }
            }
            else{
                cout<<z;
            }
        }
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ans();
    return 0;
}

Submission Info

Submission Time
Task B - RGB Matching
User thesinhajee
Language C++ (GCC 9.2.1)
Score 0
Code Size 10533 Byte
Status RE
Exec Time 163 ms
Memory 17200 KiB

Compile Error

./Main.cpp: In function ‘long long unsigned int fac(long long unsigned int, long long int)’:
./Main.cpp:53:19: warning: comparison of integer expressions of different signedness: ‘long long int’ and ‘long long unsigned int’ [-Wsign-compare]
   53 |     for (i = 2; i <= n; i++)
      |                 ~~^~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
AC × 67
RE × 15
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, random2_01.txt, random2_02.txt, random2_03.txt, random2_04.txt, random2_05.txt, random2_06.txt, random2_07.txt, random2_08.txt, random2_09.txt, random2_10.txt, random2_11.txt, random2_12.txt, random2_13.txt, random2_14.txt, random2_15.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt, random_36.txt, random_37.txt, random_38.txt, random_39.txt, random_40.txt, random_41.txt, random_42.txt, random_43.txt, random_44.txt, random_45.txt, random_46.txt, random_47.txt, random_48.txt, random_49.txt, random_50.txt, random_51.txt, random_52.txt, random_53.txt, random_54.txt, random_55.txt, random_56.txt, random_57.txt, random_58.txt, random_59.txt, random_60.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
hand_01.txt RE 163 ms 10284 KiB
hand_02.txt RE 144 ms 8936 KiB
hand_03.txt RE 141 ms 8960 KiB
hand_04.txt RE 149 ms 10292 KiB
random2_01.txt AC 93 ms 17064 KiB
random2_02.txt AC 94 ms 17112 KiB
random2_03.txt AC 93 ms 17088 KiB
random2_04.txt AC 94 ms 17012 KiB
random2_05.txt AC 94 ms 17092 KiB
random2_06.txt AC 15 ms 4524 KiB
random2_07.txt AC 25 ms 6728 KiB
random2_08.txt AC 42 ms 8964 KiB
random2_09.txt AC 85 ms 15936 KiB
random2_10.txt AC 42 ms 8916 KiB
random2_11.txt AC 3 ms 3676 KiB
random2_12.txt AC 4 ms 3736 KiB
random2_13.txt AC 4 ms 3572 KiB
random2_14.txt AC 2 ms 3660 KiB
random2_15.txt AC 3 ms 3612 KiB
random_01.txt AC 51 ms 5240 KiB
random_02.txt AC 97 ms 17064 KiB
random_03.txt AC 50 ms 5224 KiB
random_04.txt AC 97 ms 17068 KiB
random_05.txt AC 51 ms 5248 KiB
random_06.txt AC 97 ms 17200 KiB
random_07.txt AC 100 ms 17092 KiB
random_08.txt AC 97 ms 17176 KiB
random_09.txt AC 95 ms 16936 KiB
random_10.txt AC 98 ms 17068 KiB
random_11.txt AC 95 ms 17140 KiB
random_12.txt AC 97 ms 17120 KiB
random_13.txt AC 98 ms 17192 KiB
random_14.txt AC 50 ms 5428 KiB
random_15.txt AC 94 ms 16980 KiB
random_16.txt AC 96 ms 16936 KiB
random_17.txt AC 94 ms 16936 KiB
random_18.txt AC 94 ms 17052 KiB
random_19.txt AC 94 ms 17108 KiB
random_20.txt AC 95 ms 17028 KiB
random_21.txt AC 28 ms 6640 KiB
random_22.txt AC 11 ms 4416 KiB
random_23.txt AC 28 ms 6496 KiB
random_24.txt AC 44 ms 8728 KiB
random_25.txt AC 30 ms 6548 KiB
random_26.txt AC 21 ms 4136 KiB
random_27.txt AC 28 ms 6508 KiB
random_28.txt AC 70 ms 13448 KiB
random_29.txt AC 84 ms 15788 KiB
random_30.txt AC 71 ms 13272 KiB
random_31.txt AC 58 ms 11032 KiB
random_32.txt AC 44 ms 9368 KiB
random_33.txt AC 17 ms 3972 KiB
random_34.txt AC 13 ms 4920 KiB
random_35.txt AC 30 ms 6984 KiB
random_36.txt AC 75 ms 13928 KiB
random_37.txt AC 63 ms 11412 KiB
random_38.txt AC 47 ms 9228 KiB
random_39.txt AC 61 ms 11508 KiB
random_40.txt AC 78 ms 14152 KiB
random_41.txt RE 114 ms 3340 KiB
random_42.txt RE 110 ms 3236 KiB
random_43.txt AC 5 ms 3704 KiB
random_44.txt RE 114 ms 3264 KiB
random_45.txt AC 8 ms 3624 KiB
random_46.txt AC 4 ms 3716 KiB
random_47.txt RE 115 ms 3328 KiB
random_48.txt AC 3 ms 3572 KiB
random_49.txt RE 112 ms 3368 KiB
random_50.txt AC 7 ms 3556 KiB
random_51.txt AC 4 ms 3528 KiB
random_52.txt AC 2 ms 3496 KiB
random_53.txt RE 116 ms 3212 KiB
random_54.txt RE 110 ms 3288 KiB
random_55.txt AC 9 ms 3656 KiB
random_56.txt RE 115 ms 3300 KiB
random_57.txt RE 111 ms 3332 KiB
random_58.txt RE 113 ms 3436 KiB
random_59.txt RE 112 ms 3216 KiB
random_60.txt AC 9 ms 3580 KiB
sample_01.txt AC 2 ms 3544 KiB
sample_02.txt AC 2 ms 3568 KiB
sample_03.txt AC 2 ms 3428 KiB