MIME Type puzzle discussion

what do you do then??

See my answer here.

To me, as a beginner in C#, this puzzle is very hard and complex.
I cannot even solve the second test.
I don’t understand why my defined array with stored values cannot be reversed.
Is there even needed array reversing?
Definitely not easy puzzle for me.
Is there super easy ones?

There is a bug in COC C#, because Test2 fails even on outputting “UNKNOWN” with Console.WriteLine().
Standard Output Stream shows UNKNOWN, but no matter what:

Found: Nothing
Expected: UNKNOWN

my code below:

using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;

class Solution
{
    static void Main(string[] args)
    {
        int N = int.Parse(Console.ReadLine()); // Number of elements which make up the association table.
        int Q = int.Parse(Console.ReadLine()); // Number Q of file names to be analyzed.

        string[] arr = new string[N];

        for (int i = 0; i < N; i++)
        {
            string[] inputs = Console.ReadLine().Split(' ');
            string EXT = inputs[0]; // file extension
            string MT = inputs[1]; // MIME type.

            arr[arr.GetLength(0)-i-1] = MT;
        }
        for (int i = 0; i < Q; i++)
        {
            string FNAME = Console.ReadLine(); // One file name per line.            
        }

        bool found = false;

        foreach(var item in arr)
        {
            if(item.Contains("gif") || item.Contains("png") || item.Contains("html"))
            {
                Console.WriteLine($"{item}");
                found = true;
            }
            else
            {
                found = false;
            }
        }

        if(!found)
        {
            Console.WriteLine("UNKNOWN");
        }
    }
}

There’s a bug in your code. You’re reading file names and then disregarding them right away.

If this puzzle proves too difficult for you, you may want to learn and brush up your C# knowledge using other websites first. CodinGame is intended for those with basic knowledge in a programming language.

You are right about having bug in my code.
The bug I found in ‘else’ statement where I missed adding output Console.WriteLine(“UNKNOWN”).
Not sure if bug accounts not in disregarding file names. I haven’t made there yet.
But thanks anyway for mentioning!

You’re welcome.

If you have further questions regarding your code, you may share it with me via private message. It’s better not to post codes in public in this forum.

Ok, got it!:slight_smile:

ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
add this to the beginning of the main function)

Hi, I think there is something broken in the tests at least for c++.
My old c++ solution that already passed two years ago, times out in the last ide validator.
I tried several (valid) c++ solutions from other users here and they also time out.
In fact, I couldn’t find a single c++ solution that was published on codingame for this puzzle that passed in the ide.
The Java version of my program (which is identical in every aspect) passes all tests.

Replying because i have a similar problem. I can’t pass the last test case for large datasets because my code “doesn’t limit extensions”. I am pretty sure it does. Does anyone else have a similar problem ?

How do you know that is the reason? Where does that quote “doesn’t limit file extensions” come from? The console?

Also, what programming language are you using?

Apologies. i was way to vague and should have been more specific. I used C++. I couldn’t pass test case 5 and the console gave the error message:
“Failure
Process has timed out. This may mean that your solution is not optimized enough to handle some cases.”
After i submitted my solution anyway it passed 9 out of 10 validators. The one that it didn’t pass is number 8 : Limit size in extensions

No worries. Now that I understand your situation, there are two things I can do:

  1. Test 5: Very likely there’s an issue with that test case, which was also reported by @Ultrixx last month. I’ll raise a bug report on Discord within this week to ask CodinGame staff to look into it.

  2. Validator 8: Although my old C++ code now times out on Test 5, the same code is still able to pass all validators. That probably indicates either a bug in your code or your code being too slow. If you want, you may send me your code in private message and I’ll take a look at it tomorrow.

EDIT

I’ve searched this forum topic just now. It appears that the issue isn’t new as players raised it a few years ago. CodinGame staff mentioned that they had fixed the C/C++ timeout issue (see here, here and here). A player mentioned one way and another player mentioned another way which helped them pass Test 5. So it might actually be doable.

@BlaiseEbuth If it’s ok for you, could you please help test and confirm whether your implementation still passes all the tests and validators? (I’m trying myself but haven’t succeeded so far.) If it doesn’t, I might later on ask CG to take a look. Or I might ask anyway if the level of optimisation is too much to ask for, given that the puzzle is classified as Easy.

Thank you.

Hey!

It seems I don’t have kept the djb2 code. But I can confirm that my C++ code using std::map doesn’t pass the 5th testcase anymore, even with optimization pragmas, but passes all the validators.

Also, no problems with solutions in other languages like Perl. Even my Clojure solution passes it… :sweat_smile:

The C++ environment is probably less optimized for std now than it used to be…

I could retry to implement a hashmap, but even if it works, it makes the puzzle out of the easy category in C++, as it was already the case for C. Though it’s still pretty easy in other languages, so IDK… :man_shrugging:

1 Like

Thank you for your reply!

It’s good to know we’re on the same page about the challenge this poses in C++ and even C. I’ll give it some more thought before reaching out to CG about the issue. Thanks again!

1 Like

I did some tests with C++ and found that printing consumes the majority of time.

I wrote a solution which, instead of couting a line per loop iteration, outputs to an in-memory buffer first and then dumps everything to stdout at the end. No micro-optimizations, like avoiding allocations, were applied. This solution took just 30ms to do everything except printing, which is way below the time limit of 500ms (obtained experimentally). My solution is available in case anyone is interested.

And your code still times out in the last test, because of the printing, right?

Yes. Only a part of the output was printed before timing out.

1 Like