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

Автор McDic, 5 лет назад, По-английски

Recently I made a problem that requires calculating 20~30 digits of precision. (Calculating high precision is not a main idea, it's just required to solve this problem easily. This approach can be avoided and solvable by only big integers, but it needs very unusual mathematical observation.)

One of my friends said this problem should not be opened for Competitive Programming participants. He said this problem is bad because this requires hard work to self-implement high precision data structures or use built-in structures are not in C++ like Python's decimal.Decimal or Java's java.math.BigDecimal.

Why this feature makes this problem bad as competitive programming problem? I can see many problems in Codeforces force users to use either fast languages like C++ or very weird usage of system calls like I/O operations. Also, some data structures like Red-Black tree are not built in some languages like Python 3. Why not for this case?

Can anyone explain? Thanks in advance.

I removed that problem from my current proposal list. If I succeed to deal with constraints to make avoid BigDecimal/BigInteger easily, I will add it. Other problems are not forcing you to use such data structures. Thank you for all feedbacks.

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

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится -17 Проголосовать: не нравится

I read the title of the blog wrongly. I thought it was "What kind of problems are prohibited in CP?"

Sorry for the unrelated answer.

  • »
    »
    5 лет назад, # ^ |
    Rev. 4   Проголосовать: нравится -10 Проголосовать: не нравится

    I implemented python solution for this problem using Python 3 and built-in modules. This problem is not research problem.

»
5 лет назад, # |
  Проголосовать: нравится +52 Проголосовать: не нравится

They aren't prohibited, just not liked since most problems requiring huge numbers of precision can be easily solved if using python or java, and if the idea is cool then most likely the same properties exist for numbers of size 10^18 or numbers modulo some 10 digit prime. Also codejam had one problem which required bigInt in qualification round, so its not as if they don't exist, they are just not common because of what I mention.

  • »
    »
    5 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

    Thanks for detailed explanation. I can see there is a way exist to convert my problem into modulo problem without losing properties, but it's hard to deal with size of constraints.. I think I should look into it.

    By the way, why they don't like if problem can be easily solved if using Python or Java? There are also some problems force user to use C++ to solve easily.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится -7 Проголосовать: не нравится

    I wouldn't say that the problem in Code Jam was bad. First of all, the subtask that required bigInt was only worth 1 point, and as it stated in the statement, it was only for fun and bragging rights. Also, it didn't really require a bigInt implementation, since no complex operations (e.g. mod) needed to be done. A simple implementation using string was enough. Because of the nature of the problem, even without using bigInt, you (or at least I) still had to iterate digit-wise the number, so implementing it using a string could even be easier than dividing by 10 every time.

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +30 Проголосовать: не нравится

      Test set 2 of Cryptopangrams (also from the qualification round) required for compute the GCD of numbers as big as $$$10^{200}$$$. And that was worth 15 points.

»
5 лет назад, # |
  Проголосовать: нравится +35 Проголосовать: не нравится

Would you like such problem in a round, when you participate?

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +86 Проголосовать: не нравится

    I don't like geometry problem in rounds, it also should be prohibited?

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

    Unless the problem requires some random dirty codes, I think I should get used to it. Isn't that good attitude for problem solving?

    • »
      »
      »
      5 лет назад, # ^ |
        Проголосовать: нравится +13 Проголосовать: не нравится

      well, if you write problem with 25-digit precision in C++, it will probably require some dirty codes.

      • »
        »
        »
        »
        5 лет назад, # ^ |
        Rev. 2   Проголосовать: нравится -15 Проголосовать: не нравится

        Then you can avoid C++ or get external reference for decimal code in case.

        • »
          »
          »
          »
          »
          5 лет назад, # ^ |
            Проголосовать: нравится +8 Проголосовать: не нравится

          Yeah, just because coding it up in c++ is difficult, it doesn't mean that those type of problems should not appear in contests.

»
5 лет назад, # |
  Проголосовать: нравится +17 Проголосовать: не нравится

80-90% people in CP use C++. So recommended way of setting problems are bias towards C++ users. Some problems aren't solvable in some languages, so in some platform they explicitly say that "It is not guaranteed that all problems can be solved in all languages".

Btw in Python there is Set and dictionary, so I don't understand the point about "Red-black tree" not built in in Python 3? (I'm really just asking, I'm not very used to Python).

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится -22 Проголосовать: не нравится

    Understand, thank you. But it's surprising that C++ is still major language in competitive programming since Python and Java are dominating popularity for many years.

    Python's set and dict are hash table, so it has different properties than red black tree.

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

      Competitive programming focuses heavily on speed. Java is a few times slower than C++, so some people do use it for competitive programming (though they're still at a disadvantage), but Python can be up to 50-100 times slower than C++ in certain cases.

      Do you have any source for "Python and Java are dominating for many years", since I don't agree with that statement. All C++, Java and Python are popular languages and they all have different tradeoffs. For example, Python is dominating in Data Science, but for competitive programming Python is a very bad choice just because of the nature of the field.

      • »
        »
        »
        »
        5 лет назад, # ^ |
        Rev. 3   Проголосовать: нравится +8 Проголосовать: не нравится

        I always learned it's better to optimize approaches in fundamental level, not just some unnecessarily considered overheads.

        Sure, C++ dominates the field of competitive programming. But in many fields C++ and C are not "1st-placed in usage" languages and I thought this is one of the big factors of usage in competitive programming.

        By the way, I referenced PYPL and other many blogs, but I can see C/C++ are higher than Python in some of popular indices like TIOBE.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится +13 Проголосовать: не нравится

    Set in python is a hashtable not a bst.

»
5 лет назад, # |
Rev. 2   Проголосовать: нравится +16 Проголосовать: не нравится

I think this kind of problem is not bad, for a fair view. But the actual world is not so fair.

Suppose that someone publishes problem which requires large integers which does not fit into $$$64$$$ or $$$128$$$-bit integers, and criticized. They criticize like "it requires program language skill, which is not fair". But I think that, we can even use the criticism idea to the problem which requires to use $$$O(n \log n)$$$ Dijkstra Algorithm. That's because the programming language C# doesn't support Priority Queue. But of course, we are reluctant to bring such criticism to Dijkstra Algorithm problem.

That's why I am having opinion that using things like bigint in programming contests are fair and should not be criticized. Actually, I actually did this discussion when SRM 737 Div1 Medium, but I realized that my opinion is obviously in minority.

»
5 лет назад, # |
  Проголосовать: нравится +25 Проголосовать: не нравится

Let's say that I have a problem which is one liner in PHP and any other language require at least 1000 lines of bugs. Does that justify using this problem in a contest?

And your next point, using C++ as a fast language is the same as using Python for a language that has builtin BigInt. Speed and optimization is a very important key in Competitive programming so some problem makes it hard for slow languages to pass in the time limit, "They have no choice".

But "most" of problems that require BigInt just does that for the sake of it. They could have set the constraints lower or choosing to print the answer mod number.

  • »
    »
    5 лет назад, # ^ |
    Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится
    1. I think you scaled a lot. It's better to compare to between implementing Red-Black tree from nothing yourself or using std::set.

    2. Understand, thank you. But please look at this comment

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

      Implementing a balanced binary tree (treap, AVL, splay, implicit segment tree or whatever you want to use) is, in my opinion, way easier than implementing your own BigDecimal (and, I think, is even easier than custom BigInteger).

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

        It might be depend on how you focus on optimizations on multiplication/modulo operations. Sometimes it needs to be fully optimized, but sometimes it is not necessary.

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

OK, so suppose you will use such a task in some contest I'll participate. Then I'll do one of the following:

  1. Use python

  2. Search on github a big integer/decimal template and just use it.

Is this what you want? What's the point?

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится -8 Проголосовать: не нравится

    That's just additional step for convenience, many people use their pre-coded codes or templates for complex data structures.

»
5 лет назад, # |
  Проголосовать: нравится +24 Проголосовать: не нравится

It is much more fun to solve problem that require critical thinking, solving problem that require knowledge of builtin function or some different language is neither interesting nor fair for everyone. so if you can avoid use of bigdecimal without changing problem idea, then you should do it.

  • »
    »
    5 лет назад, # ^ |
      Проголосовать: нравится -8 Проголосовать: не нравится

    It may be vary to say which knowledge should be basic or not, even for usage of some language's features and basic data structures.

»
5 лет назад, # |
  Проголосовать: нравится +30 Проголосовать: не нравится

Does it add anything to the problem? There's a difference between "We need this because it's cool and necessary to solve the problem" vs "We used big integers/decimals just to say we used them".

You say it's not a main idea. Then it shouldn't be part of the problem in my view.

»
5 лет назад, # |
Rev. 5   Проголосовать: нравится 0 Проголосовать: не нравится

(merged this comment in main post)

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Competitive programming is supposed to be mostly about algorithms. How much of your problem is algorithmic and how much can be "solved" by having a bigint library available? It's not that problems using bigints are not allowed, they just tend to suck. See: 986D - Perfect Encoding.

I have no idea if your problem is like that. If the bigints are necessary to allow a really novel solution, there should be no problem using it in a contest, but from past experience, I don't expect it to be like that.