Submission #864497

#TimeUsernameProblemLanguageResultExecution timeMemory
864497RequiemAmusement Park (CEOI19_amusementpark)C++17
0 / 100
0 ms500 KiB
#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[edge[i].fi].pb(edge[i].se); degree[edge[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<int,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[11]; before.resize(n+1); now.resize(n+1); iota(permutation+1,permutation+1+n,1); do{ for(int i=1;i<=n;i++){ pos[permutation[i]] = i; } // for(int i=1;i<=n;i++){ // cout<<permutation[i]<<' '; // } // cout<<endl; int cost = 0; for(int i=1;i<=m;i++){ tmp[i] = edge[i]; } int code = 0; for(int i=1;i<=m;i++){ if (pos[tmp[i].fi] > pos[tmp[i].se]) { cost++; swap(tmp[i].fi,tmp[i].se); code = (code * base + 2) % MOD; } else code = (code * base + 1)%MOD; } // cout<<cost<<endl; if (hashcode[code] == 0 and check()){ ans = (ans + cost) % MOD; hashcode[code]=1; } }while(next_permutation(permutation+1,permutation+1+n)); cout<<ans<<endl; }

Compilation message (stderr)

amusementpark.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main()
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...