답안 #548131

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548131 2022-04-12T13:56:01 Z lucaperju 장난감 기차 (IOI17_train) C++17
100 / 100
289 ms 1712 KB
#include <bits/stdc++.h>
#include "train.h"
using namespace std;

vector<int>ed[5005];
vector<int>in[5005];
int cnt[5005],inq[5005];
std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) {
	std::vector<int> res(a.size());
    for(int i=0;i<u.size();++i)
    {
        ed[u[i]].push_back(v[i]);
        in[v[i]].push_back(u[i]);
    }
    while(1)
    {
        vector<int> S(a.size());
        vector<int> toProcess;
        int i,n=a.size();
        for(i=0;i<n;++i)
            inq[i]=cnt[i]=0;
        for(i=0;i<n;++i)
            if(r[i])
                S[i]=1;
            else
                S[i]=0;
        for(i=0;i<n;++i)
        {
            if(S[i])
            {
                for(int j=0;j<in[i].size();++j)
                {
                    int x=in[i][j];
                    if(!S[x] && !inq[x])
                    {
                        ++cnt[x];
                        if(cnt[x]>0 && a[x]==1 || cnt[x]==ed[x].size() && a[x]==0)
                        {
                            inq[x]=1;
                            toProcess.push_back(x);
                        }
                    }
                }
            }
        }
        while(!toProcess.empty())
        {
            int i=toProcess.back();
            toProcess.pop_back();
            inq[i]=0;
            S[i]=1;
            for(int j=0;j<in[i].size();++j)
            {
                int x=in[i][j];
                if(!S[x] && !inq[x])
                {
                    ++cnt[x];
                    if(cnt[x]>0 && a[x]==1 || cnt[x]==ed[x].size() && a[x]==0)
                    {
                        inq[x]=1;
                        toProcess.push_back(x);
                    }
                }
            }
        }
        int pz=-1;
        for(i=0;i<n;++i)
        {
            if(r[i]==1)
            {
                int cntc=0;
                for(int j=0;j<ed[i].size();++j)
                    if(!S[ed[i][j]])
                        ++cntc;
                if(a[i]==0 && cntc>0 || a[i]==1 && cntc==ed[i].size())
                {
                    pz=i;
                    break;
                }
            }
        }
        if(pz==-1)
            return S;
        r[pz]=0;
    }
}

/*
int main() {
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int> a(n), r(n), u(m), v(m);

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &a[i]));

	for(int i = 0; i < n; i++)
		assert(1 == scanf("%d", &r[i]));

	for(int i = 0; i < m; i++)
		assert(2 == scanf("%d %d", &u[i], &v[i]));

	vector<int> res = who_wins(a, r, u, v);

	for(int i = 0; i < (int)res.size(); i++)
		printf(i ? " %d" : "%d", res[i]);
	printf("\n");

	return 0;
}
*/

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:10:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |     for(int i=0;i<u.size();++i)
      |                 ~^~~~~~~~~
train.cpp:31:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |                 for(int j=0;j<in[i].size();++j)
      |                             ~^~~~~~~~~~~~~
train.cpp:37:57: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |                         if(cnt[x]>0 && a[x]==1 || cnt[x]==ed[x].size() && a[x]==0)
      |                                                   ~~~~~~^~~~~~~~~~~~~~
train.cpp:37:37: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   37 |                         if(cnt[x]>0 && a[x]==1 || cnt[x]==ed[x].size() && a[x]==0)
      |                            ~~~~~~~~~^~~~~~~~~~
train.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |             for(int j=0;j<in[i].size();++j)
      |                         ~^~~~~~~~~~~~~
train.cpp:58:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |                     if(cnt[x]>0 && a[x]==1 || cnt[x]==ed[x].size() && a[x]==0)
      |                                               ~~~~~~^~~~~~~~~~~~~~
