Submission #154265

# Submission time Handle Problem Language Result Execution time Memory
154265 2019-09-19T18:53:51 Z stefantaga Bulb Game (FXCUP4_bulb) C++17
100 / 100
103 ms 20752 KB
#include <bits/stdc++.h>
#include "bulb.h"
using namespace std;
struct bec
{
    int st,dr;
}val[300005];
bool notbec (int nr)
{
    if (nr==-1||nr==-2)
    {
        return 0;
    }
    return 1;
}
void dfs (int x,vector <int> &l,vector <int> &r)
{
    if (notbec(l[x]))
    {
        dfs(l[x],l,r);
        val[x].st=val[l[x]].st;
    }
    else
    {
        val[x].st=l[x];
    }
    if (notbec(r[x]))
    {
        dfs(r[x],l,r);
        val[x].dr=val[r[x]].st;
    }
    else
    {
        val[x].dr=r[x];
    }
}int marcaj[300005],marcaj2[300005];
int FindWinner(int t,vector<int> l,vector<int> r)
{
	int n= l.size(),poz,poz1,ok,ok1,i;
	poz=0;
	while (poz!=-1&&poz!=-2)
    {
        poz=l[poz];
    }
    if (poz==-2)
    {
        return 0;
    }
    else
    {
        dfs(0,l,r);
        poz=0;
        ok=0;
        ok1=0;
        while (notbec(poz))
        {
            poz1=r[poz];
            while (notbec(poz1))
            {
                marcaj[poz1]=1;
                poz1=l[poz1];
            }
            marcaj2[poz]=1;
            if (val[r[poz]].st==-2)
            {
                ok1=1;
            }
            poz=l[poz];
        }
        for (i=0;i<n;i++)
        {
            if (notbec(r[i])==0)
            {
                if (r[i]==-2)
                {
                    ok+=notbec(l[0]);
                }
                else
                {
                    ok+=ok1;
                }
            }
            else
            {
                 if (marcaj[i]==1&&(val[r[i]].st==-2||r[i]==-2))
            {
                ok+=max(notbec(l[0]),notbec(r[0]));
            }
            else
            if (marcaj2[i]==1)
            {
                poz=r[i];
                if (notbec(i)==0)
                {
                    if (r[i]==-2)
                    {
                        ok++;
                        continue;
                    }
                }
                if (val[poz].st==-2||poz==-2)
                {
                    ok++;
                    continue;
                }
                while (notbec(poz))
                {
                    if (val[r[poz]].st==-2||r[poz]==-2)
                    {
                        ok++;
                        break;
                    }
                    poz=l[poz];
                }
            }
            else
            {
                ok+=ok1;
            }
            }
        }
        if (ok==n)
        {
            return 0;
        }
        return 1;
    }
}
/// -2 albastru,-1 rosu , Al doilea (0) vrea -2 , Primul (1) -1 .
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 452 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 408 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 452 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 476 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 408 KB Output is correct
25 Correct 4 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 408 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 452 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 3 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 3 ms 376 KB Output is correct
16 Correct 3 ms 376 KB Output is correct
17 Correct 3 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 3 ms 376 KB Output is correct
21 Correct 3 ms 376 KB Output is correct
22 Correct 3 ms 476 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 3 ms 408 KB Output is correct
25 Correct 4 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 77 ms 7900 KB Output is correct
28 Correct 90 ms 10360 KB Output is correct
29 Correct 88 ms 10360 KB Output is correct
30 Correct 101 ms 20752 KB Output is correct
31 Correct 99 ms 20728 KB Output is correct
32 Correct 87 ms 10488 KB Output is correct
33 Correct 88 ms 10488 KB Output is correct
34 Correct 87 ms 10424 KB Output is correct
35 Correct 87 ms 10360 KB Output is correct
36 Correct 89 ms 10428 KB Output is correct
37 Correct 87 ms 10360 KB Output is correct
38 Correct 87 ms 10360 KB Output is correct
39 Correct 91 ms 10488 KB Output is correct
40 Correct 87 ms 10332 KB Output is correct
41 Correct 89 ms 10488 KB Output is correct
42 Correct 88 ms 10360 KB Output is correct
43 Correct 87 ms 10360 KB Output is correct
44 Correct 87 ms 10408 KB Output is correct
45 Correct 87 ms 10360 KB Output is correct
46 Correct 87 ms 10488 KB Output is correct
47 Correct 99 ms 14584 KB Output is correct
48 Correct 103 ms 14636 KB Output is correct
49 Correct 98 ms 14584 KB Output is correct
50 Correct 99 ms 14712 KB Output is correct