답안 #1065808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065808 2024-08-19T11:56:51 Z Faisal_Saqib 장난감 기차 (IOI17_train) C++17
100 / 100
1752 ms 2272 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vll vector<ll>
#define pb push_back
#define sll set<ll>

const int N=5e3+10;
vll ma[N];
bool charge[N],alive[N],vis[N];
sll rem;
ll n,owner[N],m,deg[N],deg_[N];
sll attr(sll& a,ll player)
{
    ll sz=a.size();
    for(auto&i:rem)
    {
        vis[i]=0;
        deg_[i]=deg[i];
    }
    // cout<<"Computing attractor of: ";
    queue<int> q;
    for(auto&i:a)
    {
        // cout<<i<<' ';
        if(alive[i])
        {
            q.push(i);
            vis[i]=1;
        }
    }
    // cout<<endl;
    sll ans;
    // cout<<"reach: ";
    while(q.size())
    {
        int f=q.front();
        q.pop();
        ans.insert(f);
        // cout<<f<<' ';
        for(ll&y:ma[f])
        {
            if(!alive[y])continue;
            deg_[y]--;
            if(owner[y]==player)
            {
                // y have edge to the set a and is own by palyer so he will take the edge
                if(!vis[y])
                {
                    vis[y]=1;
                    q.push(y);
                }
            }
            else // Owned by other player
            {
                if(deg_[y]==0 and vis[y]==0)
                {
                    vis[y]=1;
                    q.push(y);
                }
            }
        }
    }
    // cout<<endl;
    return ans;
}
sll attrcomp(sll& a,ll player)
{
    // We never want to reach any vertex in a
    // Reach(a) == compliement( Safety(  compliment( a ) ) ) 
    // Reach( compliment ( a ) ) == compliement( Safety( a ) ) 
    // compliment( Reach( compliment ( a ) ) ) == Safety( a )
    sll cp;
    for(auto&i:a)
        cp.insert(i);
    // if(a.find(i)==a.end())
    cp=attr(cp,player);
    sll ans;
    for(auto&i:rem)
        if(cp.find(i)==cp.end())
            ans.insert(i);
    return ans;
}
sll Buchi(sll& a)
{
    ll sz=a.size();
    while(true)
    {
        auto cur=attrcomp(a,1);
        if(cur.size()==0)break;
        // cout<<"Step\n";
        // cout<<"For a: ";
        // for(auto i:a)
        // {
            // cout<<i<<' ';
        // }
        // cout<<endl;
        // cout<<"Got cur: ";
        // for(auto i:cur)
        // {
            // cout<<i<<' ';
        // }
        // cout<<endl;
        cur=attr(cur,2);
        // cout<<"Got cur: ";
        // for(auto i:cur)
        // {
            // cout<<i<<' ';
        // }
        // cout<<endl;
        for(auto&i:cur){
            auto it=a.find(i);
            if(it!=end(a))
                a.erase(it);                
            auto it1=rem.find(i);
            if(it1!=end(rem))
            {
                for(auto jp:ma[i])
                    deg[jp]--;
                alive[i]=0;
                deg[i]=0;
                ma[i].clear();
                rem.erase(it1);
            }
        }
    }
    return a;
}
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v)
{
    n=a.size();
    sll vertexs;
    for(int i=1;i<=n;i++)
    {
        rem.insert(i);
        alive[i]=1;
        if(a[i-1]==1)
        {
            owner[i]=1;
        }
        else
        {
            owner[i]=2;
        }
        if(r[i-1])
        {
            vertexs.insert(i);
            charge[i]=1;
        }
        else
        {
            charge[i]=0;
        }
    }
    m=u.size();
    for(int j=0;j<m;j++)
    {
        u[j]++;
        v[j]++;
        ma[v[j]].pb(u[j]); // Directed edges
        deg[u[j]]++;
        // ma[v[j]].pb(u[j]);
    }
    sll answer=Buchi(vertexs);
    vector<int> ap(n);
    for(int i=1;i<=n;i++)
        ap[i-1]=alive[i];
    return ap;
}

Compilation message

train.cpp: In function 'std::set<long long int> attr(std::set<long long int>&, long long int)':
train.cpp:16:8: warning: unused variable 'sz' [-Wunused-variable]
   16 |     ll sz=a.size();
      |        ^~
train.cpp: In function 'std::set<long long int> Buchi(std::set<long long int>&)':
train.cpp:87:8: warning: unused variable 'sz' [-Wunused-variable]
   87 |     ll sz=a.size();
      |        ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1628 KB Output is correct
