답안 #864755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
864755 2023-10-23T14:25:59 Z Requiem Amusement Park (CEOI19_amusementpark) C++17
19 / 100
3000 ms 46156 KB
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define MOD 998244353
#define INF 1e18
#define fi first
#define se second
#define endl "\n"
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define sz(a) ((int)(a).size())
#define pi 3.14159265359
#define TASKNAME "amusepark"
template<typename T> bool maximize(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool minimize(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
using namespace std;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
const int MAXN = 3e2 + 9;
ii edge[MAXN],tmp[MAXN];
int n,m,ans=0;
int degree[MAXN];
vector<int> g[MAXN];
queue<int> q;

bool check(){
    for(int i=1;i<=n;i++){
        degree[i] = 0;
        g[i].clear();
    }
    for(int i=1;i<=m;i++){
        g[tmp[i].fi].pb(tmp[i].se);
        degree[tmp[i].se]++;
        // cout<<edge[i].fi<<' '<<edge[i].se<<endl;
    }
    int cnt = 0;
    // cout<<endl<<endl;
    for(int i=1;i<=n;i++){

        if (degree[i] == 0) q.push(i);
    }

    while(!q.empty()){
        int u = q.front();
        cnt++;
        q.pop();
        for(auto v: g[u]){
            degree[v]--;
            if (degree[v] == 0) q.push(v);
        }
    }
    return cnt == n;
}
int pos[MAXN],w[MAXN][MAXN];
vector<vector<int>> before;
vector<vector<int>> now;
map<string ,int> hashcode;
const int base = 311;
main()
{
    fast;
    // freopen(TASKNAME".inp","r",stdin);
    // freopen(TASKNAME".out","w",stdout);
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>edge[i].fi>>edge[i].se;
        w[edge[i].fi][edge[i].se] = w[edge[i].se][edge[i].fi] = 1;
        tmp[i] = edge[i];
    }
    int permutation[15];
    before.resize(n+1);
    now.resize(n+1);
    string s;
    iota(permutation+1,permutation+1+n,1);
    do{
        for(int i=1;i<=n;i++){
            pos[permutation[i]] = i;
        }
        int cost = 0;
        for(int i=1;i<=m;i++){
            tmp[i] = edge[i];
        }
        int code = 0;
        s.clear();


        for(int i=1;i<=m;i++){
            if (pos[tmp[i].fi] > pos[tmp[i].se]) {
                cost++;
                swap(tmp[i].fi,tmp[i].se);
                s = s + '1';
//                code = (code * base + 2) % MOD;
            }
            else{
                s = s + '0';
//                code = (code * base + 1)%MOD;
            }
        }
        // cout<<cost<<endl;
        if (hashcode[s] == 0 and check()){
            ans = (ans + cost) % MOD;
            hashcode[s] = 1;
        }

    }while(next_permutation(permutation+1,permutation+1+n));
    cout<<ans<<endl;


}

Compilation message

amusementpark.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main()
      | ^~~~
amusementpark.cpp: In function 'int main()':
amusementpark.cpp:85:13: warning: unused variable 'code' [-Wunused-variable]
   85 |         int code = 0;
      |             ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 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 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 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 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 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 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 356 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 5 ms 668 KB Output is correct
31 Correct 6 ms 860 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 13 ms 604 KB Output is correct
35 Correct 20 ms 856 KB Output is correct
36 Correct 33 ms 1620 KB Output is correct
37 Correct 49 ms 3408 KB Output is correct
38 Correct 69 ms 5428 KB Output is correct
39 Correct 58 ms 348 KB Output is correct
40 Correct 71 ms 348 KB Output is correct
41 Correct 106 ms 596 KB Output is correct
42 Correct 149 ms 1024 KB Output is correct
43 Correct 252 ms 3428 KB Output is correct
44 Correct 379 ms 6948 KB Output is correct
45 Correct 479 ms 15088 KB Output is correct
46 Correct 633 ms 28524 KB Output is correct
47 Correct 780 ms 46156 KB Output is correct
48 Correct 74 ms 516 KB Output is correct
49 Correct 131 ms 808 KB Output is correct
50 Correct 140 ms 708 KB Output is correct
51 Correct 137 ms 796 KB Output is correct
52 Correct 471 ms 480 KB Output is correct
53 Correct 875 ms 540 KB Output is correct
54 Correct 1277 ms 948 KB Output is correct
55 Correct 2356 ms 4004 KB Output is correct
56 Execution timed out 3037 ms 21860 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 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 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 356 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 5 ms 668 KB Output is correct
31 Correct 6 ms 860 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 13 ms 604 KB Output is correct
35 Correct 20 ms 856 KB Output is correct
36 Correct 33 ms 1620 KB Output is correct
37 Correct 49 ms 3408 KB Output is correct
38 Correct 69 ms 5428 KB Output is correct
39 Correct 58 ms 348 KB Output is correct
40 Correct 71 ms 348 KB Output is correct
41 Correct 106 ms 596 KB Output is correct
42 Correct 149 ms 1024 KB Output is correct
43 Correct 252 ms 3428 KB Output is correct
44 Correct 379 ms 6948 KB Output is correct
45 Correct 479 ms 15088 KB Output is correct
46 Correct 633 ms 28524 KB Output is correct
47 Correct 780 ms 46156 KB Output is correct
48 Correct 74 ms 516 KB Output is correct
49 Correct 131 ms 808 KB Output is correct
50 Correct 140 ms 708 KB Output is correct
51 Correct 137 ms 796 KB Output is correct
52 Correct 471 ms 480 KB Output is correct
53 Correct 875 ms 540 KB Output is correct
54 Correct 1277 ms 948 KB Output is correct
55 Correct 2356 ms 4004 KB Output is correct
56 Execution timed out 3037 ms 21860 KB Time limit exceeded
57 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 600 KB Output is correct
3 Correct 0 ms 348 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 1 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 600 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 348 KB Output is correct
28 Correct 2 ms 356 KB Output is correct
29 Correct 3 ms 604 KB Output is correct
30 Correct 5 ms 668 KB Output is correct
31 Correct 6 ms 860 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 8 ms 348 KB Output is correct
34 Correct 13 ms 604 KB Output is correct
35 Correct 20 ms 856 KB Output is correct
36 Correct 33 ms 1620 KB Output is correct
37 Correct 49 ms 3408 KB Output is correct
38 Correct 69 ms 5428 KB Output is correct
39 Correct 58 ms 348 KB Output is correct
40 Correct 71 ms 348 KB Output is correct
41 Correct 106 ms 596 KB Output is correct
42 Correct 149 ms 1024 KB Output is correct
43 Correct 252 ms 3428 KB Output is correct
44 Correct 379 ms 6948 KB Output is correct
45 Correct 479 ms 15088 KB Output is correct
46 Correct 633 ms 28524 KB Output is correct
47 Correct 780 ms 46156 KB Output is correct
48 Correct 74 ms 516 KB Output is correct
49 Correct 131 ms 808 KB Output is correct
50 Correct 140 ms 708 KB Output is correct
51 Correct 137 ms 796 KB Output is correct
52 Correct 471 ms 480 KB Output is correct
53 Correct 875 ms 540 KB Output is correct
54 Correct 1277 ms 948 KB Output is correct
55 Correct 2356 ms 4004 KB Output is correct
56 Execution timed out 3037 ms 21860 KB Time limit exceeded
57 Halted 0 ms 0 KB -