답안 #921956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
921956 2024-02-04T15:03:01 Z HuyQuang_re_Zero 장난감 기차 (IOI17_train) C++14
100 / 100
937 ms 9812 KB
#include <bits/stdc++.h>
#define ll long long
#define db long double
#define N 200005
#define II pair <ll,ll>
#define III pair <ll,II>
#define IV pair <vector <int>,vector <int> >
#define IDB pair <db,int>
#define TII pair <treap*,treap*>
#define fst first
#define snd second
#define BIT(x,i) ((x>>i)&1)
#define pi acos(-1)
#define to_radian(x) (x*pi/180.0)
#define to_degree(x) (x*180.0/pi)
#define Log(x) (31-__builtin_clz((int)x))
#define LogLL(x) (63-__builtin_clzll((ll)x))
using namespace std;
#include "train.h"
int d[5005],own[N],is_charge[N],U[N],V[N],n,m,i,u,v,res[N],deg[5005];
vector <int> a[N];
vector <int> who_wins(vector <int> _own,vector <int> _is_charge,vector <int> _U,vector <int> _V)
{
    for(i=0;i<_own.size();i++)
    {
        n++;
        own[n]=_own[i]; is_charge[n]=_is_charge[i];
    }
    for(i=0;i<_U.size();i++)
    {
        m++;
        U[m]=_U[i]+1; V[m]=_V[i]+1;
    }

    memset(res,-1,sizeof(res));
    while(1)
    {
        auto BFS=[&](vector <int> vec,int ok)
        {
            for(u=1;u<=n;u++) a[u].clear();
            memset(deg,0,sizeof(deg));
            for(i=1;i<=m;i++)
            {
                u=U[i]; v=V[i];
                if(res[u]==-1 && res[v]==-1)
                    a[v].push_back(u),deg[u]++;
            }
            memset(d,0,sizeof(d));
            queue <int> q;
            for(int u:vec) q.push(u),d[u]=1;
            while(q.size()>0)
            {
                int u=q.front(); q.pop();
                for(int v:a[u])
                {
                    deg[v]--;
                    if(d[v]==0 && (deg[v]==0 || own[v]==ok))
                        q.push(v),d[v]=1;
                }
            }
        };
        vector <int> vec;
        for(u=1;u<=n;u++)
            if(res[u]==-1 && is_charge[u])
                vec.push_back(u);
        BFS(vec,1);
        vec.clear();
        for(u=1;u<=n;u++)
            if(res[u]==-1 && d[u]==0)
                vec.push_back(u);
        if(vec.size()==0)
        {
            for(u=1;u<=n;u++)
                if(res[u]==-1) res[u]=1;
            break;
        }
        BFS(vec,0);
        for(u=1;u<=n;u++)
            if(res[u]==-1 && d[u]==1)
                res[u]=0;
    }
    vector <int> w;
    for(u=1;u<=n;u++) w.push_back(res[u]);
    return w;
}
/*
int main()
{
    freopen("train.inp","r",stdin);
    freopen("train.out","w",stdout);
    int n,m,k; cin>>n>>m;
    vector <int> own,is_charge,U,V;
    for(int i=1;i<=n;i++) cin>>k,own.push_back(k);
    for(int i=1;i<=n;i++) cin>>k,is_charge.push_back(k);
    for(int i=1;i<=m;i++) cin>>u,U.push_back(u);
    for(int i=1;i<=m;i++) cin>>v,V.push_back(v);
    vector <int> w=who_wins(own,is_charge,U,V);
    for(int k:w) cout<<k<<" ";
}

*/

Compilation message

train.cpp: In function 'std::vector<int> who_wins(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:24:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(i=0;i<_own.size();i++)
      |             ~^~~~~~~~~~~~
train.cpp:29:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(i=0;i<_U.size();i++)
      |             ~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9052 KB Output is correct
