답안 #932081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932081 2024-02-23T00:24:32 Z ainta 장난감 기차 (IOI17_train) C++17
100 / 100
899 ms 2140 KB
#include <bits/stdc++.h>
using namespace std;

#define rng(i,a,b) for(int i=int(a);i<=int(b);i++)
#define rep(i,b) rng(i,0,b-1)
#define gnr(i,b,a) for(int i=int(b);i>=int(a);i--)
#define per(i,b) gnr(i,b-1,0)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#define si(x) int(x.size())
template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;
typedef long long ll;
using pii=pair<int,int>;
using vi=vc<int>;
using uint=unsigned;
using ull=unsigned long long;
using pil=pair<int,ll>;
using pli=pair<ll,int>;
using pll=pair<ll,ll>;
using t3=tuple<int,int,int>;
#define N_ 5010
int n, m, removed[N_], attr[N_], Q[N_], Deg[N_];
vi E[N_], F[N_];

auto Attr(vi T, int ck, vi &a, vi &r, vi &vis){
    int head=0,tail=0;
    rep(i,n)vis[i]=Deg[i]=0;
    auto QAdd = [&](int x){
        if(!removed[x] && !vis[x])Q[++tail] = x, vis[x]=1;
    };
    rep(i,n){
        if(removed[i])continue;
        if(T[i]){
            QAdd(i);
        }
        for(auto &x: F[i]){
            if(removed[x])continue;
            if(a[x] != ck)Deg[x]++;
        }
    }
    rep(i,n){
        if(removed[i])continue;
        if(a[i] != ck && !Deg[i])QAdd(i);
    }
    while(head < tail){
        int x = Q[++head];
        for(auto &y : F[x]){
            if(removed[y])continue;
            if(a[y] == ck)QAdd(y);
            if(a[y] != ck){
                Deg[y]--;
                if(!Deg[y])QAdd(y);
            }
        }
    }
}
extern std::vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) {
	n = a.size();
	m = u.size();
	int i, j, k;
    vi res(n), T(n);
    rep(i,m){
        E[u[i]].pb(v[i]);
        F[v[i]].pb(u[i]);
    }
    vi Attr0(n), Attr1(n);
    while(1){
        rep(i,n){
            T[i]=0;
            if(removed[i])continue;
            if(r[i])T[i]=1;
        }
        Attr(T, 1, a, r, Attr1);
        rep(i,n)if(!removed[i]) Attr1[i] = !Attr1[i];
        Attr(Attr1, 0, a, r, Attr0);
        int ck=0;
        rep(i,n){
            if(!removed[i] && Attr0[i])removed[i]=1, ck=1;
        }
        if(!ck)break;
    }
    rep(i,n)res[i] = !removed[i];
	return res;
}

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:66:6: warning: unused variable 'i' [-Wunused-variable]
   66 |  int i, j, k;
      |      ^
train.cpp:66:9: warning: unused variable 'j' [-Wunused-variable]
   66 |  int i, j, k;
      |         ^