2 Correct 9 ms 1628 KB Output is correct
3 Correct 8 ms 1628 KB Output is correct
4 Correct 8 ms 1628 KB Output is correct
5 Correct 7 ms 1624 KB Output is correct
6 Correct 7 ms 1688 KB Output is correct
7 Correct 6 ms 1616 KB Output is correct
8 Correct 9 ms 1628 KB Output is correct
9 Correct 6 ms 1628 KB Output is correct
10 Correct 7 ms 1624 KB Output is correct
11 Correct 6 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 466 ms 1912 KB Output is correct
2 Correct 798 ms 1884 KB Output is correct
3 Correct 993 ms 1880 KB Output is correct
4 Correct 7 ms 1884 KB Output is correct
5 Correct 11 ms 1672 KB Output is correct
6 Correct 9 ms 1880 KB Output is correct
7 Correct 6 ms 1964 KB Output is correct
8 Correct 7 ms 1880 KB Output is correct
9 Correct 6 ms 1884 KB Output is correct
10 Correct 6 ms 1780 KB Output is correct
11 Correct 6 ms 1624 KB Output is correct
12 Correct 6 ms 1876 KB Output is correct
13 Correct 6 ms 1624 KB Output is correct
14 Correct 6 ms 1628 KB Output is correct
15 Correct 6 ms 1624 KB Output is correct
16 Correct 6 ms 1628 KB Output is correct
17 Correct 6 ms 1840 KB Output is correct
18 Correct 1557 ms 1628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2136 KB Output is correct
2 Correct 11 ms 1628 KB Output is correct
3 Correct 7 ms 2044 KB Output is correct
4 Correct 9 ms 2136 KB Output is correct
5 Correct 7 ms 1776 KB Output is correct
6 Correct 9 ms 1628 KB Output is correct
7 Correct 7 ms 1624 KB Output is correct
8 Correct 6 ms 1884 KB Output is correct
9 Correct 8 ms 2140 KB Output is correct
10 Correct 6 ms 2140 KB Output is correct
11 Correct 6 ms 2272 KB Output is correct
12 Correct 6 ms 2140 KB Output is correct
13 Correct 7 ms 1860 KB Output is correct
14 Correct 6 ms 1796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1628 KB Output is correct
2 Correct 6 ms 1824 KB Output is correct
3 Correct 7 ms 1628 KB Output is correct
4 Correct 5 ms 1628 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 4 ms 1628 KB Output is correct
7 Correct 3 ms 1116 KB Output is correct
8 Correct 4 ms 1116 KB Output is correct
9 Correct 3 ms 1116 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 3 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1628 KB Output is correct
2 Correct 9 ms 1628 KB Output is correct
3 Correct 8 ms 1628 KB Output is correct
4 Correct 8 ms 1628 KB Output is correct
5 Correct 7 ms 1624 KB Output is correct
6 Correct 7 ms 1688 KB Output is correct
7 Correct 6 ms 1616 KB Output is correct
8 Correct 9 ms 1628 KB Output is correct
9 Correct 6 ms 1628 KB Output is correct
10 Correct 7 ms 1624 KB Output is correct
11 Correct 6 ms 1372 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 466 ms 1912 KB Output is correct
33 Correct 798 ms 1884 KB Output is correct
34 Correct 993 ms 1880 KB Output is correct
35 Correct 7 ms 1884 KB Output is correct
36 Correct 11 ms 1672 KB Output is correct
37 Correct 9 ms 1880 KB Output is correct
38 Correct 6 ms 1964 KB Output is correct
39 Correct 7 ms 1880 KB Output is correct
40 Correct 6 ms 1884 KB Output is correct
41 Correct 6 ms 1780 KB Output is correct
42 Correct 6 ms 1624 KB Output is correct
43 Correct 6 ms 1876 KB Output is correct
44 Correct 6 ms 1624 KB Output is correct
45 Correct 6 ms 1628 KB Output is correct
46 Correct 6 ms 1624 KB Output is correct
47 Correct 6 ms 1628 KB Output is correct
48 Correct 6 ms 1840 KB Output is correct
49 Correct 1557 ms 1628 KB Output is correct
50 Correct 8 ms 2136 KB Output is correct
51 Correct 11 ms 1628 KB Output is correct
52 Correct 7 ms 2044 KB Output is correct
53 Correct 9 ms 2136 KB Output is correct
54 Correct 7 ms 1776 KB Output is correct
55 Correct 9 ms 1628 KB Output is correct
56 Correct 7 ms 1624 KB Output is correct
57 Correct 6 ms 1884 KB Output is correct
58 Correct 8 ms 2140 KB Output is correct
59 Correct 6 ms 2140 KB Output is correct
60 Correct 6 ms 2272 KB Output is correct
61 Correct 6 ms 2140 KB Output is correct
62 Correct 7 ms 1860 KB Output is correct
63 Correct 6 ms 1796 KB Output is correct
64 Correct 7 ms 1628 KB Output is correct
65 Correct 6 ms 1824 KB Output is correct
66 Correct 7 ms 1628 KB Output is correct
67 Correct 5 ms 1628 KB Output is correct
68 Correct 1 ms 604 KB Output is correct
69 Correct 4 ms 1628 KB Output is correct
70 Correct 3 ms 1116 KB Output is correct
71 Correct 4 ms 1116 KB Output is correct
72 Correct 3 ms 1116 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 3 ms 1116 KB Output is correct
75 Correct 500 ms 1940 KB Output is correct
76 Correct 775 ms 1880 KB Output is correct
77 Correct 972 ms 1968 KB Output is correct
78 Correct 956 ms 2132 KB Output is correct
79 Correct 955 ms 1972 KB Output is correct
80 Correct 7 ms 1880 KB Output is correct
81 Correct 7 ms 1884 KB Output is correct
82 Correct 8 ms 1628 KB Output is correct
83 Correct 9 ms 1880 KB Output is correct
84 Correct 10 ms 1628 KB Output is correct
85 Correct 9 ms 1780 KB Output is correct
86 Correct 10 ms 1628 KB Output is correct
87 Correct 8 ms 1880 KB Output is correct
88 Correct 13 ms 1880 KB Output is correct
89 Correct 8 ms 1884 KB Output is correct
90 Correct 22 ms 1828 KB Output is correct
91 Correct 20 ms 1884 KB Output is correct
92 Correct 50 ms 1884 KB Output is correct
93 Correct 45 ms 1884 KB Output is correct
94 Correct 42 ms 1884 KB Output is correct
95 Correct 49 ms 1908 KB Output is correct
96 Correct 262 ms 1628 KB Output is correct
97 Correct 1018 ms 1884 KB Output is correct
98 Correct 1505 ms 1880 KB Output is correct
99 Correct 1752 ms 2048 KB Output is correct
100 Correct 1552 ms 1880 KB Output is correct