Submission #1115868

# Submission time Handle Problem Language Result Execution time Memory
1115868 2024-11-21T02:58:57 Z Thanhs Political Development (BOI17_politicaldevelopment) C++17
100 / 100
1470 ms 306760 KB
#include <bits/stdc++.h>
using namespace std;

#define name "TENBAI"
#define fi first
#define se second
#define int long long
#define endl '\n'
#define setmin(x, y) x = min((x), (y))
#define setmax(x, y) x = max((x), (y))
#define sqr(x) ((x) * (x))

mt19937 hdp(chrono::high_resolution_clock::now().time_since_epoch().count());
int rand(int l, int r){return l + ((hdp() % (r - l + 1)) + r - l + 1) % (r - l + 1);}

const int NM = 5e4 + 5;

int ans = 1, n, k;
bitset<NM> g[NM];

void dfs(int sz, const bitset<NM>& bs)
{
    setmax(ans, sz);
    for (int i = bs._Find_first(); i < n; i = bs._Find_next(i))
        dfs(sz + 1, bs & g[i]);
}

void sub1()
{
    vector<vector<int>> v;
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        while (t--)
        {
            int x;
            cin >> x;
            g[i][x] = 1;
        }
        for (int k = v.size(), j = 0; j < k; j++)
        {
            bool sus = 0;
            for (int x : v[j])
                if (!g[i][x])
                {
                    sus = 1;
                    break;
                }
            if (!sus)
            {
                v.push_back(v[j]);
                v.back().push_back(i);
                setmax(ans, (int)v.back().size());
            }
        }
        v.push_back(vector<int>(1, i));
    }
    cout << ans;
}

void sub2()
{
    for (int i = 0; i < n; i++)
    {
        int t;
        cin >> t;
        while (t--)
        {
            int x;
            cin >> x;
            g[i][x] = 1;
        }
    }
    for (int i = 0; i < n; i++)
        dfs(1, g[i]);
    cout << ans;
}

void solve()
{
    cin >> n >> k;
    if (n <= 5000)
        sub1();
    else
        sub2();
}

