SleepingThread's blog

By SleepingThread, history, 11 months ago, In English

Hello, codeforces!

I'm making a game for a university project, and I faced this problem and thought discussing it on codeforces would be nice because it's somehow related to CP, and shows how CP is useful in real life.

The game is actually about 2 players (Multiplayer game) starting in a room in a house and the goal is to reach another specified room, the house is partitioned into a number of rooms, and each room has colored walls.

  • Each room has at most one hidden gem, and each player can hold at most two gems at the same time.
  • When a player carries a gem of color $$$X$$$ he can pass through any wall of color $$$X$$$ (penetrates the wall to the next room).
  • The two players can collaborate and exchange gems with each other if they are in the same room.
  • If a player found a hidden gem in some room, he can either take it if he carries less than 2 gems, or if he had at least one gem, he can exchange it with one of his gems (this operation is reversible and possible any number of times).

My part is to make a levels generator! until now I finished the basic house structure generator, but I'm stuck on generating a valid distribution for gems. I want to generate the MINIMUM number of gems to make the level solvable!

the number of rooms is at most 20 and there are at most 7 colors. (white walls can't be penetrated, so no gems of white color).

what is the best solution you can come up with :) ?

Full text and comments »

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

By SleepingThread, history, 16 months ago, In English

Today I changed my handle, but when I opened my country rating standing, I noticed that country's flag was gone from the standings.

Full text and comments »

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

By SleepingThread, history, 18 months ago, In English

Hello everyone!

I've been doing CP for almost two years, and I still suck at constructive algorithms, even those problems with low-difficulty tags, especially those problems which their tutorial contains phrases like

We can prove that..

we notice that ...

I feel like I don't have that intuition, and when I try to approach this type of problems.. I feel like : "are you sure you are on the right way ?".

I will be happy to hear your advice!

Or if someone had this problem in the past and now he is fine with constructive algorithms, what did he do?

Thanks :)

Full text and comments »

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

By SleepingThread, history, 21 month(s) ago, In English

I've been doing CP for about one year and a half.

I've trained hard, it was tough, but during this period I was very motivated.

but these days I think I lost my passion, maybe because I couldn't reach another new color, or maybe it's frustration because of thinking that's hard for me to reach a high rating, and my intelligence level limits me to do better.

If you see my solved problems rating, you can't say that I'm a specialist, I spend a lot of time solving high rated problems, maybe because I enjoy learning data structures-tagged problems and learning new things.

although I lost my passion, but I'm sure that I still love it, but there is something stopping me to continue!

any advice is welcomed, I think many people have passed something like this.

Full text and comments »

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

By SleepingThread, history, 2 years ago, In English

Hello everyone! I was solving a problem, but thinking in the wrong way, but I came up with this problem :

Given a 0-1 weighted tree that contains $$$N$$$ nodes $$$N <= 10^5$$$.

The value of a path is the sum of weights on this path.

For each node, find the number of simple paths which passes this node and have an odd value.

Have a good day!

Full text and comments »

  • Vote: I like it
  • -3
  • Vote: I do not like it

By SleepingThread, history, 2 years ago, In English

Hello everyone!

I was trying to solve this problem using hash struct, the complexity of my solution is O(N) which should pass the testings, but the judgment was giving me TLE, and after hours of trying to fix the problem, I decided to remove struct hash and instead of it, build the hash in the main, and Surprisingly it passed the testings!

this is my hash struct:

struct Hash
{
    int n,Base,Mod,Inv;
    vector <int> Po,iPo,Pre;
    Hash(string &s,int base,int mod)
    {
        Mod=mod;
        Base=base;
        Po.pb(1);
        iPo.pb(1);
        Pre.pb(0);
        Inv=inv(base,Mod);
        for(int i=1; i<=(int)s.size(); i++)
            Add(s[i-1]);
    }
    void Add(char c)
    {
        Po.pb(mul(Base,Po.back(),Mod));
        iPo.pb(mul(Inv,iPo.back(),Mod));
        Pre.pb(sum(Pre.back(),mul(c,Po.back(),Mod),Mod));
    }
    int G(int L,int R)
    {
        R++;
        int g=sub(Pre[R],Pre[L],Mod);
        return mul(iPo[L+1],g,Mod);
    }
};

and this is the first submission which was giving TLE and this the accepted submission

you can compare between them and notice that is exactly no difference except replacing the struct with normal code. so the question is, is using struct time consuming ?

Full text and comments »

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