Preparing for the Contest | Codeforces 1914B Solution | Codeforces Round 916 (Div. 3) | English

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

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

  • @ThamyresDanielaBarbosa
    @ThamyresDanielaBarbosa 6 หลายเดือนก่อน

    can you show how it would be done in python?

  • @priyanshkumar17
    @priyanshkumar17 10 หลายเดือนก่อน

    Sir, for this question, I used a naive approach. But, on submitting, I'm getting wrong answer on test 2.
    I have invested 3 hours (after the contest) on my existing approach before viewing this video solution.
    I request you to please reply me regarding WHY this approach isn't getting passed ?
    My code is :
    #include
    using namespace std;
    void printVec(vector vec){
    for(int i = 0; i < vec.size(); i++){
    cout > k;
    vector vec;
    for(int i = 0; i < n; i++){
    vec.push_back(i + 1);
    }
    // Edge Cases
    if(k == n - 1){
    printVec(vec);
    return;
    }
    if(k == 0){
    reverse(vec.begin(), vec.end());
    printVec(vec);
    return;
    }
    int i = 0, j = 1;
    int count = n - 1;
    while(count != k && i < n && j < n){
    swap(vec[i], vec[j]);
    count--;
    i += 2;
    j += 2;
    }
    if(count == k){
    printVec(vec);
    return;
    }
    }
    int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
    solve();
    }
    return 0;
    }

    • @codingdynamo
      @codingdynamo  10 หลายเดือนก่อน

      What is the answer for your solution for test case
      1
      5 1
      i.e. n = 5 and k = 1, it returns empty. This is one issue.

    • @priyanshkumar17
      @priyanshkumar17 10 หลายเดือนก่อน +1

      haa sir yeh galti thi. Thanks for pointing it out.​