Codeforces Round 843 Div 2 | Problem B : Gardener And The Array Solution | Newton School

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 พ.ย. 2024

ความคิดเห็น • 20

  • @KaranMashru
    @KaranMashru ปีที่แล้ว +2

    (Subscribe for more such videos)
    Code :
    #include
    using namespace std;
    #define ll long long
    int main()
    {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll t, f, i, j, n, p;
    string ans;

    cin>>t;

    for(;t--;)
    {
    cin>>n;

    unordered_map mp;

    ll k[n];
    vector bits[n];

    for(i=0; i>k[i];

    for(j=0; j>p;
    if(mp.find(p)==mp.end()){
    mp[p]=1;
    }else{
    mp[p]++;
    }
    bits[i].push_back(p);
    }
    }

    ans="NO";

    for(i=0; i

    • @haste291
      @haste291 ปีที่แล้ว

      sir how to store whole bits in one index
      in this line bits[i].push_back(p);

    • @mannumichel1925
      @mannumichel1925 ปีที่แล้ว

      @@haste291 😄aree bhai idhar push_back ho rha hai , vector in c++ ka property hai push_back karne se element attach ho jata hai last mein vector k. Tum ek bar vector in c++ ka video dekh lo samajh jawoge.

  • @beinghappy9223
    @beinghappy9223 ปีที่แล้ว

    Thanks for the amazing explanation .You are doing a great work

  • @HarshKumar-jx3ds
    @HarshKumar-jx3ds 4 หลายเดือนก่อน

    hey can you explain what's wrong with my code, it gives WA at some hidden test case
    #include
    using namespace std;
    #define int long long
    #define pairs pair
    #define vll vector
    #define vps vector
    #define ip(arr) for(int i = 0; i < arr.size(); i++) cin >> arr[i];
    #define op(arr) for(int i = 0; i < arr.size(); i++) { cout k;
    vll curr;
    while(k--){
    int temp;
    cin>>temp;
    curr.push_back(temp);
    }
    arr.push_back(curr);
    }
    bool ans1 = solve(arr);
    reverse(all(arr));
    bool ans2 = solve(arr);
    bool ans = ans1||ans2;
    cout

  • @saurabh.gupta22
    @saurabh.gupta22 6 หลายเดือนก่อน

    Great Explanation sir

  • @reddotcheese
    @reddotcheese ปีที่แล้ว

    Great Explanation sir.

  • @jerichoicbm6648
    @jerichoicbm6648 ปีที่แล้ว

    Any specific reason for taking the subsequence of size n(the total numbers) and not k(

    • @codingcommunitynewtonschoo8582
      @codingcommunitynewtonschoo8582  ปีที่แล้ว +2

      If I consider all n elements , then after remaining 1 element, the chances of OR value remaining same is more. Eg : if n = 10, so in one subsequence I take all 10 elements and in another I take 5 elements. Now, I remove one same element from both subsequence. Now, chances of subsequence having 9 elements and OR value same is more then subsequence having 4 elements. There are 5 more elements in bigger subsequence to fulfill the requirement of the set bits of the element which is removed.
      I hope you got my point.

  • @aradhyapandey1489
    @aradhyapandey1489 ปีที่แล้ว

    nice explanation!!

  • @yashagrawal1663
    @yashagrawal1663 ปีที่แล้ว

    thank you so much

  • @varunakrishnani7688
    @varunakrishnani7688 ปีที่แล้ว

    Thank you! 😊🙏🏻

  • @vimalkumardubey6834
    @vimalkumardubey6834 ปีที่แล้ว +1

    Sir apni codeforces id bataiye !

  • @user-zw3di8fv9z
    @user-zw3di8fv9z ปีที่แล้ว

    sir aap please koi example leke samjha diya kariye.
    aise jyada nahi samajh aata.

  • @hariharibolll3459
    @hariharibolll3459 ปีที่แล้ว +3

    I Have applied the same logic but it gives TLE On Test 5 .Here is the code :
    #include
    using namespace std;
    #define ll long long int
    const int N = 2e5+10;
    int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int t;cin>>t;
    while(t--){
    int arr[N];
    memset(arr,0,sizeof(arr));
    arr[0] = 1;
    ll q ;cin>>q;
    ll qq = q;
    int ff =0;
    vectorbits[q];
    for(ll j= 0;j>n;
    for(ll i = 0;i>y;
    bits[j].push_back(y);
    arr[y]++;
    }


    }
    for(vectorx:bits){
    int f = 1;
    for(ll i= 0;i

    • @codingcommunitynewtonschoo8582
      @codingcommunitynewtonschoo8582  ปีที่แล้ว +1

      Use unordered map instead of arr....

    • @hariharibolll3459
      @hariharibolll3459 ปีที่แล้ว +2

      @@codingcommunitynewtonschoo8582 Yes is got accepted by using map. Thanku PrabhuJi for replying 🙏🌸

    • @siddhantnigam2015
      @siddhantnigam2015 ปีที่แล้ว +1

      @@codingcommunitynewtonschoo8582 why does it give TLE?

    • @hariharibolll3459
      @hariharibolll3459 ปีที่แล้ว +1

      @@siddhantnigam2015 Hare Krishna PrabhuJi. It gives TLE because memset(arr) is done by running a loop of 10^5 . so doing it again and again for each test case will give TLE