train.cpp:66:12: warning: unused variable 'k' [-Wunused-variable]
   66 |  int i, j, k;
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1368 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 5 ms 1372 KB Output is correct
5 Correct 4 ms 1368 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 4 ms 1404 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 4 ms 1116 KB Output is correct
11 Correct 3 ms 1368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 0 ms 604 KB Output is correct
3 Correct 0 ms 684 KB Output is correct
4 Correct 0 ms 600 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 0 ms 604 KB Output is correct
9 Correct 0 ms 684 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 0 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 0 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 2136 KB Output is correct
2 Correct 239 ms 1880 KB Output is correct
3 Correct 330 ms 1856 KB Output is correct
4 Correct 6 ms 1624 KB Output is correct
5 Correct 7 ms 1628 KB Output is correct
6 Correct 7 ms 1716 KB Output is correct
7 Correct 6 ms 1628 KB Output is correct
8 Correct 6 ms 1628 KB Output is correct
9 Correct 5 ms 1628 KB Output is correct
10 Correct 6 ms 1776 KB Output is correct
11 Correct 6 ms 1624 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 6 ms 1628 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 1624 KB Output is correct
17 Correct 6 ms 1628 KB Output is correct
18 Correct 420 ms 1476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1640 KB Output is correct
2 Correct 6 ms 1636 KB Output is correct
3 Correct 6 ms 1628 KB Output is correct
4 Correct 6 ms 1628 KB Output is correct
5 Correct 6 ms 1628 KB Output is correct
6 Correct 6 ms 1716 KB Output is correct
7 Correct 6 ms 1624 KB Output is correct
8 Correct 6 ms 1628 KB Output is correct
9 Correct 6 ms 1628 KB Output is correct
10 Correct 6 ms 1628 KB Output is correct
11 Correct 6 ms 1628 KB Output is correct
12 Correct 6 ms 1828 KB Output is correct
13 Correct 6 ms 1628 KB Output is correct
14 Correct 6 ms 1624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1624 KB Output is correct
2 Correct 6 ms 1876 KB Output is correct
3 Correct 7 ms 1628 KB Output is correct
4 Correct 6 ms 1628 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 3 ms 1372 KB Output is correct
7 Correct 4 ms 1372 KB Output is correct
8 Correct 5 ms 1452 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 1 ms 856 KB Output is correct
11 Correct 4 ms 1208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 1368 KB Output is correct
2 Correct 5 ms 1372 KB Output is correct
3 Correct 5 ms 1372 KB Output is correct
4 Correct 5 ms 1372 KB Output is correct
5 Correct 4 ms 1368 KB Output is correct
6 Correct 4 ms 1372 KB Output is correct
7 Correct 3 ms 1372 KB Output is correct
8 Correct 4 ms 1404 KB Output is correct
9 Correct 4 ms 1372 KB Output is correct
10 Correct 4 ms 1116 KB Output is correct
11 Correct 3 ms 1368 KB Output is correct
12 Correct 1 ms 600 KB Output is correct
13 Correct 0 ms 604 KB Output is correct
14 Correct 0 ms 684 KB Output is correct
15 Correct 0 ms 600 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 0 ms 604 KB Output is correct
20 Correct 0 ms 684 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 0 ms 600 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 0 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 0 ms 604 KB Output is correct
28 Correct 0 ms 604 KB Output is correct
29 Correct 0 ms 604 KB Output is correct
30 Correct 1 ms 604 KB Output is correct
31 Correct 0 ms 604 KB Output is correct
32 Correct 107 ms 2136 KB Output is correct
33 Correct 239 ms 1880 KB Output is correct
34 Correct 330 ms 1856 KB Output is correct
35 Correct 6 ms 1624 KB Output is correct
36 Correct 7 ms 1628 KB Output is correct
37 Correct 7 ms 1716 KB Output is correct
38 Correct 6 ms 1628 KB Output is correct
39 Correct 6 ms 1628 KB Output is correct
40 Correct 5 ms 1628 KB Output is correct
41 Correct 6 ms 1776 KB Output is correct
42 Correct 6 ms 1624 KB Output is correct
43 Correct 7 ms 1628 KB Output is correct
44 Correct 6 ms 1628 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 1624 KB Output is correct
48 Correct 6 ms 1628 KB Output is correct
49 Correct 420 ms 1476 KB Output is correct
50 Correct 5 ms 1640 KB Output is correct
51 Correct 6 ms 1636 KB Output is correct
52 Correct 6 ms 1628 KB Output is correct
53 Correct 6 ms 1628 KB Output is correct
54 Correct 6 ms 1628 KB Output is correct
55 Correct 6 ms 1716 KB Output is correct
56 Correct 6 ms 1624 KB Output is correct
57 Correct 6 ms 1628 KB Output is correct
58 Correct 6 ms 1628 KB Output is correct
59 Correct 6 ms 1628 KB Output is correct
60 Correct 6 ms 1628 KB Output is correct
61 Correct 6 ms 1828 KB Output is correct
62 Correct 6 ms 1628 KB Output is correct
63 Correct 6 ms 1624 KB Output is correct
64 Correct 7 ms 1624 KB Output is correct
65 Correct 6 ms 1876 KB Output is correct
66 Correct 7 ms 1628 KB Output is correct
67 Correct 6 ms 1628 KB Output is correct
68 Correct 1 ms 600 KB Output is correct
69 Correct 3 ms 1372 KB Output is correct
70 Correct 4 ms 1372 KB Output is correct
71 Correct 5 ms 1452 KB Output is correct
72 Correct 4 ms 1372 KB Output is correct
73 Correct 1 ms 856 KB Output is correct
74 Correct 4 ms 1208 KB Output is correct
75 Correct 126 ms 1820 KB Output is correct
76 Correct 295 ms 1884 KB Output is correct
77 Correct 400 ms 2080 KB Output is correct
78 Correct 407 ms 1872 KB Output is correct
79 Correct 402 ms 1880 KB Output is correct
80 Correct 9 ms 1856 KB Output is correct
81 Correct 8 ms 1760 KB Output is correct
82 Correct 8 ms 1852 KB Output is correct
83 Correct 7 ms 1756 KB Output is correct
84 Correct 8 ms 2140 KB Output is correct
85 Correct 7 ms 1628 KB Output is correct
86 Correct 8 ms 2060 KB Output is correct
87 Correct 6 ms 1628 KB Output is correct
88 Correct 11 ms 1628 KB Output is correct
89 Correct 7 ms 1628 KB Output is correct
90 Correct 17 ms 1856 KB Output is correct
91 Correct 13 ms 1628 KB Output is correct
92 Correct 29 ms 1628 KB Output is correct
93 Correct 29 ms 1824 KB Output is correct
94 Correct 31 ms 1628 KB Output is correct
95 Correct 34 ms 1628 KB Output is correct
96 Correct 100 ms 1628 KB Output is correct
97 Correct 426 ms 1628 KB Output is correct
98 Correct 843 ms 2016 KB Output is correct
99 Correct 899 ms 1944 KB Output is correct
100 Correct 415 ms 1372 KB Output is correct