Google code jam’19 Round 1C: Power Rangers

Logic :
call 1 to 595 in increament of 5;
count a,b,c,d,e and store coresponding positions
one will have 23 count;
add that to answer;
out of those 23 number 
call number+1;
count A,B,C,D,E
one will have count of 5;
add that to answer;
call these number+1; // for third position
count will be like 2,2,1,0,0 take one with 1 count;
finally call that number+1;
if that gives X,this is your answer to last position 
and one not taken will become 4th position
total call=119+23+5+1=148<150 

#include<bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define MOD 1000000007
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define FOR(a,n) for(int i=a;i<n;++i)
#define arrin(n) for(int i=0; i < n; ++i) cin>>arr[i];
#define arrout(n) for(int i=0; i < n; ++i) cout<<arr[i]<<" ";cout<<nl;
#define nl "\n"
#define mp make_pair
typedef unsigned long long ull;
typedef long long int ll;
typedef long double ld;
using namespace std;
void verdict(string a)
{
  cout<<a<<endl;
  char s;
  cin>>s;
}
char ask(int n)
{
   cout<<n<<endl;
   char s;
   cin>>s;
   return s;
}
int main()
{
  fastio();
  ll T,F;
  cin>>T>>F;
  for(ll z=1;z<=T;z++)
  {
     map<ll,ll> M;
     M['A']=0;
     M['B']=1;
     M['C']=2;
     M['D']=3;
     M['E']=4;
     map<char,ll> m1,m2,m3;
     ll store[5];
     memset(store,0,sizeof(store));
     vector<ll> v1[5],v2[5],v3[5];
     for(ll i=1;i<595;i+=5)
     {
       char x=ask(i);
       m1[x]++;
       v1[M[x]].pb(i);
     }
     string ans="";
     char c1;
     for(auto i  : m1)
     {
       if(i.second==23)
       {
          ans+=i.first;
          c1=i.first;
          store[M[c1]]=1;
          break;
       }
     }
     //cout<<ans<<endl;
     for(auto i : v1[M[c1]])
     {
        char x=ask(i+1);
        m2[x]++;
        v2[M[x]].pb(i);
     }
     for(auto i  : m2)
     {
       if(i.second==5)
       {
          ans+=i.first;
          c1=i.first;
          store[M[c1]]=1;
          break;
       }
     }
     //cout<<ans<<endl;
     for(auto i : v2[M[c1]])
     {
        char x=ask(i+2);
        m3[x]++;
        v3[M[x]].pb(i);
     }
     for(auto i  : m3)
     {
       if(i.second==1)
       {
          ans+=i.first;
          c1=i.first;
          store[M[c1]]=1;
          break;
       }
     }
     //cout<<ans<<endl;
     char fini=ask(v3[M[c1]][0]+3);
     store[M[fini]]=1;
     for(ll i=0;i<5;i++)
     {
        if(store[i]!=1)
        {  
           if(i==0) ans+='A',ans+=fini;
           else if(i==1) ans+='B',ans+=fini;
           else if(i==2) ans+='C',ans+=fini;
           else if(i==3) ans+='D',ans+=fini;
           else if(i==4) ans+='E',ans+=fini;
        }
     }
     verdict(ans);
  }
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  return 0;
}

Leave a comment