ldn060904's blog

By ldn060904, history, 45 hours ago, In English

Hello peoples of codeforces, I just want to ask a question. Recently, I found debugging interactive problems' code manually kinda frustrating. Take this problem as an example. Having to answer the code's queries on my own is really time-consuming and one mistake means typing all over again. But if we could have another code that can simply read the original code's queries and answering them automatically then it would be really useful and convenient, especially when participating in a contest. If the problem was non-interactive, I would simply use files for input and output, but interactive problems require simultaneous interaction between two codes, which makes the solution of using files failed. So I am curious to know how to implement that. I would be so appreciative if someone can provide me a template in C++. Thanks for reading and have a nice day.

  • Vote: I like it
  • +1
  • Vote: I do not like it

45 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by ldn060904 (previous revision, new revision, compare).

45 hours ago, # |
  Vote: I like it +15 Vote: I do not like it

I put all query functions in lambdas. I can easily modify it to return the value from some given data. For example

void solve(){
    int n;
    //vector<int> seq(n);
    auto query = [&](int i,int j){
        cout<<"? "<<i+1<<" "<<j+1<<endl;
        int ans;
        //ans = (seq[i] | seq[j]);
        return ans;

Its very easy to switch between local testing and submissions. You can also use #ifdefs, if you have to change a lot. It's perhaps not the best way to test, but I think it is simple enough.

  • »
    44 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I am looking for a code that can check the original code (the code I would submit). Then I could write a code to generate random tests and check the original one. For example the problem I mentioned in the blog. I want to have a code to simply generate random sequences, run the original code and interact with it, and check whether the sequence that the first code provides are the correct ones. If that is possible, I could automatically check the original one with a lot of random tests and fix the bugs if it gives an incorrect answer. I am sorry if the blog is easily to be misunderstood.

44 hours ago, # |
Rev. 5   Vote: I like it +4 Vote: I do not like it

For this problem, you can write some code like this to check your code