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

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

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 :)

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

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

could u give example with a problem

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

outputs are also hidden na ?

  • »
    »
    6 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +14 Проголосовать: не нравится

    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 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      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.