답안 #390143

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
390143 2021-04-15T12:47:35 Z mehrdad_sohrabi 장난감 기차 (IOI17_train) C++14
100 / 100
504 ms 1988 KB
#include <bits/stdc++.h>
#include "train.h"
/// 500 485 462 A4
using namespace std;
typedef long long int ll;
typedef complex<double> point;
typedef long double ld;
#define pb push_back
#define pii pair < ll , ll >
#define F first
#define S second
//#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
const int N=5e3+10,inf=(ll)1e15;
ll vis[N];
ll t[N];
vector <int> g[N],in[N];
ll mark[N];
std::vector<int32_t> who_wins(std::vector<int32_t> A, std::vector<int32_t> R, std::vector<int32_t> U, std::vector<int32_t> V) {
	ll n=A.size(),m=U.size();
    for (int i=0;i<n;i++){
        g[i].clear();
        in[i].clear();
        vis[i]=0;
    }
	for (int i=0;i<U.size();i++){
        g[U[i]].pb(V[i]);
        in[V[i]].pb(U[i]);
	}
	ll cnt=0;
	while(true){
        queue <int> q;
        for (int i=0;i<n;i++){
            t[i]=g[i].size();
            mark[i]=0;
            if (vis[i]==0 && R[i]==1){
                q.push(i);
                t[i]=0;
            }
        }
        while(q.size()){
            ll v=q.front();
            if (mark[v]) cout << 1/0 << endl;
            mark[v]=1;
            t[v]=0;
            q.pop();
            for (auto u : in[v]){
              //  cout << u << " " << v << " " << A[u] << " " << t[u] << endl;
                if (A[u]==1 && t[u]!=0){
                    t[u]=0;
                    q.push(u);
                }
                else if (t[u]!=0){
                    t[u]--;
                    if (t[u]==0) q.push(u);
                }
            }
        }
        ll p1=0;
        for (int i=0;i<n;i++){
            if (vis[i] || R[i]==0) continue;
            ll p2=0;
            ll p3=0;
            for (auto u : g[i]){
                if (t[u]==0) p2=1;
                else p3=1;
            }
            if (p2==0 || (A[i]==0 && p3==1)){
                p1=1;
                vis[i]=1;
            }
        }
        if (p1==0) break;
	}
	ll p1=0;
	for (int i=0;i<n;i++){
        if (vis[i]==0 && R[i]==1) p1=1;
	}
	vector <int32_t> ans;
	for (int i=0;i<n;i++){
        if (p1==0) ans.pb(0);
        else {
            if (t[i]==0) ans.pb(1);
            else ans.pb(0);
        }
	}
	return ans;
}
/*
int32_t main() {
	int n, m;
	assert(2 == scanf("%d %d", &n, &m));

	vector<int32_t> 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<int32_t> 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;
}
*/
/*
15 40
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 1 0 0 0 0 1 0 0 0 1 0 0 1 0
10 7
1 13
3 1
7 6
14 8
2 7
4 11
6 7
5 13
6 13
4 0
3 7
4 12
5 11
2 8
3 9
0 6
8 9
3 0
2 0
13 6
8 13
9 7
5 10
12 12
14 11
2 10
1 0
2 9
10 14
9 0
11 13
5 6
14 5
14 10
7 13
10 4
11 1
0 1
2 3
*/
/*
10 7
14 8
2 7
4 11
4 0
3 7
4 12
5 11
2 8
3 9
8 9
3 0
2 0
9 7
12 12
14 11
2 9
9 0
14 5
2 3
*/

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:29:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i=0;i<U.size();i++){
      |               ~^~~~~~~~~
train.cpp:46:35: warning: division by zero [-Wdiv-by-zero]
   46 |             if (mark[v]) cout << 1/0 << endl;
      |                                  ~^~
train.cpp:23:16: warning: unused variable 'm' [-Wunused-variable]
   23 |  ll n=A.size(),m=U.size();
      |                ^
train.cpp:33:5: warning: unused variable 'cnt' [-Wunused-variable]
   33 |  ll cnt=0;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1228 KB Output is correct
2 Correct 8 ms 1228 KB Output is correct
3 Correct 8 ms 1196 KB Output is correct
4 Correct 8 ms 1196 KB Output is correct
5 Correct 8 ms 1228 KB Output is correct
6 Correct 8 ms 1248 KB Output is correct
7 Correct 7 ms 1228 KB Output is correct
8 Correct 7 ms 1224 KB Output is correct
9 Correct 6 ms 1228 KB Output is correct
10 Correct 6 ms 1228 KB Output is correct
11 Correct 4 ms 1232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 516 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 536 KB Output is correct
6 Correct 1 ms 540 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 1872 KB Output is correct
2 Correct 142 ms 1868 KB Output is correct
3 Correct 204 ms 1880 KB Output is correct
4 Correct 10 ms 1872 KB Output is correct
5 Correct 15 ms 1696 KB Output is correct
6 Correct 10 ms 1692 KB Output is correct
7 Correct 12 ms 1624 KB Output is correct
8 Correct 8 ms 1616 KB Output is correct
9 Correct 8 ms 1612 KB Output is correct
10 Correct 8 ms 1636 KB Output is correct
11 Correct 8 ms 1612 KB Output is correct
12 Correct 11 ms 1484 KB Output is correct
13 Correct 12 ms 1732 KB Output is correct
14 Correct 11 ms 1884 KB Output is correct
15 Correct 9 ms 1740 KB Output is correct
16 Correct 9 ms 1740 KB Output is correct
17 Correct 9 ms 1740 KB Output is correct
18 Correct 310 ms 1200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1612 KB Output is correct
2 Correct 8 ms 1740 KB Output is correct
3 Correct 9 ms 1868 KB Output is correct
4 Correct 10 ms 1868 KB Output is correct
5 Correct 12 ms 1892 KB Output is correct
6 Correct 13 ms 1820 KB Output is correct
7 Correct 11 ms 1740 KB Output is correct
8 Correct 10 ms 1736 KB Output is correct
9 Correct 11 ms 1740 KB Output is correct
10 Correct 10 ms 1968 KB Output is correct
11 Correct 10 ms 1908 KB Output is correct
12 Correct 9 ms 1868 KB Output is correct
13 Correct 9 ms 1868 KB Output is correct
14 Correct 9 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 1868 KB Output is correct
2 Correct 9 ms 1740 KB Output is correct
3 Correct 9 ms 1676 KB Output is correct
4 Correct 8 ms 1612 KB Output is correct
5 Correct 1 ms 588 KB Output is correct
6 Correct 6 ms 1140 KB Output is correct
7 Correct 5 ms 1356 KB Output is correct
8 Correct 6 ms 1356 KB Output is correct
9 Correct 6 ms 1356 KB Output is correct
10 Correct 2 ms 716 KB Output is correct
11 Correct 5 ms 1180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 1228 KB Output is correct
2 Correct 8 ms 1228 KB Output is correct
3 Correct 8 ms 1196 KB Output is correct
4 Correct 8 ms 1196 KB Output is correct
5 Correct 8 ms 1228 KB Output is correct
6 Correct 8 ms 1248 KB Output is correct
7 Correct 7 ms 1228 KB Output is correct
8 Correct 7 ms 1224 KB Output is correct
9 Correct 6 ms 1228 KB Output is correct
10 Correct 6 ms 1228 KB Output is correct
11 Correct 4 ms 1232 KB Output is correct
12 Correct 1 ms 460 KB Output is correct
13 Correct 1 ms 516 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 460 KB Output is correct
16 Correct 1 ms 536 KB Output is correct
17 Correct 1 ms 540 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 460 KB Output is correct
21 Correct 1 ms 460 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 1 ms 460 KB Output is correct
24 Correct 1 ms 460 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 460 KB Output is correct
27 Correct 1 ms 460 KB Output is correct
28 Correct 1 ms 460 KB Output is correct
29 Correct 1 ms 460 KB Output is correct
30 Correct 1 ms 460 KB Output is correct
31 Correct 1 ms 460 KB Output is correct
32 Correct 76 ms 1872 KB Output is correct
33 Correct 142 ms 1868 KB Output is correct
34 Correct 204 ms 1880 KB Output is correct
35 Correct 10 ms 1872 KB Output is correct
36 Correct 15 ms 1696 KB Output is correct
37 Correct 10 ms 1692 KB Output is correct
38 Correct 12 ms 1624 KB Output is correct
39 Correct 8 ms 1616 KB Output is correct
40 Correct 8 ms 1612 KB Output is correct
41 Correct 8 ms 1636 KB Output is correct
42 Correct 8 ms 1612 KB Output is correct
43 Correct 11 ms 1484 KB Output is correct
44 Correct 12 ms 1732 KB Output is correct
45 Correct 11 ms 1884 KB Output is correct
46 Correct 9 ms 1740 KB Output is correct
47 Correct 9 ms 1740 KB Output is correct
48 Correct 9 ms 1740 KB Output is correct
49 Correct 310 ms 1200 KB Output is correct
50 Correct 8 ms 1612 KB Output is correct
51 Correct 8 ms 1740 KB Output is correct
52 Correct 9 ms 1868 KB Output is correct
53 Correct 10 ms 1868 KB Output is correct
54 Correct 12 ms 1892 KB Output is correct
55 Correct 13 ms 1820 KB Output is correct
56 Correct 11 ms 1740 KB Output is correct
57 Correct 10 ms 1736 KB Output is correct
58 Correct 11 ms 1740 KB Output is correct
59 Correct 10 ms 1968 KB Output is correct
60 Correct 10 ms 1908 KB Output is correct
61 Correct 9 ms 1868 KB Output is correct
62 Correct 9 ms 1868 KB Output is correct
63 Correct 9 ms 1740 KB Output is correct
64 Correct 12 ms 1868 KB Output is correct
65 Correct 9 ms 1740 KB Output is correct
66 Correct 9 ms 1676 KB Output is correct
67 Correct 8 ms 1612 KB Output is correct
68 Correct 1 ms 588 KB Output is correct
69 Correct 6 ms 1140 KB Output is correct
70 Correct 5 ms 1356 KB Output is correct
71 Correct 6 ms 1356 KB Output is correct
72 Correct 6 ms 1356 KB Output is correct
73 Correct 2 ms 716 KB Output is correct
74 Correct 5 ms 1180 KB Output is correct
75 Correct 114 ms 1824 KB Output is correct
76 Correct 164 ms 1876 KB Output is correct
77 Correct 230 ms 1864 KB Output is correct
78 Correct 227 ms 1892 KB Output is correct
79 Correct 253 ms 1868 KB Output is correct
80 Correct 10 ms 1868 KB Output is correct
81 Correct 10 ms 1868 KB Output is correct
82 Correct 10 ms 1868 KB Output is correct
83 Correct 12 ms 1868 KB Output is correct
84 Correct 12 ms 1964 KB Output is correct
85 Correct 10 ms 1840 KB Output is correct
86 Correct 12 ms 1868 KB Output is correct
87 Correct 9 ms 1868 KB Output is correct
88 Correct 16 ms 1900 KB Output is correct
89 Correct 10 ms 1868 KB Output is correct
90 Correct 20 ms 1892 KB Output is correct
91 Correct 26 ms 1868 KB Output is correct
92 Correct 38 ms 1988 KB Output is correct
93 Correct 40 ms 1868 KB Output is correct
94 Correct 33 ms 1868 KB Output is correct
95 Correct 36 ms 1900 KB Output is correct
96 Correct 76 ms 1764 KB Output is correct
97 Correct 273 ms 1912 KB Output is correct
98 Correct 460 ms 1896 KB Output is correct
99 Correct 504 ms 1876 KB Output is correct
100 Correct 309 ms 1316 KB Output is correct