TiredRetiredThread's blog

By TiredRetiredThread, history, 3 years 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 »

By TiredRetiredThread, history, 4 years 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 »

By TiredRetiredThread, history, 4 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 \lt = 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 »

By TiredRetiredThread, history, 5 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 »