제출 #697101

#제출 시각아이디문제언어결과실행 시간메모리
697101Alihan_8Amusement Park (CEOI19_amusementpark)C++17
19 / 100
526 ms17336 KiB
#include <bits/stdc++.h>
// include <ext/pb_ds/assoc_container.hpp>
// include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
// define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>
#define mpr make_pair
#define ln '\n'
void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
#define int long long
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n, m; cin >> n >> m;
	vector <int> a(m), b(m);
	for ( int i = 0; i < m; i++ ){
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
	}
	const int Mod = 998244353;
	vector <int> p(n);
	iota(all(p), 0);
	set <int> st;
	do{
        vector <int> g[n], pos(n);
        for ( int i = 0; i < n; i++ ) pos[p[i]] = i;
        int rev = 0, mask = 0;
        for ( int i = 0; i < m; i++ ){
            if ( pos[a[i]] > pos[b[i]] ){
                g[b[i]].pb(a[i]);
                mask |= 1ll << i;
            }
            else g[a[i]].pb(b[i]);
        }
        vector <int> used(n);
        function <bool(int)> dfs = [&](int x){
            used[x] = true;
            for ( auto to: g[x] ){
                if ( !used[to] ){
                    if ( dfs(to) ) return true;
                }
                else if ( used[to] == 1 ) return true;
            }
            used[x] = 2;
            return false;
        };
        bool flag = true;
        for ( int i = 0; i < n; i++ ){
            if ( !used[i] and dfs(i) ){
                flag = false;
                break;
            }
        }
        if ( flag ) st.insert(mask);
	} while ( next_permutation(all(p)) );
    int cnt = 0;
    auto f = [&](int x){
        return __builtin_popcount(x);
    };
    for ( auto i: st ) cnt = (cnt+f(i))%Mod;
    cout << cnt;

	cout << '\n';
}

컴파일 시 표준 에러 (stderr) 메시지

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:30:13: warning: unused variable 'rev' [-Wunused-variable]
   30 |         int rev = 0, mask = 0;
      |             ^~~
amusementpark.cpp: In function 'void IO(std::string)':
amusementpark.cpp:11:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
amusementpark.cpp:11:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | void IO(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                                                               ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...