2 Correct 6 ms 9308 KB Output is correct
3 Correct 5 ms 9348 KB Output is correct
4 Correct 6 ms 9308 KB Output is correct
5 Correct 6 ms 9352 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 5 ms 9340 KB Output is correct
8 Correct 7 ms 9308 KB Output is correct
9 Correct 5 ms 9560 KB Output is correct
10 Correct 5 ms 9052 KB Output is correct
11 Correct 5 ms 9052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 8796 KB Output is correct
2 Correct 2 ms 8796 KB Output is correct
3 Correct 2 ms 8796 KB Output is correct
4 Correct 2 ms 8796 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 2 ms 8796 KB Output is correct
7 Correct 2 ms 8796 KB Output is correct
8 Correct 2 ms 8796 KB Output is correct
9 Correct 2 ms 8796 KB Output is correct
10 Correct 2 ms 8796 KB Output is correct
11 Correct 2 ms 8796 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8800 KB Output is correct
17 Correct 2 ms 8636 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 135 ms 9480 KB Output is correct
2 Correct 281 ms 9308 KB Output is correct
3 Correct 383 ms 9472 KB Output is correct
4 Correct 7 ms 9308 KB Output is correct
5 Correct 11 ms 9564 KB Output is correct
6 Correct 11 ms 9608 KB Output is correct
7 Correct 8 ms 9564 KB Output is correct
8 Correct 8 ms 9668 KB Output is correct
9 Correct 10 ms 9564 KB Output is correct
10 Correct 7 ms 9564 KB Output is correct
11 Correct 7 ms 9564 KB Output is correct
12 Correct 7 ms 9564 KB Output is correct
13 Correct 8 ms 9564 KB Output is correct
14 Correct 10 ms 9564 KB Output is correct
15 Correct 9 ms 9676 KB Output is correct
16 Correct 7 ms 9564 KB Output is correct
17 Correct 8 ms 9564 KB Output is correct
18 Correct 578 ms 9384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 9308 KB Output is correct
2 Correct 6 ms 9308 KB Output is correct
3 Correct 6 ms 9308 KB Output is correct
4 Correct 9 ms 9308 KB Output is correct
5 Correct 7 ms 9304 KB Output is correct
6 Correct 9 ms 9308 KB Output is correct
7 Correct 7 ms 9308 KB Output is correct
8 Correct 7 ms 9308 KB Output is correct
9 Correct 7 ms 9308 KB Output is correct
10 Correct 7 ms 9308 KB Output is correct
11 Correct 7 ms 9308 KB Output is correct
12 Correct 8 ms 6748 KB Output is correct
13 Correct 9 ms 8796 KB Output is correct
14 Correct 8 ms 6772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 6744 KB Output is correct
2 Correct 8 ms 6888 KB Output is correct
3 Correct 9 ms 7004 KB Output is correct
4 Correct 6 ms 9544 KB Output is correct
5 Correct 2 ms 8796 KB Output is correct
6 Correct 4 ms 9092 KB Output is correct
7 Correct 5 ms 9308 KB Output is correct
8 Correct 5 ms 9488 KB Output is correct
9 Correct 5 ms 9308 KB Output is correct
10 Correct 3 ms 8796 KB Output is correct
11 Correct 5 ms 9224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 9052 KB Output is correct
2 Correct 6 ms 9308 KB Output is correct
3 Correct 5 ms 9348 KB Output is correct
4 Correct 6 ms 9308 KB Output is correct
5 Correct 6 ms 9352 KB Output is correct
6 Correct 5 ms 9308 KB Output is correct
7 Correct 5 ms 9340 KB Output is correct
8 Correct 7 ms 9308 KB Output is correct
9 Correct 5 ms 9560 KB Output is correct
10 Correct 5 ms 9052 KB Output is correct
11 Correct 5 ms 9052 KB Output is correct
12 Correct 2 ms 8796 KB Output is correct
13 Correct 2 ms 8796 KB Output is correct
14 Correct 2 ms 8796 KB Output is correct
15 Correct 2 ms 8796 KB Output is correct
16 Correct 2 ms 8796 KB Output is correct
17 Correct 2 ms 8796 KB Output is correct
18 Correct 2 ms 8796 KB Output is correct
19 Correct 2 ms 8796 KB Output is correct
20 Correct 2 ms 8796 KB Output is correct
21 Correct 2 ms 8796 KB Output is correct
22 Correct 2 ms 8796 KB Output is correct
23 Correct 2 ms 8796 KB Output is correct
24 Correct 2 ms 8796 KB Output is correct
25 Correct 2 ms 8796 KB Output is correct
26 Correct 2 ms 8796 KB Output is correct
27 Correct 2 ms 8800 KB Output is correct
28 Correct 2 ms 8636 KB Output is correct
29 Correct 2 ms 8796 KB Output is correct
30 Correct 2 ms 8796 KB Output is correct
31 Correct 2 ms 8828 KB Output is correct
32 Correct 135 ms 9480 KB Output is correct
33 Correct 281 ms 9308 KB Output is correct
34 Correct 383 ms 9472 KB Output is correct
35 Correct 7 ms 9308 KB Output is correct
36 Correct 11 ms 9564 KB Output is correct
37 Correct 11 ms 9608 KB Output is correct
38 Correct 8 ms 9564 KB Output is correct
39 Correct 8 ms 9668 KB Output is correct
40 Correct 10 ms 9564 KB Output is correct
41 Correct 7 ms 9564 KB Output is correct
42 Correct 7 ms 9564 KB Output is correct
43 Correct 7 ms 9564 KB Output is correct
44 Correct 8 ms 9564 KB Output is correct
45 Correct 10 ms 9564 KB Output is correct
46 Correct 9 ms 9676 KB Output is correct
47 Correct 7 ms 9564 KB Output is correct
48 Correct 8 ms 9564 KB Output is correct
49 Correct 578 ms 9384 KB Output is correct
50 Correct 6 ms 9308 KB Output is correct
51 Correct 6 ms 9308 KB Output is correct
52 Correct 6 ms 9308 KB Output is correct
53 Correct 9 ms 9308 KB Output is correct
54 Correct 7 ms 9304 KB Output is correct
55 Correct 9 ms 9308 KB Output is correct
56 Correct 7 ms 9308 KB Output is correct
57 Correct 7 ms 9308 KB Output is correct
58 Correct 7 ms 9308 KB Output is correct
59 Correct 7 ms 9308 KB Output is correct
60 Correct 7 ms 9308 KB Output is correct
61 Correct 8 ms 6748 KB Output is correct
62 Correct 9 ms 8796 KB Output is correct
63 Correct 8 ms 6772 KB Output is correct
64 Correct 9 ms 6744 KB Output is correct
65 Correct 8 ms 6888 KB Output is correct
66 Correct 9 ms 7004 KB Output is correct
67 Correct 6 ms 9544 KB Output is correct
68 Correct 2 ms 8796 KB Output is correct
69 Correct 4 ms 9092 KB Output is correct
70 Correct 5 ms 9308 KB Output is correct
71 Correct 5 ms 9488 KB Output is correct
72 Correct 5 ms 9308 KB Output is correct
73 Correct 3 ms 8796 KB Output is correct
74 Correct 5 ms 9224 KB Output is correct
75 Correct 227 ms 9656 KB Output is correct
76 Correct 288 ms 9680 KB Output is correct
77 Correct 402 ms 9688 KB Output is correct
78 Correct 387 ms 9564 KB Output is correct
79 Correct 400 ms 7020 KB Output is correct
80 Correct 7 ms 9600 KB Output is correct
81 Correct 8 ms 9712 KB Output is correct
82 Correct 9 ms 9564 KB Output is correct
83 Correct 8 ms 9564 KB Output is correct
84 Correct 8 ms 9564 KB Output is correct
85 Correct 10 ms 9564 KB Output is correct
86 Correct 12 ms 9564 KB Output is correct
87 Correct 9 ms 9604 KB Output is correct
88 Correct 14 ms 9564 KB Output is correct
89 Correct 8 ms 9564 KB Output is correct
90 Correct 16 ms 9664 KB Output is correct
91 Correct 16 ms 9564 KB Output is correct
92 Correct 33 ms 9708 KB Output is correct
93 Correct 38 ms 9564 KB Output is correct
94 Correct 31 ms 9564 KB Output is correct
95 Correct 33 ms 9564 KB Output is correct
96 Correct 88 ms 9580 KB Output is correct
97 Correct 614 ms 9812 KB Output is correct
98 Correct 866 ms 9812 KB Output is correct
99 Correct 937 ms 9692 KB Output is correct
100 Correct 562 ms 9308 KB Output is correct