Submission #927962

# Submission time Handle Problem Language Result Execution time Memory
927962 2024-02-15T14:51:52 Z MrM7md cmp (balkan11_cmp) C++17
100 / 100
3601 ms 107084 KB
#include <bits/stdc++.h>
#include "cmp.h"
using namespace std;

void remember(int n) {
   int a[4];
   int _ = n;
   for(int i=3;i>=0;i--){
      a[i]=n%8;
      n/=8;
      a[i]++;
   }
   int cur=0,mlt=1000;
   for(int i=0;i<4;i++){
      cur+=a[i]*mlt;
      mlt/=10;
      // if(_ == 2649) cout << cur << endl;
      bit_set(cur+1);
   }
}

int compare(int b) {
   // cout<<1<<endl;
   int a[4];
   int amp=-1;
   // if(b==3640)amp=b;
   vector<int>v;
   int _ =b;
   for(int i=3;i>=0;i--){
      a[i]=b%8;
      b/=8;
      a[i]++;
   }
   int cur=0,mlt=1000;
   for(int i=0;i<4;i++){
      cur+=a[i]*mlt;
      mlt/=10;
      // if(_==2649)cout<<"-->>"<<cur<<endl;
      v.push_back(cur+1);
   }

   int l=0,r=3;
   int kk=0;
   bool dn=0;
   while(l<=r){
      int md=(l+r)/2;
      int get=bit_get(v[md]);
      // if(_==2649){
      //    cout << get << endl;
      //    cout<<l << ' '<< r<<endl;
      // }
      if(get){
         if(md==3)dn=1;
         l=md+1;
      }
      else{

         kk=md;
         r=md-1;
      }
   }
   // if(_==2649)
   // cout<<"->>>>"<<kk<<' '<<dn<<endl;
   if(dn)return 0;
   int ans=0;
   int m;
   if(kk==0)m=1000;
   else if(kk==1)m=100;
   else if(kk==2)m=10;
   else m=1;
   if(a[kk]<=4){
      bool bl=0;int cnt=3;
      while(cnt--){
         v[kk]-=m;
         if(kk&&v[kk]==v[kk-1])continue;
         if(v[kk]<0)break;
         if(bit_get(v[kk])){
            bl=1;
         }
      }
      if(bl)ans=1;
      else ans=-1;
   }
   else{
      // if(_==2671){
         // cout<<m<<endl;
         // cout<<v[0]<<' '<<v[1]<<' '<<v[2]<<' '<<v[3]<<endl;
      // }
      bool bl=0;int cnt=3;
      while(cnt--){
         v[kk]+=m;
         if(kk&&v[kk]==v[kk-1])continue;
         if(v[kk]>=10000)break;
         if(bit_get(v[kk]))bl=1;
      }
      if(bl)ans=-1;
      else ans=1;
   }
   // if(ans == 0) cout << "herhe";
   return ans;
}

Compilation message

cmp.cpp: In function 'void remember(int)':
cmp.cpp:7:8: warning: unused variable '_' [-Wunused-variable]
    7 |    int _ = n;
      |        ^
cmp.cpp: In function 'int compare(int)':
cmp.cpp:25:8: warning: unused variable 'amp' [-Wunused-variable]
   25 |    int amp=-1;
      |        ^~~
cmp.cpp:28:8: warning: unused variable '_' [-Wunused-variable]
   28 |    int _ =b;
      |        ^
# Verdict Execution time Memory Grader output
1 Correct 3601 ms 107084 KB Output is correct - maxAccess = 10, score = 100