Блог пользователя gkapatia

Автор gkapatia, история, 6 лет назад, По-английски

Greetings,

Newton School cordially invites you to be a part of our monthly coding challenge. This month, the challenge is going to take place on eve of 23rd December, 2020 at 9PM IST. The duration of the contest is 150 minutes.

Please follow below link to register. Contest page: https://www.newtonschool.co/contest-home

Highlights of contest:
- The Prize Money is ₹20k and candidates can win exciting prizes and goodies
- Newton School goodies and Rs 100 gift vouchers to top 50 participants
- Rs 100 gift vouchers to 50 randomly selected participants between ranks 51-500
- Exclusive Newton School workshop for the top 500 participants
- We receive more than 10K registrations in our contest from all engineering colleges pan India

Registrations for contest is open till start of contest. *Note: Prizes are for Indian Participants only.

I hope you all will participate and enjoy the contest.

Regards, Newton School Team.

  • Проголосовать: нравится
  • +26
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

whats a Rs

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain solution of 4th question.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

Can someone please share their solution idea for the 6th problem?

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Is it possible for you to share your ideas for the 5th problem?

    • »
      »
      »
      6 лет назад, скрыть # ^ |
       
      Проголосовать: нравится +3 Проголосовать: не нравится

      Yes bro, I used FFT to solve the 5th problem.

      See first create a sort of frequency array of size N to store the frequency of each remainder. Then assuming it to be a polynomial, square it using FFT. And now the question had a condition that X<=Y, but here we'll obtain all possible pairs, to to handle that, separately add the cases where X=Y and then divide the count by 2.

      • »
        »
        »
        »
        6 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Thanks a lot! it would be great if you can share your code from my submissions section :).

        • »
          »
          »
          »
          »
          6 лет назад, скрыть # ^ |
           
          Проголосовать: нравится 0 Проголосовать: не нравится

          Hey, sorry for late reply bro, here's my code:

          //Nightmare05
          #include<bits/stdc++.h>
          
          using namespace std;
          
          #define sp << " " <<
          #define mod 1000000007
          #define mp make_pair
          #define pb push_back
          #define int long long
          #define double long double
          #define INF (1e18+13)
          //#define PI 3.1415926535898
          
          int power(int p,int j)
          {
              int res=1;
              p=p%mod;
              while(j>0)
              {
                  if(j&1)
                      res=(res*p)%mod;
                  j=j>>1;
                  p=(p*p)%mod;
              }
              return res;
          }
          
          
          mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
          
          int dice(int d,int p)
          {
              uniform_int_distribution<int> uid(d,p);//specify l and s.
              return uid(rng) ;
          }
          /*
          int read()
          {
                 int cc = getc(stdin);
                 for (;cc < '0' || cc > '9';)  cc = getc(stdin);
                 int ans = 0;
                 for (;cc >= '0' && cc <= '9';)
                 {
                    ans = ans * 10 + cc - '0';
                    cc = getc(stdin);
                 }
                return ans;
          }
          
          inline void print(int n)
          {
            if (n == 0)
            {
              putchar('0');
              putchar('\n');
            }
            else if (n == -1)
            {
              putchar('-');
              putchar('1');
              putchar('\n');
            }
            else
            {
              char buf[20];
              buf[19] = '\n';
              int i = 18;
              while (n)
              {
                buf[i--] = n % 10 + '0';
                n /= 10;
              }
              while (buf[i] != '\n')
                putchar(buf[++i]);
            }
          }
          
          int n;
          
          vector<vector<int>> mat_mul(vector<vector<int>> a,vector<vector<int>> b)
          {
              int n=2;
              vector<vector<int>> ans2(n,vector<int>(n,0));
              for(int i=0;i<n;i++)
              {
                  for(int j=0;j<n;j++)
                  {
                      for(int k=0;k<n;k++)
                      {
                          ans2[i][j]+=((a[i][k]*b[k][j])%mod);
                          ans2[i][j]%=mod;
                      }
                  }
              }
              return ans2;
          }
          
          vector<vector<int>> pow_mat(vector<vector<int>> mat_a,int p)
          {
              if(p==1)
                  return mat_a;
              vector<vector<int>> temp=pow_mat(mat_a,p/2);
              vector<vector<int>> res=mat_mul(temp,temp);
              if(p&1)
                  res=mat_mul(res,mat_a);
              return res;
          }
          */
          
          using cd = complex<double>;
          const double PI = acos(-1);
          
          void fft(vector<cd> & a, bool invert) {
              int n = a.size();
          
              for (int i = 1, j = 0; i < n; i++) {
                  int bit = n >> 1;
                  for (; j & bit; bit >>= 1)
                      j ^= bit;
                  j ^= bit;
          
                  if (i < j)
                      swap(a[i], a[j]);
              }
          
              for (int len = 2; len <= n; len <<= 1) {
                  double ang = 2 * PI / len * (invert ? -1 : 1);
                  cd wlen(cos(ang), sin(ang));
                  for (int i = 0; i < n; i += len) {
                      cd w(1);
                      for (int j = 0; j < len / 2; j++) {
                          cd u = a[i+j], v = a[i+j+len/2] * w;
                          a[i+j] = u + v;
                          a[i+j+len/2] = u - v;
                          w *= wlen;
                      }
                  }
              }
          
              if (invert) {
                  for (cd & x : a)
                      x /= n;
              }
          }
          
          vector<int> multiply(vector<int> const& a, vector<int> const& b) {
              vector<cd> fa(a.begin(), a.end()), fb(b.begin(), b.end());
              int n = 1;
              while (n < a.size() + b.size())
                  n <<= 1;
              fa.resize(n);
              fb.resize(n);
          
              fft(fa, false);
              fft(fb, false);
              for (int i = 0; i < n; i++)
                  fa[i] *= fb[i];
              fft(fa, true);
          
              vector<int> result(n);
              for (int i = 0; i < n; i++)
                  result[i] = round(fa[i].real());
              return result;
          }
          
          int32_t main()
          {
              ios::sync_with_stdio(false);
              cin.tie(0);
              cout.tie(0);
              //freopen("elimination_validation_input.txt", "r", stdin);
              //freopen("output.txt", "w", stdout);
              int n;
              cin >> n;
              vector<int> a(n,0);
              for(int i=1;i<n;i++)
                  a[(i*i)%n]++;
              vector<int> b=multiply(a,a);
              for(int i=n;i<b.size();i++)
                  b[i%n]+=b[i];
              int dp=0;
              for(int i=0;i<n;i++)
              {
                  dp+=a[i]*b[i];
                  dp+=a[i]*a[(2*i)%n];
              }
              cout << dp/2;
              return 0;
          }
          
      • »
        »
        »
        »
        6 лет назад, скрыть # ^ |
         
        Проголосовать: нравится 0 Проголосовать: не нравится

        Can you tell the exact problem(where you used FFT)?

  • »
    »
    6 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Did you get how to solve the 6th problem or any thoughts on how to solve it?

»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Does anyone have problem statements for the 5th 6th problem, please share

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Can anyone share the code of 2-nd problem please.

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +29 Проголосовать: не нравится

Heyy this ain't fair!! Why can't we see the problems after the contest ends :(