Submission #1062561

# Submission time Handle Problem Language Result Execution time Memory
1062561 2024-08-17T08:36:20 Z j_vdd16 Keys (IOI21_keys) C++17
37 / 100
3000 ms 26236 KB
#include "keys.h"

#include <algorithm>
#include <bitset>
#include <cstdint>
#include <cstring>
#include <iostream>
#include <limits.h>
#include <math.h>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

//#define int long long
#define loop(X, N) for(int X = 0; X < (N); X++)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;

int n, m;
vvii adj;
vi succ;

vi find_reachable(vi r, vi u, vi v, vi c) {
	//std::vector<int> ans(r.size(), 1);

    n = r.size();
    adj = vvii(n);
    succ = vi(n);

    m = u.size();
    loop(i, m) {
        adj[u[i]].push_back({v[i], c[i]});
        adj[v[i]].push_back({u[i], c[i]});
    }

    // vi ans;
    // loop(i, n) {
    //     int key = r[i];
    //     int next = -1;
    //     for (auto [room, lock] : adj[i]) {
    //         if (lock == key)
    //             next = room;
    //     }

    //     if (next == -1)
    //         ans.push_back(i);
    //     else
    //         succ[i] = next;
    // }

    // if (ans.size())
    //     return ans;

    int minCount = n;
    vi ans;

    loop(i, n) {
        set<int> keys;

        map<int, vi> todo;
        vb vis(n);
        stack<int> s;
        s.push(i);

        int count = 0;
        while (s.size()) {
            int node = s.top();
            s.pop();

            if (vis[node]) 
                continue;
            
            count++;
            vis[node] = true;

            int key = r[node];
            if (keys.count(key) == 0) {
                keys.insert(key);
                for (int x : todo[key])
                    s.push(x);
            }

            for (auto [child, lock] : adj[node]) {
                if (keys.count(lock)) {
                    s.push(child);
                }
                else {
                    todo[lock].push_back(child);
                }
            }
        }

        if (count < minCount) {
            minCount = count;
            ans = { i };
        }
        else if (count == minCount) {
            ans.push_back(i);
        }
    }

    vi res(n);
    for (int x : ans)
        res[x] = 1;

	return res;
}

Compilation message

keys.cpp: In function 'vi find_reachable(vi, vi, vi, vi)':
keys.cpp:117:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  117 |     for (int x : ans)
      |     ^~~
keys.cpp:120:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  120 |  return res;
      |  ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 7 ms 348 KB Output is correct
24 Correct 6 ms 348 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 10 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 7 ms 348 KB Output is correct
24 Correct 6 ms 348 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 10 ms 348 KB Output is correct
27 Correct 421 ms 860 KB Output is correct
28 Correct 432 ms 856 KB Output is correct
29 Correct 421 ms 936 KB Output is correct
30 Correct 222 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 444 KB Output is correct
34 Correct 93 ms 604 KB Output is correct
35 Correct 215 ms 604 KB Output is correct
36 Correct 960 ms 600 KB Output is correct
37 Correct 994 ms 744 KB Output is correct
38 Correct 1400 ms 1120 KB Output is correct
39 Correct 1408 ms 856 KB Output is correct
40 Correct 17 ms 348 KB Output is correct
41 Correct 128 ms 608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Execution timed out 3004 ms 26236 KB Time limit exceeded
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 5 ms 348 KB Output is correct
11 Correct 3 ms 480 KB Output is correct
12 Correct 3 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 5 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 0 ms 432 KB Output is correct
21 Correct 4 ms 348 KB Output is correct
22 Correct 2 ms 344 KB Output is correct
23 Correct 7 ms 348 KB Output is correct
24 Correct 6 ms 348 KB Output is correct
25 Correct 10 ms 344 KB Output is correct
26 Correct 10 ms 348 KB Output is correct
27 Correct 421 ms 860 KB Output is correct
28 Correct 432 ms 856 KB Output is correct
29 Correct 421 ms 936 KB Output is correct
30 Correct 222 ms 604 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 444 KB Output is correct
34 Correct 93 ms 604 KB Output is correct
35 Correct 215 ms 604 KB Output is correct
36 Correct 960 ms 600 KB Output is correct
37 Correct 994 ms 744 KB Output is correct
38 Correct 1400 ms 1120 KB Output is correct
39 Correct 1408 ms 856 KB Output is correct
40 Correct 17 ms 348 KB Output is correct
41 Correct 128 ms 608 KB Output is correct
42 Execution timed out 3004 ms 26236 KB Time limit exceeded
43 Halted 0 ms 0 KB -