Artin_Zer0's blog

By Artin_Zer0, history, 6 months ago, In English

It has probably happened to everyone that they try to solve a problem, but get a WA (Wrong Answer) or TLE (Time Limit Exceeded) on one of the tests. They want to find the specific test case where their code failed, but in many cases, that test case cannot be found on the submission page.

But...

I’ve found a good solution to this problem. It’s possible that we can’t find the test case on the input page, but we can find it on the output page of our own code. This can be done by making our code’s output correspond to only that single test case.

Like in the following code:

#include <bits/stdc++.h>
using namespace std;

int main(){
  ios_base::sync_with_stdio(0);cin.tie(0);
  int Tc;
  cin >> Tc;   
  int Cnt_Tc = Tc; // Count of test cases
  bool Tcc = false; // If you want to know which test case that is
  int F_Tc = 352; // The test case where your code failed
  while(Tc--) { 
    if(Tc == Cnt_Tc - F_Tc && Tcc){
      /*
          Print input
      */  
      int n;
      cin >> n;
      vector<int> a(n);
      for(auto &x : a) cin >> x;
      cout << n << endl;
      for(auto &x : a) cout << x << " ";
      cout << endl;
    }
    else if(!Tcc){
      /*
            Main code
      */  
      int n;
      cin >> n;
      vector<int> a(n);
      for(auto &x : a)cin >> x;
      int s = 0;
      for(auto &x : a)s += x;
      cout << s << endl;
    }
    else{
      /*
            Just cin extra input
      */  
      int n;
      cin >> n;
      vector<int> extra(n);
      for(auto &x : extra) cin >> x;
    }
  }
  return 0;
}

If this blog helped you, please upvote it :)

  • Vote: I like it
  • -17
  • Vote: I do not like it

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

could u give example with a problem

»
6 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

outputs are also hidden na ?

  • »
    »
    6 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +14 Vote: I do not like it

    Another trick:

    void send (int x) {
        if (x==1) while (1);
        else if (x==2) cout<<"ARANDOMMESSAGE";
        else if (x==3) {
            new int [2ll*1024*1024*1024];
        }
        else if (x==4) abort();
    }
    

    You can send a 2-bit segment of input with every submission like this. However, most contests have submission limit/penalties that disables this trick since it is usually viewed as cheating for exploiting feedback to obtain input data that is hidden.

    • »
      »
      »
      6 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      This is chaotic evil. Love it.

      I had an idea of encoding the input using printable Unicode codepoints but I realized that CF clips the output after 512 bytes, not after 512 chars. So, this ends up being worse.