train.cpp:58:33: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   58 |                     if(cnt[x]>0 && a[x]==1 || cnt[x]==ed[x].size() && a[x]==0)
      |                        ~~~~~~~~~^~~~~~~~~~
train.cpp:72:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |                 for(int j=0;j<ed[i].size();++j)
      |                             ~^~~~~~~~~~~~~
train.cpp:75:56: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |                 if(a[i]==0 && cntc>0 || a[i]==1 && cntc==ed[i].size())
      |                                                    ~~~~^~~~~~~~~~~~~~
train.cpp:75:28: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   75 |                 if(a[i]==0 && cntc>0 || a[i]==1 && cntc==ed[i].size())
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1184 KB Output is correct
2 Correct 94 ms 1184 KB Output is correct
3 Correct 83 ms 1200 KB Output is correct
4 Correct 80 ms 1192 KB Output is correct
5 Correct 80 ms 1180 KB Output is correct
6 Correct 79 ms 1184 KB Output is correct
7 Correct 83 ms 1108 KB Output is correct
8 Correct 21 ms 1108 KB Output is correct
9 Correct 58 ms 1164 KB Output is correct
10 Correct 41 ms 1108 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 536 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 540 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 548 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 544 KB Output is correct
16 Correct 1 ms 540 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 1588 KB Output is correct
2 Correct 94 ms 1576 KB Output is correct
3 Correct 104 ms 1680 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 46 ms 1584 KB Output is correct
6 Correct 23 ms 1620 KB Output is correct
7 Correct 8 ms 1620 KB Output is correct
8 Correct 8 ms 1620 KB Output is correct
9 Correct 7 ms 1492 KB Output is correct
10 Correct 7 ms 1556 KB Output is correct
11 Correct 7 ms 1480 KB Output is correct
12 Correct 6 ms 1492 KB Output is correct
13 Correct 8 ms 1576 KB Output is correct
14 Correct 10 ms 1712 KB Output is correct
15 Correct 10 ms 1620 KB Output is correct
16 Correct 9 ms 1580 KB Output is correct
17 Correct 9 ms 1672 KB Output is correct
18 Correct 147 ms 1292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1364 KB Output is correct
2 Correct 7 ms 1492 KB Output is correct
3 Correct 15 ms 1584 KB Output is correct
4 Correct 222 ms 1620 KB Output is correct
5 Correct 16 ms 1620 KB Output is correct
6 Correct 22 ms 1572 KB Output is correct
7 Correct 46 ms 1492 KB Output is correct
8 Correct 50 ms 1556 KB Output is correct
9 Correct 143 ms 1496 KB Output is correct
10 Correct 8 ms 1620 KB Output is correct
11 Correct 9 ms 1540 KB Output is correct
12 Correct 9 ms 1580 KB Output is correct
13 Correct 7 ms 1584 KB Output is correct
14 Correct 7 ms 1452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1584 KB Output is correct
2 Correct 10 ms 1620 KB Output is correct
3 Correct 9 ms 1580 KB Output is correct
4 Correct 8 ms 1492 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 5 ms 1108 KB Output is correct
7 Correct 5 ms 1236 KB Output is correct
8 Correct 5 ms 1236 KB Output is correct
9 Correct 5 ms 1184 KB Output is correct
10 Correct 2 ms 684 KB Output is correct
11 Correct 5 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 1184 KB Output is correct
2 Correct 94 ms 1184 KB Output is correct
3 Correct 83 ms 1200 KB Output is correct
4 Correct 80 ms 1192 KB Output is correct
5 Correct 80 ms 1180 KB Output is correct
6 Correct 79 ms 1184 KB Output is correct
7 Correct 83 ms 1108 KB Output is correct
8 Correct 21 ms 1108 KB Output is correct
9 Correct 58 ms 1164 KB Output is correct
10 Correct 41 ms 1108 KB Output is correct
11 Correct 4 ms 1236 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 536 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 1 ms 540 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 548 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 544 KB Output is correct
27 Correct 1 ms 540 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 468 KB Output is correct
31 Correct 1 ms 468 KB Output is correct
32 Correct 57 ms 1588 KB Output is correct
33 Correct 94 ms 1576 KB Output is correct
34 Correct 104 ms 1680 KB Output is correct
35 Correct 8 ms 1620 KB Output is correct
36 Correct 46 ms 1584 KB Output is correct
37 Correct 23 ms 1620 KB Output is correct
38 Correct 8 ms 1620 KB Output is correct
39 Correct 8 ms 1620 KB Output is correct
40 Correct 7 ms 1492 KB Output is correct
41 Correct 7 ms 1556 KB Output is correct
42 Correct 7 ms 1480 KB Output is correct
43 Correct 6 ms 1492 KB Output is correct
44 Correct 8 ms 1576 KB Output is correct
45 Correct 10 ms 1712 KB Output is correct
46 Correct 10 ms 1620 KB Output is correct
47 Correct 9 ms 1580 KB Output is correct
48 Correct 9 ms 1672 KB Output is correct
49 Correct 147 ms 1292 KB Output is correct
50 Correct 9 ms 1364 KB Output is correct
51 Correct 7 ms 1492 KB Output is correct
52 Correct 15 ms 1584 KB Output is correct
53 Correct 222 ms 1620 KB Output is correct
54 Correct 16 ms 1620 KB Output is correct
55 Correct 22 ms 1572 KB Output is correct
56 Correct 46 ms 1492 KB Output is correct
57 Correct 50 ms 1556 KB Output is correct
58 Correct 143 ms 1496 KB Output is correct
59 Correct 8 ms 1620 KB Output is correct
60 Correct 9 ms 1540 KB Output is correct
61 Correct 9 ms 1580 KB Output is correct
62 Correct 7 ms 1584 KB Output is correct
63 Correct 7 ms 1452 KB Output is correct
64 Correct 8 ms 1584 KB Output is correct
65 Correct 10 ms 1620 KB Output is correct
66 Correct 9 ms 1580 KB Output is correct
67 Correct 8 ms 1492 KB Output is correct
68 Correct 1 ms 596 KB Output is correct
69 Correct 5 ms 1108 KB Output is correct
70 Correct 5 ms 1236 KB Output is correct
71 Correct 5 ms 1236 KB Output is correct
72 Correct 5 ms 1184 KB Output is correct
73 Correct 2 ms 684 KB Output is correct
74 Correct 5 ms 1108 KB Output is correct
75 Correct 128 ms 1636 KB Output is correct
76 Correct 160 ms 1680 KB Output is correct
77 Correct 210 ms 1620 KB Output is correct
78 Correct 198 ms 1676 KB Output is correct
79 Correct 217 ms 1676 KB Output is correct
80 Correct 8 ms 1588 KB Output is correct
81 Correct 14 ms 1628 KB Output is correct
82 Correct 24 ms 1620 KB Output is correct
83 Correct 76 ms 1632 KB Output is correct
84 Correct 14 ms 1616 KB Output is correct
85 Correct 72 ms 1492 KB Output is correct
86 Correct 37 ms 1620 KB Output is correct
87 Correct 15 ms 1632 KB Output is correct
88 Correct 95 ms 1628 KB Output is correct
89 Correct 42 ms 1632 KB Output is correct
90 Correct 51 ms 1576 KB Output is correct
91 Correct 91 ms 1628 KB Output is correct
92 Correct 92 ms 1640 KB Output is correct
93 Correct 115 ms 1608 KB Output is correct
94 Correct 132 ms 1616 KB Output is correct
95 Correct 102 ms 1620 KB Output is correct
96 Correct 105 ms 1528 KB Output is correct
97 Correct 202 ms 1644 KB Output is correct
98 Correct 289 ms 1620 KB Output is correct
99 Correct 280 ms 1580 KB Output is correct
100 Correct 143 ms 1288 KB Output is correct