답안 #1065801

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1065801 2024-08-19T11:52:32 Z Faisal_Saqib 장난감 기차 (IOI17_train) C++17
49 / 100
2000 ms 2904 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 10 ms 1884 KB Output is correct
2 Correct 10 ms 1884 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 9 ms 1884 KB Output is correct
5 Correct 8 ms 2048 KB Output is correct
6 Correct 8 ms 1884 KB Output is correct
7 Correct 6 ms 1880 KB Output is correct
8 Correct 11 ms 1884 KB Output is correct
9 Correct 7 ms 2136 KB Output is correct
10 Correct 10 ms 1932 KB Output is correct
11 Correct 6 ms 1884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 600 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 472 ms 1880 KB Output is correct
2 Correct 831 ms 2284 KB Output is correct
3 Correct 1091 ms 2396 KB Output is correct
4 Correct 11 ms 2140 KB Output is correct
5 Correct 11 ms 1884 KB Output is correct
6 Correct 10 ms 1880 KB Output is correct
7 Correct 8 ms 2576 KB Output is correct
8 Correct 7 ms 2140 KB Output is correct
9 Correct 7 ms 2380 KB Output is correct
10 Correct 8 ms 1884 KB Output is correct
11 Correct 7 ms 2056 KB Output is correct
12 Correct 7 ms 2396 KB Output is correct
13 Correct 8 ms 1992 KB Output is correct
14 Correct 10 ms 1880 KB Output is correct
15 Correct 6 ms 1860 KB Output is correct
16 Correct 7 ms 2140 KB Output is correct
17 Correct 8 ms 1884 KB Output is correct
18 Correct 1854 ms 2240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 2904 KB Output is correct
2 Correct 7 ms 1628 KB Output is correct
3 Correct 6 ms 2140 KB Output is correct
4 Correct 8 ms 2140 KB Output is correct
5 Correct 8 ms 1932 KB Output is correct
6 Correct 7 ms 1628 KB Output is correct
7 Correct 8 ms 1884 KB Output is correct
8 Correct 8 ms 2020 KB Output is correct
9 Correct 11 ms 2652 KB Output is correct
10 Correct 7 ms 2596 KB Output is correct
11 Correct 12 ms 2804 KB Output is correct
12 Correct 7 ms 2652 KB Output is correct
13 Correct 7 ms 1884 KB Output is correct
14 Correct 7 ms 1792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1884 KB Output is correct
2 Correct 6 ms 1788 KB Output is correct
3 Correct 8 ms 1628 KB Output is correct
4 Correct 6 ms 1628 KB Output is correct
5 Correct 1 ms 576 KB Output is correct
6 Correct 4 ms 1884 KB Output is correct
7 Correct 3 ms 1112 KB Output is correct
8 Correct 3 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 4 ms 1116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 1884 KB Output is correct
2 Correct 10 ms 1884 KB Output is correct
3 Correct 9 ms 1884 KB Output is correct
4 Correct 9 ms 1884 KB Output is correct
5 Correct 8 ms 2048 KB Output is correct
6 Correct 8 ms 1884 KB Output is correct
7 Correct 6 ms 1880 KB Output is correct
8 Correct 11 ms 1884 KB Output is correct
9 Correct 7 ms 2136 KB Output is correct
10 Correct 10 ms 1932 KB Output is correct
11 Correct 6 ms 1884 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 600 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 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 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 0 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 0 ms 348 KB Output is correct
32 Correct 472 ms 1880 KB Output is correct
33 Correct 831 ms 2284 KB Output is correct
34 Correct 1091 ms 2396 KB Output is correct
35 Correct 11 ms 2140 KB Output is correct
36 Correct 11 ms 1884 KB Output is correct
37 Correct 10 ms 1880 KB Output is correct
38 Correct 8 ms 2576 KB Output is correct
39 Correct 7 ms 2140 KB Output is correct
40 Correct 7 ms 2380 KB Output is correct
41 Correct 8 ms 1884 KB Output is correct
42 Correct 7 ms 2056 KB Output is correct
43 Correct 7 ms 2396 KB Output is correct
44 Correct 8 ms 1992 KB Output is correct
45 Correct 10 ms 1880 KB Output is correct
46 Correct 6 ms 1860 KB Output is correct
47 Correct 7 ms 2140 KB Output is correct
48 Correct 8 ms 1884 KB Output is correct
49 Correct 1854 ms 2240 KB Output is correct
50 Correct 8 ms 2904 KB Output is correct
51 Correct 7 ms 1628 KB Output is correct
52 Correct 6 ms 2140 KB Output is correct
53 Correct 8 ms 2140 KB Output is correct
54 Correct 8 ms 1932 KB Output is correct
55 Correct 7 ms 1628 KB Output is correct
56 Correct 8 ms 1884 KB Output is correct
57 Correct 8 ms 2020 KB Output is correct
58 Correct 11 ms 2652 KB Output is correct
59 Correct 7 ms 2596 KB Output is correct
60 Correct 12 ms 2804 KB Output is correct
61 Correct 7 ms 2652 KB Output is correct
62 Correct 7 ms 1884 KB Output is correct
63 Correct 7 ms 1792 KB Output is correct
64 Correct 7 ms 1884 KB Output is correct
65 Correct 6 ms 1788 KB Output is correct
66 Correct 8 ms 1628 KB Output is correct
67 Correct 6 ms 1628 KB Output is correct
68 Correct 1 ms 576 KB Output is correct
69 Correct 4 ms 1884 KB Output is correct
70 Correct 3 ms 1112 KB Output is correct
71 Correct 3 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 4 ms 1116 KB Output is correct
75 Correct 528 ms 2244 KB Output is correct
76 Correct 849 ms 2288 KB Output is correct
77 Correct 1072 ms 2396 KB Output is correct
78 Correct 1093 ms 2396 KB Output is correct
79 Correct 1095 ms 2392 KB Output is correct
80 Correct 8 ms 2140 KB Output is correct
81 Correct 8 ms 2140 KB Output is correct
82 Correct 9 ms 1988 KB Output is correct
83 Correct 9 ms 1884 KB Output is correct
84 Correct 10 ms 1884 KB Output is correct
85 Correct 8 ms 2144 KB Output is correct
86 Correct 11 ms 1884 KB Output is correct
87 Correct 7 ms 2140 KB Output is correct
88 Correct 14 ms 1992 KB Output is correct
89 Correct 9 ms 2236 KB Output is correct
90 Correct 23 ms 1880 KB Output is correct
91 Correct 22 ms 2140 KB Output is correct
92 Correct 52 ms 2140 KB Output is correct
93 Correct 47 ms 2136 KB Output is correct
94 Correct 44 ms 2140 KB Output is correct
95 Correct 52 ms 2176 KB Output is correct
96 Correct 227 ms 1884 KB Output is correct
97 Correct 1128 ms 2396 KB Output is correct
98 Correct 1696 ms 2392 KB Output is correct
99 Execution timed out 2028 ms 2592 KB Time limit exceeded
100 Halted 0 ms 0 KB -