signed main()
{
    if (fopen("in.txt", "r")) 
    {
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    }
    else if (fopen(name".inp", "r"))
    {
        freopen(name".inp", "r", stdin);
        freopen(name".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int tc = 1; 
    // cin >> tc;
    while (tc--)
        solve();
}

Compilation message

politicaldevelopment.cpp: In function 'int main()':
politicaldevelopment.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen("in.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
politicaldevelopment.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen("out.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
politicaldevelopment.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   98 |         freopen(name".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
politicaldevelopment.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   99 |         freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 35 ms 31820 KB Output is correct
4 Correct 43 ms 31880 KB Output is correct
5 Correct 41 ms 31888 KB Output is correct
6 Correct 35 ms 31876 KB Output is correct
7 Correct 34 ms 31876 KB Output is correct
8 Correct 19 ms 848 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 20 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 35 ms 31820 KB Output is correct
4 Correct 43 ms 31880 KB Output is correct
5 Correct 41 ms 31888 KB Output is correct
6 Correct 35 ms 31876 KB Output is correct
7 Correct 34 ms 31876 KB Output is correct
8 Correct 19 ms 848 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 20 ms 848 KB Output is correct
11 Correct 44 ms 31876 KB Output is correct
12 Correct 48 ms 31880 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 35 ms 31900 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 36 ms 31884 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 37 ms 31876 KB Output is correct
19 Correct 21 ms 848 KB Output is correct
20 Correct 31 ms 31560 KB Output is correct
21 Correct 30 ms 31560 KB Output is correct
22 Correct 22 ms 848 KB Output is correct
23 Correct 41 ms 31876 KB Output is correct
24 Correct 29 ms 848 KB Output is correct
25 Correct 40 ms 31796 KB Output is correct
26 Correct 37 ms 31832 KB Output is correct
27 Correct 35 ms 31848 KB Output is correct
28 Correct 40 ms 31876 KB Output is correct
29 Correct 39 ms 31764 KB Output is correct
30 Correct 45 ms 31832 KB Output is correct
31 Correct 40 ms 31804 KB Output is correct
32 Correct 53 ms 31804 KB Output is correct
33 Correct 41 ms 31884 KB Output is correct
34 Correct 42 ms 31884 KB Output is correct
35 Correct 13 ms 17232 KB Output is correct
36 Correct 13 ms 17400 KB Output is correct
37 Correct 13 ms 17232 KB Output is correct
38 Correct 6 ms 8784 KB Output is correct
39 Correct 5 ms 8784 KB Output is correct
40 Correct 52 ms 32396 KB Output is correct
41 Correct 5 ms 8784 KB Output is correct
42 Correct 53 ms 32176 KB Output is correct
43 Correct 51 ms 32012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 848 KB Output is correct
2 Correct 1 ms 508 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 669 ms 306760 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1427 ms 306620 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 664 ms 306536 KB Output is correct
16 Correct 753 ms 306504 KB Output is correct
17 Correct 1470 ms 306576 KB Output is correct
18 Correct 710 ms 306568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 35 ms 31820 KB Output is correct
4 Correct 43 ms 31880 KB Output is correct
5 Correct 41 ms 31888 KB Output is correct
6 Correct 35 ms 31876 KB Output is correct
7 Correct 34 ms 31876 KB Output is correct
8 Correct 19 ms 848 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 20 ms 848 KB Output is correct
11 Correct 44 ms 31876 KB Output is correct
12 Correct 48 ms 31880 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 35 ms 31900 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 36 ms 31884 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 37 ms 31876 KB Output is correct
19 Correct 21 ms 848 KB Output is correct
20 Correct 31 ms 31560 KB Output is correct
21 Correct 30 ms 31560 KB Output is correct
22 Correct 22 ms 848 KB Output is correct
23 Correct 41 ms 31876 KB Output is correct
24 Correct 29 ms 848 KB Output is correct
25 Correct 40 ms 31796 KB Output is correct
26 Correct 37 ms 31832 KB Output is correct
27 Correct 35 ms 31848 KB Output is correct
28 Correct 40 ms 31876 KB Output is correct
29 Correct 39 ms 31764 KB Output is correct
30 Correct 45 ms 31832 KB Output is correct
31 Correct 40 ms 31804 KB Output is correct
32 Correct 53 ms 31804 KB Output is correct
33 Correct 41 ms 31884 KB Output is correct
34 Correct 42 ms 31884 KB Output is correct
35 Correct 13 ms 17232 KB Output is correct
36 Correct 13 ms 17400 KB Output is correct
37 Correct 13 ms 17232 KB Output is correct
38 Correct 6 ms 8784 KB Output is correct
39 Correct 5 ms 8784 KB Output is correct
40 Correct 52 ms 32396 KB Output is correct
41 Correct 5 ms 8784 KB Output is correct
42 Correct 53 ms 32176 KB Output is correct
43 Correct 51 ms 32012 KB Output is correct
44 Correct 540 ms 63980 KB Output is correct
45 Correct 1 ms 504 KB Output is correct
46 Correct 48 ms 32068 KB Output is correct
47 Correct 77 ms 32512 KB Output is correct
48 Correct 51 ms 31972 KB Output is correct
49 Correct 90 ms 32720 KB Output is correct
50 Correct 75 ms 32512 KB Output is correct
51 Correct 173 ms 34348 KB Output is correct
52 Correct 54 ms 31108 KB Output is correct
53 Correct 189 ms 33888 KB Output is correct
54 Correct 164 ms 34556 KB Output is correct
55 Correct 37 ms 31820 KB Output is correct
56 Correct 53 ms 31108 KB Output is correct
57 Correct 22 ms 848 KB Output is correct
58 Correct 177 ms 34076 KB Output is correct
59 Correct 81 ms 33280 KB Output is correct
60 Correct 38 ms 31888 KB Output is correct
61 Correct 124 ms 33196 KB Output is correct
62 Correct 81 ms 33292 KB Output is correct
63 Correct 551 ms 63980 KB Output is correct
64 Correct 300 ms 46836 KB Output is correct
65 Correct 48 ms 32144 KB Output is correct
66 Correct 80 ms 33288 KB Output is correct
67 Correct 205 ms 39156 KB Output is correct
68 Correct 308 ms 46592 KB Output is correct
69 Correct 49 ms 32036 KB Output is correct
70 Correct 93 ms 33204 KB Output is correct
71 Correct 230 ms 39156 KB Output is correct
72 Correct 178 ms 36044 KB Output is correct
73 Correct 37 ms 31876 KB Output is correct
74 Correct 89 ms 33280 KB Output is correct
75 Correct 159 ms 36092 KB Output is correct
76 Correct 55 ms 32256 KB Output is correct
77 Correct 102 ms 33752 KB Output is correct
78 Correct 43 ms 31772 KB Output is correct
79 Correct 30 ms 18052 KB Output is correct
80 Correct 77 ms 32272 KB Output is correct
81 Correct 108 ms 33760 KB Output is correct
82 Correct 5 ms 8784 KB Output is correct
83 Correct 32 ms 18076 KB Output is correct
84 Correct 105 ms 32744 KB Output is correct
85 Correct 5 ms 8784 KB Output is correct
86 Correct 91 ms 32768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 35 ms 31820 KB Output is correct
4 Correct 43 ms 31880 KB Output is correct
5 Correct 41 ms 31888 KB Output is correct
6 Correct 35 ms 31876 KB Output is correct
7 Correct 34 ms 31876 KB Output is correct
8 Correct 19 ms 848 KB Output is correct
9 Correct 1 ms 508 KB Output is correct
10 Correct 20 ms 848 KB Output is correct
11 Correct 44 ms 31876 KB Output is correct
12 Correct 48 ms 31880 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 35 ms 31900 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 36 ms 31884 KB Output is correct
17 Correct 1 ms 504 KB Output is correct
18 Correct 37 ms 31876 KB Output is correct
19 Correct 21 ms 848 KB Output is correct
20 Correct 31 ms 31560 KB Output is correct
21 Correct 30 ms 31560 KB Output is correct
22 Correct 22 ms 848 KB Output is correct
23 Correct 41 ms 31876 KB Output is correct
24 Correct 29 ms 848 KB Output is correct
25 Correct 40 ms 31796 KB Output is correct
26 Correct 37 ms 31832 KB Output is correct
27 Correct 35 ms 31848 KB Output is correct
28 Correct 40 ms 31876 KB Output is correct
29 Correct 39 ms 31764 KB Output is correct
30 Correct 45 ms 31832 KB Output is correct
31 Correct 40 ms 31804 KB Output is correct
32 Correct 53 ms 31804 KB Output is correct
33 Correct 41 ms 31884 KB Output is correct
34 Correct 42 ms 31884 KB Output is correct
35 Correct 13 ms 17232 KB Output is correct
36 Correct 13 ms 17400 KB Output is correct
37 Correct 13 ms 17232 KB Output is correct
38 Correct 6 ms 8784 KB Output is correct
39 Correct 5 ms 8784 KB Output is correct
40 Correct 52 ms 32396 KB Output is correct
41 Correct 5 ms 8784 KB Output is correct
42 Correct 53 ms 32176 KB Output is correct
43 Correct 51 ms 32012 KB Output is correct
44 Correct 1 ms 336 KB Output is correct
45 Correct 552 ms 305316 KB Output is correct
46 Correct 342 ms 302664 KB Output is correct
47 Correct 515 ms 305676 KB Output is correct
48 Correct 462 ms 305736 KB Output is correct
49 Correct 163 ms 294216 KB Output is correct
50 Correct 462 ms 306532 KB Output is correct
51 Correct 448 ms 305736 KB Output is correct
52 Correct 172 ms 300880 KB Output is correct
53 Correct 165 ms 289924 KB Output is correct
54 Correct 29 ms 848 KB Output is correct
55 Correct 515 ms 306536 KB Output is correct
56 Correct 151 ms 278344 KB Output is correct
57 Correct 210 ms 277844 KB Output is correct
58 Correct 782 ms 301900 KB Output is correct
59 Correct 155 ms 273480 KB Output is correct
60 Correct 162 ms 276776 KB Output is correct
61 Correct 835 ms 301380 KB Output is correct
62 Correct 346 ms 293704 KB Output is correct
63 Correct 349 ms 301128 KB Output is correct
64 Correct 153 ms 279880 KB Output is correct
65 Correct 491 ms 305868 KB Output is correct
66 Correct 278 ms 305148 KB Output is correct
67 Correct 323 ms 305728 KB Output is correct
68 Correct 375 ms 306156 KB Output is correct
69 Correct 488 ms 305480 KB Output is correct
70 Correct 213 ms 301664 KB Output is correct
71 Correct 362 ms 304756 KB Output is correct
72 Correct 272 ms 302332 KB Output is correct
73 Correct 433 ms 306004 KB Output is correct
74 Correct 213 ms 299340 KB Output is correct
75 Correct 152 ms 154464 KB Output is correct
76 Correct 292 ms 300700 KB Output is correct
77 Correct 401 ms 305860 KB Output is correct
78 Correct 193 ms 154520 KB Output is correct
79 Correct 141 ms 154448 KB Output is correct
80 Correct 70 ms 78416 KB Output is correct
81 Correct 180 ms 154440 KB Output is correct
82 Correct 362 ms 303964 KB Output is correct
83 Correct 66 ms 78416 KB Output is correct
84 Correct 354 ms 304184 KB Output is correct