Submission #579400

#TimeUsernameProblemLanguageResultExecution timeMemory
579400amunduzbaevAmusement Park (CEOI19_amusementpark)C++17
42 / 100
3077 ms98996 KiB
#include "bits/stdc++.h" using namespace std; #define ar array typedef int64_t ll; //~ #define int ll const int N = 20; const int P = 487; const int mod = 119 << 23 | 1; const int P2 = 167; const int mod2 = 1e9 + 9; vector<int> edges[N], qwe[N]; int used[N], is[N][N], cur[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int n, m; cin>>n>>m; vector<ar<int, 2>> e(m); for(int i=0;i<m;i++){ cin>>e[i][0]>>e[i][1]; edges[e[i][0]].push_back(e[i][1]); edges[e[i][1]].push_back(e[i][0]); is[e[i][0]][e[i][1]] = 1; } for(int i=1;i<=n;i++) sort(edges[i].begin(), edges[i].end()); vector<int> p(n); iota(p.begin(), p.end(), 1); int res = 0; vector<ar<int, 3>> tot; do{ memset(used, 0, sizeof used); int cnt = 0; for(auto u : p){ cur[u] = 0; qwe[u].clear(); for(auto x : edges[u]){ if(used[x]) continue; qwe[u].push_back(x); cur[u] |= (1 << x); if(!is[u][x]) cnt++; } used[u] = 1; } int hh = 0; for(int i=1;i<=n;i++){ hh = (hh * 1ll * P + cur[i]) % mod; } int h2 = 0; for(int i=1;i<=n;i++){ h2 = (h2 * 1ll * P2 + cur[i]) % mod2; } tot.push_back({hh, h2, cnt}); //~ if(!ss.count({hh, h2})){ //~ ss.insert({hh, h2}); //~ res = (res + cnt) % mod; //~ } }while(next_permutation(p.begin(), p.end())); sort(tot.begin(), tot.end()); for(int i=0;i<(int)tot.size();i++){ if(!i || tot[i] != tot[i-1]){ res += tot[i][2]; if(res >= mod) res -= mod; } } cout<<res<<"\n"; }
#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...