답안 #1114309

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1114309 2024-11-18T13:57:50 Z n3rm1n Amusement Park (CEOI19_amusementpark) C++17
19 / 100
181 ms 13680 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 12, MAXM = 200;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int n, m;
int from[MAXM], to[MAXM];
void read()
{
    cin >> n >> m;
    for (int i = 1; i <= m; ++ i)
        cin >> from[i] >> to[i];
}
int order[MAXN], used[MAXN], visited[MAXN], in_cycle[MAXN]; /// na koq poziciq e i
int ans = 0, imp = 0;
const int mod = 998244353;
unordered_set < long long > mp;
vector < int > g[MAXN];
void dfs(int beg)
{
    if(imp)return;
    visited[beg] = 1;
    in_cycle[beg] = 1;
    for (auto nb: g[beg])
    {
        if(imp)return;
        if(!visited[nb])dfs(nb);
        else if(in_cycle[nb])imp = 1;
    }
    in_cycle[beg] = 0;
}

void check()
{
    int cnt = 0;
    long long curr = 0;
    for (int i = 1; i <= m; ++ i)
    {
        if(order[from[i]] > order[to[i]])
            curr = curr;
        else
            curr = curr + (1 << (i-1));
    }
    if(mp.find(curr) != mp.end())return;
    mp.insert(curr);
    for (int i = 1; i <= n; ++ i)
    {
        g[i].clear();
        visited[i] = 0;
        in_cycle[i] = 0;
    }
    for (int i = 1; i <= m; ++ i)
    {
        if(order[from[i]] > order[to[i]])g[from[i]].push_back(to[i]);
        else
        {
            cnt ++;
            g[to[i]].push_back(from[i]);
        }
    }
    imp = 0;
    for (int i = 1; i <= n && (!imp); ++ i)
    {
        if(visited[order[i]])continue;
        dfs(visited[order[i]]);
    }
    if(imp)return;
    ans += cnt;
}
void gen(int pos)
{
    if(pos > n)
    {
        check();
        return;
    }
    for (int i = 1; i <= n; ++ i)
    {
        if(used[i])continue;
        order[pos] = i;
        used[i] = 1;
        gen(pos+1);
        used[i] = 0;
    }
}
int main()
{
    speed();
    read();
    gen(1);
    cout << ans << endl;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 3 ms 592 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 4 ms 468 KB Output is correct
35 Correct 7 ms 592 KB Output is correct
36 Correct 7 ms 848 KB Output is correct
37 Correct 12 ms 1616 KB Output is correct
38 Correct 16 ms 1964 KB Output is correct
39 Correct 13 ms 336 KB Output is correct
40 Correct 17 ms 336 KB Output is correct
41 Correct 24 ms 336 KB Output is correct
42 Correct 34 ms 648 KB Output is correct
43 Correct 50 ms 1452 KB Output is correct
44 Correct 53 ms 2724 KB Output is correct
45 Correct 82 ms 5320 KB Output is correct
46 Correct 153 ms 10100 KB Output is correct
47 Incorrect 181 ms 13680 KB Output isn't correct
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 3 ms 592 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 4 ms 468 KB Output is correct
35 Correct 7 ms 592 KB Output is correct
36 Correct 7 ms 848 KB Output is correct
37 Correct 12 ms 1616 KB Output is correct
38 Correct 16 ms 1964 KB Output is correct
39 Correct 13 ms 336 KB Output is correct
40 Correct 17 ms 336 KB Output is correct
41 Correct 24 ms 336 KB Output is correct
42 Correct 34 ms 648 KB Output is correct
43 Correct 50 ms 1452 KB Output is correct
44 Correct 53 ms 2724 KB Output is correct
45 Correct 82 ms 5320 KB Output is correct
46 Correct 153 ms 10100 KB Output is correct
47 Incorrect 181 ms 13680 KB Output isn't correct
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 464 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 464 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 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 504 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 504 KB Output is correct
29 Correct 2 ms 336 KB Output is correct
30 Correct 2 ms 592 KB Output is correct
31 Correct 3 ms 592 KB Output is correct
32 Correct 3 ms 336 KB Output is correct
33 Correct 3 ms 336 KB Output is correct
34 Correct 4 ms 468 KB Output is correct
35 Correct 7 ms 592 KB Output is correct
36 Correct 7 ms 848 KB Output is correct
37 Correct 12 ms 1616 KB Output is correct
38 Correct 16 ms 1964 KB Output is correct
39 Correct 13 ms 336 KB Output is correct
40 Correct 17 ms 336 KB Output is correct
41 Correct 24 ms 336 KB Output is correct
42 Correct 34 ms 648 KB Output is correct
43 Correct 50 ms 1452 KB Output is correct
44 Correct 53 ms 2724 KB Output is correct
45 Correct 82 ms 5320 KB Output is correct
46 Correct 153 ms 10100 KB Output is correct
47 Incorrect 181 ms 13680 KB Output isn't correct
48 Halted 0 ms 0 KB -