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

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

Today, finally for the first time in history, I got a test case to hack the problem 2155D - Batteries.

But the contest had already ended :(

The test case is actually easy:

(n = 40, a = 4) and the active positions are (1,14,27,40). It should be solved in under (400) operations, but everyone who wrote code that checks by iterating over the gaps between the batteries will get the result in approximately (403)–(404) queries.

One day I'll also hack, today I got the motivation.

UPDATE — It's only for those who did not do cyclic test. (Including tourist)

  • MLA19 Do add this test case for later testing in practice.
  • Проголосовать: нравится
  • +162
  • Проголосовать: не нравится

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

The tests are bad IMO. People wrote O(t * m) code in E which should TLE but passes

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

    I think you mean about $$$O(n^2)$$$, yeah that's the code I'm talking about. But that is actually smart, The code will always give the output in approx the same steps as desired. But yeah approx doesn't always mean less than equal to right :)

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

      No I mean that in Problem E

      People are doing this

      if (n > 1){
              int ans = 0;
              for (int i = 2; i <= m; i++){
                  ans |= col[i];
              }
              cout << (ans ? "Mimo\n" : "Yuyu\n");
          }
      

      This for loop over O(m) but there is no bound on sum of m so its TLE

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

        Oh, The cases were really weak, man.

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

        Not necessarily. 2e9 operations is large, but every one of them is a single OR operation. Time limit is 2 seconds. If we assume one cpu cycle per OR instruction, no compiler optimisation, and 1GHz CPU 2e9 OR operations pass. But codeforces most probably uses faster CPUs, and GCC definitely vectorized the OR operation here because it's GCC it likes doing black magic optimisations. So it should easily pass. Bitwise operations are just way too fast.

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

The array is cyclic, so when your step size is 1, (40+1) gives you a pair (40,1) to check, hence the code that you're talking about will ask exact 40 queries.

run this code to try out different cases, i have currently used your case with my code.


#include "bits/stdc++.h" using namespace std; int32_t main () { int n=40; int q = 0; set<int>st; st.insert(1); st.insert(14); st.insert(27); st.insert(40); auto ask = [&] (int x, int y) -> int { q++; return (st.count(x) and st.count(y)); }; for(int step = 1;step<n;step++){ for(int i=1;i<=n;i++){ int j = (i + step); if(j>n)j-=n; int v = ask(i,j); if(v) { cout<<q<<endl; return 0; } } } cout<<q<<endl; }
»
12 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

We can get the answer here in 40 queries right, because we will get the pair (1, 40) in n iterations for checking the gap length = 1

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

TLDR: those who only asked for (i,j) such that j = i — step , for a step size = step.

and did not consider the pair(i, (i+step)%n+1) , should fail this case mentioned. (tourist is one of them btw).

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

It wouldn't have mattered whether the contest ended or not :(. Hacks were disabled for the problem from the start...

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

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

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

Uphack when?

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

In this testcase, tourist code is finding the answer in 403 operations [1, 14, 27, 40]. It supposed to be find in under 400 operations. Please check on this MLA19

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

I solved the problem in a rather different way from every other solution I have seen; mine seems to get your sample test case in 146 tries, but I am not entirely convinced that my method always works regardless (I ended up submitting right at 1:59:59 and fortunately didn't have any typos, but I didn't have the chance to fully prove to myself that my solution is sufficiently optimal).

What I did:

Spoiler

342117601

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

I think this could be avoided is the interactor uses an approximate algorithm on MIS.