답안 #600542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
600542 2022-07-21T04:25:10 Z Hanksburger 늑대인간 (IOI18_werewolf) C++17
100 / 100
723 ms 158564 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> child[400005], adj1[200005], adj2[200005], ql[200005], qr[200005], ans;
int p[200005], par[400005], tin[400005], tout[400005], t;
set<int> ss[400005];
int parent(int u)
{
    return (par[u]==u)?u:(par[u]=parent(par[u]));
}
void f(int u)
{
    tin[u]=(t++);
    for (int v:child[u])
        f(v);
    tout[u]=(t++);
}
vector<int> check_validity(int n, vector<int> x, vector<int> y, vector<int> s, vector<int> e, vector<int> l, vector<int> r)
{
    for (int i=0; i<x.size(); i++)
    {
        int u=min(x[i], y[i]), v=max(x[i], y[i]);
        adj1[u].push_back(v);
        adj2[v].push_back(u);
    }
    for (int i=0; i<l.size(); i++)
    {
        ql[l[i]].push_back(i);
        qr[r[i]].push_back(i);
        ans.push_back(0);
    }
    for (int i=0; i<=n*2; i++)
        par[i]=i;
    int cnt=n;
    for (int i=n-1; i>=0; i--)
    {
        for (int j:adj1[i])
        {
            int a=parent(i), b=parent(j);
            if (a!=b)
            {
                child[cnt].push_back(a);
                child[cnt].push_back(b);
                par[a]=par[b]=(cnt++);
            }
        }
        for (int j:ql[i])
            p[j]=parent(s[j]);
    }
    f(cnt-1);
    for (int i=0; i<n; i++)
    {
        ss[i].insert(tin[i]);
        par[i]=i;
    }
    for (int i=0; i<n; i++)
    {
        for (int j:adj2[i])
        {
            int a=parent(i), b=parent(j);
            if (a!=b)
            {
                if (ss[a].size()>ss[b].size())
                    swap(a, b);
                ss[b].insert(ss[a].begin(), ss[a].end());
                par[a]=b;
            }
        }
        for (int j:qr[i])
        {
            int x=parent(e[j]);
            auto itr=ss[x].lower_bound(tin[p[j]]);
            if (itr!=ss[x].end() && (*itr)<=tout[p[j]])
                ans[j]=1;
        }
    }
    return ans;
}

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for (int i=0; i<x.size(); i++)
      |                   ~^~~~~~~~~
werewolf.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i=0; i<l.size(); i++)
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47300 KB Output is correct
2 Correct 22 ms 47316 KB Output is correct
3 Correct 22 ms 47280 KB Output is correct
4 Correct 22 ms 47300 KB Output is correct
5 Correct 22 ms 47316 KB Output is correct
6 Correct 25 ms 47280 KB Output is correct
7 Correct 26 ms 47224 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 22 ms 47296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47300 KB Output is correct
2 Correct 22 ms 47316 KB Output is correct
3 Correct 22 ms 47280 KB Output is correct
4 Correct 22 ms 47300 KB Output is correct
5 Correct 22 ms 47316 KB Output is correct
6 Correct 25 ms 47280 KB Output is correct
7 Correct 26 ms 47224 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 22 ms 47296 KB Output is correct
10 Correct 27 ms 48340 KB Output is correct
11 Correct 28 ms 48340 KB Output is correct
12 Correct 27 ms 48568 KB Output is correct
13 Correct 30 ms 48324 KB Output is correct
14 Correct 30 ms 48268 KB Output is correct
15 Correct 29 ms 48468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 723 ms 151176 KB Output is correct
2 Correct 505 ms 117592 KB Output is correct
3 Correct 541 ms 122484 KB Output is correct
4 Correct 606 ms 130528 KB Output is correct
5 Correct 593 ms 131904 KB Output is correct
6 Correct 642 ms 138212 KB Output is correct
7 Correct 664 ms 158564 KB Output is correct
8 Correct 553 ms 117584 KB Output is correct
9 Correct 486 ms 121144 KB Output is correct
10 Correct 505 ms 129252 KB Output is correct
11 Correct 474 ms 130828 KB Output is correct
12 Correct 587 ms 138828 KB Output is correct
13 Correct 507 ms 123692 KB Output is correct
14 Correct 495 ms 123656 KB Output is correct
15 Correct 519 ms 123700 KB Output is correct
16 Correct 498 ms 123764 KB Output is correct
17 Correct 719 ms 157808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 47300 KB Output is correct
2 Correct 22 ms 47316 KB Output is correct
3 Correct 22 ms 47280 KB Output is correct
4 Correct 22 ms 47300 KB Output is correct
5 Correct 22 ms 47316 KB Output is correct
6 Correct 25 ms 47280 KB Output is correct
7 Correct 26 ms 47224 KB Output is correct
8 Correct 21 ms 47316 KB Output is correct
9 Correct 22 ms 47296 KB Output is correct
10 Correct 27 ms 48340 KB Output is correct
11 Correct 28 ms 48340 KB Output is correct
12 Correct 27 ms 48568 KB Output is correct
13 Correct 30 ms 48324 KB Output is correct
14 Correct 30 ms 48268 KB Output is correct
15 Correct 29 ms 48468 KB Output is correct
16 Correct 723 ms 151176 KB Output is correct
17 Correct 505 ms 117592 KB Output is correct
18 Correct 541 ms 122484 KB Output is correct
19 Correct 606 ms 130528 KB Output is correct
20 Correct 593 ms 131904 KB Output is correct
21 Correct 642 ms 138212 KB Output is correct
22 Correct 664 ms 158564 KB Output is correct
23 Correct 553 ms 117584 KB Output is correct
24 Correct 486 ms 121144 KB Output is correct
25 Correct 505 ms 129252 KB Output is correct
26 Correct 474 ms 130828 KB Output is correct
27 Correct 587 ms 138828 KB Output is correct
28 Correct 507 ms 123692 KB Output is correct
29 Correct 495 ms 123656 KB Output is correct
30 Correct 519 ms 123700 KB Output is correct
31 Correct 498 ms 123764 KB Output is correct
32 Correct 719 ms 157808 KB Output is correct
33 Correct 650 ms 128364 KB Output is correct
34 Correct 243 ms 80664 KB Output is correct
35 Correct 630 ms 122500 KB Output is correct
36 Correct 624 ms 132084 KB Output is correct
37 Correct 666 ms 122604 KB Output is correct
38 Correct 650 ms 129144 KB Output is correct
39 Correct 624 ms 112988 KB Output is correct
40 Correct 655 ms 129524 KB Output is correct
41 Correct 603 ms 123316 KB Output is correct
42 Correct 586 ms 130544 KB Output is correct
43 Correct 706 ms 125568 KB Output is correct
44 Correct 621 ms 122944 KB Output is correct
45 Correct 540 ms 112836 KB Output is correct
46 Correct 557 ms 111992 KB Output is correct
47 Correct 513 ms 123840 KB Output is correct
48 Correct 529 ms 123712 KB Output is correct
49 Correct 563 ms 123984 KB Output is correct
50 Correct 532 ms 123764 KB Output is correct
51 Correct 646 ms 126900 KB Output is correct
52 Correct 602 ms 126932 KB Output is correct