답안 #259963

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
259963 2020-08-08T21:13:08 Z MarcoMeijer Amusement Park (CEOI19_amusementpark) C++14
100 / 100
1440 ms 22264 KB
#include <bits/stdc++.h>
using namespace std;

// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e9
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
#define sz size()

// input
template<class T> void IN(T& x) {cin >> x;}
template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); }

// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi," ",x.se);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }

//===================//
//  Added libraries  //
//===================//

// mod library
ll MOD=998244353;

inline ll mod(ll x_) {
    return (x_)%MOD;
}
ll modpow(ll x_, ll N_) {
    if(N_ == 0) return 1;
    ll a = modpow(x_,N_/2);
    a = (a*a)%MOD;
    if(N_%2) a = (a*x_)%MOD;
    return a;
}
ll inv(ll x_) {
    return modpow(x_, MOD-2);
}
class mi {
public:
    mi(ll v=0) {value = v;}
    mi  operator+ (ll rs) {
        ll res = value+rs;
        if(res > MOD) res -= MOD;
        return res;
    }
    mi  operator- (ll rs) {return mod(value-rs+MOD);}
    mi  operator* (ll rs) {return mod(value*rs);}
    mi  operator/ (ll rs) {return mod(value*inv(rs));}
    mi& operator+=(ll rs) {*this = (*this)+rs; return *this;}
    mi& operator-=(ll rs) {*this = (*this)-rs; return *this;}
    mi& operator*=(ll rs) {*this = (*this)*rs; return *this;}
    mi& operator/=(ll rs) {*this = (*this)/rs; return *this;}
    operator ll&() {return value;}

    ll value;
};
typedef vector<mi> vmi;

//===================//
//end added libraries//
//===================//

void program();
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    program();
}


//===================//
//   begin program   //
//===================//

const int MX = (1<<18)+2;
int n, m, BIT;
int N[18];
int LSB[MX];
map<int,int> dp[MX];

void program() {
    IN(n,m);
    RE(i,n) N[i] = 0;
    RE(i,m) {
        int u, v;
        IN(u,v);
        u--; v--;
        N[u] |= (1<<v);
        N[v] |= (1<<u);
    }
    BIT = (1<<n);
    RE(i,n) LSB[1<<i]=i;

    dp[0][BIT-1] = 1;
    RE(a,BIT) {
        FOR(p,dp[a]) {
            int b=p.fi;
            mi curDP = p.se;
            int nb=b;
            while(nb) {
                int lsb=(nb&-nb);
                int i=LSB[lsb];
                nb -= lsb;
                int A = a|(1<<i);
                int B = b&(~((1<<(i+1))-1)) | (N[i]&(~a));
                auto& DP = dp[A][B];
                DP = mi(DP)+curDP;
            }
        }
        if(a != BIT-1) dp[a].clear();
    }
    OUTL(ll((mi)dp[BIT-1][0]*mi(m)/mi(2)));
}

Compilation message

amusementpark.cpp: In function 'void program()':
amusementpark.cpp:129:26: warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
                 int B = b&(~((1<<(i+1))-1)) | (N[i]&(~a));
                         ~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12672 KB Output is correct
2 Correct 8 ms 12672 KB Output is correct
3 Correct 9 ms 12672 KB Output is correct
4 Correct 8 ms 12672 KB Output is correct
5 Correct 9 ms 12672 KB Output is correct
6 Correct 8 ms 12672 KB Output is correct
7 Correct 8 ms 12672 KB Output is correct
8 Correct 8 ms 12672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12672 KB Output is correct
2 Correct 8 ms 12672 KB Output is correct
3 Correct 9 ms 12672 KB Output is correct
4 Correct 8 ms 12672 KB Output is correct
5 Correct 9 ms 12672 KB Output is correct
6 Correct 8 ms 12672 KB Output is correct
7 Correct 8 ms 12672 KB Output is correct
8 Correct 8 ms 12672 KB Output is correct
9 Correct 9 ms 12672 KB Output is correct
10 Correct 8 ms 12672 KB Output is correct
11 Correct 8 ms 12672 KB Output is correct
12 Correct 9 ms 12672 KB Output is correct
13 Correct 9 ms 12672 KB Output is correct
14 Correct 8 ms 12672 KB Output is correct
15 Correct 9 ms 12672 KB Output is correct
16 Correct 9 ms 12672 KB Output is correct
17 Correct 8 ms 12672 KB Output is correct
18 Correct 9 ms 12672 KB Output is correct
19 Correct 9 ms 12672 KB Output is correct
20 Correct 9 ms 12672 KB Output is correct
21 Correct 8 ms 12672 KB Output is correct
22 Correct 9 ms 12672 KB Output is correct
23 Correct 8 ms 12672 KB Output is correct
24 Correct 9 ms 12672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12672 KB Output is correct
2 Correct 8 ms 12672 KB Output is correct
3 Correct 9 ms 12672 KB Output is correct
4 Correct 8 ms 12672 KB Output is correct
5 Correct 9 ms 12672 KB Output is correct
6 Correct 8 ms 12672 KB Output is correct
7 Correct 8 ms 12672 KB Output is correct
8 Correct 8 ms 12672 KB Output is correct
9 Correct 9 ms 12672 KB Output is correct
10 Correct 8 ms 12672 KB Output is correct
11 Correct 8 ms 12672 KB Output is correct
12 Correct 9 ms 12672 KB Output is correct
13 Correct 9 ms 12672 KB Output is correct
14 Correct 8 ms 12672 KB Output is correct
15 Correct 9 ms 12672 KB Output is correct
16 Correct 9 ms 12672 KB Output is correct
17 Correct 8 ms 12672 KB Output is correct
18 Correct 9 ms 12672 KB Output is correct
19 Correct 9 ms 12672 KB Output is correct
20 Correct 9 ms 12672 KB Output is correct
21 Correct 8 ms 12672 KB Output is correct
22 Correct 9 ms 12672 KB Output is correct
23 Correct 8 ms 12672 KB Output is correct
24 Correct 9 ms 12672 KB Output is correct
25 Correct 9 ms 12672 KB Output is correct
26 Correct 10 ms 12712 KB Output is correct
27 Correct 9 ms 12672 KB Output is correct
28 Correct 10 ms 12672 KB Output is correct
29 Correct 8 ms 12672 KB Output is correct
30 Correct 9 ms 12672 KB Output is correct
31 Correct 9 ms 12672 KB Output is correct
32 Correct 9 ms 12716 KB Output is correct
33 Correct 9 ms 12672 KB Output is correct
34 Correct 10 ms 12672 KB Output is correct
35 Correct 9 ms 12672 KB Output is correct
36 Correct 10 ms 12672 KB Output is correct
37 Correct 9 ms 12672 KB Output is correct
38 Correct 9 ms 12672 KB Output is correct
39 Correct 9 ms 12672 KB Output is correct
40 Correct 9 ms 12672 KB Output is correct
41 Correct 9 ms 12672 KB Output is correct
42 Correct 9 ms 12800 KB Output is correct
43 Correct 9 ms 12672 KB Output is correct
44 Correct 9 ms 12672 KB Output is correct
45 Correct 9 ms 12672 KB Output is correct
46 Correct 9 ms 12672 KB Output is correct
47 Correct 9 ms 12672 KB Output is correct
48 Correct 9 ms 12672 KB Output is correct
49 Correct 9 ms 12672 KB Output is correct
50 Correct 9 ms 12672 KB Output is correct
51 Correct 8 ms 12672 KB Output is correct
52 Correct 8 ms 12672 KB Output is correct
53 Correct 9 ms 12672 KB Output is correct
54 Correct 9 ms 12672 KB Output is correct
55 Correct 9 ms 12672 KB Output is correct
56 Correct 9 ms 12672 KB Output is correct
57 Correct 9 ms 12672 KB Output is correct
58 Correct 10 ms 12672 KB Output is correct
59 Correct 9 ms 12672 KB Output is correct
60 Correct 9 ms 12672 KB Output is correct
61 Correct 9 ms 12672 KB Output is correct
62 Correct 9 ms 12672 KB Output is correct
63 Correct 9 ms 12672 KB Output is correct
64 Correct 9 ms 12672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12672 KB Output is correct
2 Correct 8 ms 12672 KB Output is correct
3 Correct 9 ms 12672 KB Output is correct
4 Correct 8 ms 12672 KB Output is correct
5 Correct 9 ms 12672 KB Output is correct
6 Correct 8 ms 12672 KB Output is correct
7 Correct 8 ms 12672 KB Output is correct
8 Correct 8 ms 12672 KB Output is correct
9 Correct 9 ms 12672 KB Output is correct
10 Correct 8 ms 12672 KB Output is correct
11 Correct 8 ms 12672 KB Output is correct
12 Correct 9 ms 12672 KB Output is correct
13 Correct 9 ms 12672 KB Output is correct
14 Correct 8 ms 12672 KB Output is correct
15 Correct 9 ms 12672 KB Output is correct
16 Correct 9 ms 12672 KB Output is correct
17 Correct 8 ms 12672 KB Output is correct
18 Correct 9 ms 12672 KB Output is correct
19 Correct 9 ms 12672 KB Output is correct
20 Correct 9 ms 12672 KB Output is correct
21 Correct 8 ms 12672 KB Output is correct
22 Correct 9 ms 12672 KB Output is correct
23 Correct 8 ms 12672 KB Output is correct
24 Correct 9 ms 12672 KB Output is correct
25 Correct 9 ms 12672 KB Output is correct
26 Correct 10 ms 12712 KB Output is correct
27 Correct 9 ms 12672 KB Output is correct
28 Correct 10 ms 12672 KB Output is correct
29 Correct 8 ms 12672 KB Output is correct
30 Correct 9 ms 12672 KB Output is correct
31 Correct 9 ms 12672 KB Output is correct
32 Correct 9 ms 12716 KB Output is correct
33 Correct 9 ms 12672 KB Output is correct
34 Correct 10 ms 12672 KB Output is correct
35 Correct 9 ms 12672 KB Output is correct
36 Correct 10 ms 12672 KB Output is correct
37 Correct 9 ms 12672 KB Output is correct
38 Correct 9 ms 12672 KB Output is correct
39 Correct 9 ms 12672 KB Output is correct
40 Correct 9 ms 12672 KB Output is correct
41 Correct 9 ms 12672 KB Output is correct
42 Correct 9 ms 12800 KB Output is correct
43 Correct 9 ms 12672 KB Output is correct
44 Correct 9 ms 12672 KB Output is correct
45 Correct 9 ms 12672 KB Output is correct
46 Correct 9 ms 12672 KB Output is correct
47 Correct 9 ms 12672 KB Output is correct
48 Correct 9 ms 12672 KB Output is correct
49 Correct 9 ms 12672 KB Output is correct
50 Correct 9 ms 12672 KB Output is correct
51 Correct 8 ms 12672 KB Output is correct
52 Correct 8 ms 12672 KB Output is correct
53 Correct 9 ms 12672 KB Output is correct
54 Correct 9 ms 12672 KB Output is correct
55 Correct 9 ms 12672 KB Output is correct
56 Correct 9 ms 12672 KB Output is correct
57 Correct 9 ms 12672 KB Output is correct
58 Correct 10 ms 12672 KB Output is correct
59 Correct 9 ms 12672 KB Output is correct
60 Correct 9 ms 12672 KB Output is correct
61 Correct 9 ms 12672 KB Output is correct
62 Correct 9 ms 12672 KB Output is correct
63 Correct 9 ms 12672 KB Output is correct
64 Correct 9 ms 12672 KB Output is correct
65 Correct 26 ms 13240 KB Output is correct
66 Correct 35 ms 13184 KB Output is correct
67 Correct 32 ms 13184 KB Output is correct
68 Correct 32 ms 13184 KB Output is correct
69 Correct 13 ms 13088 KB Output is correct
70 Correct 15 ms 13056 KB Output is correct
71 Correct 15 ms 13184 KB Output is correct
72 Correct 15 ms 13184 KB Output is correct
73 Correct 15 ms 13056 KB Output is correct
74 Correct 16 ms 13184 KB Output is correct
75 Correct 16 ms 13184 KB Output is correct
76 Correct 15 ms 13056 KB Output is correct
77 Correct 52 ms 13696 KB Output is correct
78 Correct 58 ms 13696 KB Output is correct
79 Correct 79 ms 13816 KB Output is correct
80 Correct 66 ms 13696 KB Output is correct
81 Correct 76 ms 13948 KB Output is correct
82 Correct 68 ms 13816 KB Output is correct
83 Correct 67 ms 13688 KB Output is correct
84 Correct 49 ms 13696 KB Output is correct
85 Correct 25 ms 13440 KB Output is correct
86 Correct 23 ms 13568 KB Output is correct
87 Correct 29 ms 13820 KB Output is correct
88 Correct 22 ms 13696 KB Output is correct
89 Correct 25 ms 13568 KB Output is correct
90 Correct 25 ms 13696 KB Output is correct
91 Correct 25 ms 13696 KB Output is correct
92 Correct 24 ms 13568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 12672 KB Output is correct
2 Correct 8 ms 12672 KB Output is correct
3 Correct 9 ms 12672 KB Output is correct
4 Correct 8 ms 12672 KB Output is correct
5 Correct 9 ms 12672 KB Output is correct
6 Correct 8 ms 12672 KB Output is correct
7 Correct 8 ms 12672 KB Output is correct
8 Correct 8 ms 12672 KB Output is correct
9 Correct 9 ms 12672 KB Output is correct
10 Correct 8 ms 12672 KB Output is correct
11 Correct 8 ms 12672 KB Output is correct
12 Correct 9 ms 12672 KB Output is correct
13 Correct 9 ms 12672 KB Output is correct
14 Correct 8 ms 12672 KB Output is correct
15 Correct 9 ms 12672 KB Output is correct
16 Correct 9 ms 12672 KB Output is correct
17 Correct 8 ms 12672 KB Output is correct
18 Correct 9 ms 12672 KB Output is correct
19 Correct 9 ms 12672 KB Output is correct
20 Correct 9 ms 12672 KB Output is correct
21 Correct 8 ms 12672 KB Output is correct
22 Correct 9 ms 12672 KB Output is correct
23 Correct 8 ms 12672 KB Output is correct
24 Correct 9 ms 12672 KB Output is correct
25 Correct 9 ms 12672 KB Output is correct
26 Correct 10 ms 12712 KB Output is correct
27 Correct 9 ms 12672 KB Output is correct
28 Correct 10 ms 12672 KB Output is correct
29 Correct 8 ms 12672 KB Output is correct
30 Correct 9 ms 12672 KB Output is correct
31 Correct 9 ms 12672 KB Output is correct
32 Correct 9 ms 12716 KB Output is correct
33 Correct 9 ms 12672 KB Output is correct
34 Correct 10 ms 12672 KB Output is correct
35 Correct 9 ms 12672 KB Output is correct
36 Correct 10 ms 12672 KB Output is correct
37 Correct 9 ms 12672 KB Output is correct
38 Correct 9 ms 12672 KB Output is correct
39 Correct 9 ms 12672 KB Output is correct
40 Correct 9 ms 12672 KB Output is correct
41 Correct 9 ms 12672 KB Output is correct
42 Correct 9 ms 12800 KB Output is correct
43 Correct 9 ms 12672 KB Output is correct
44 Correct 9 ms 12672 KB Output is correct
45 Correct 9 ms 12672 KB Output is correct
46 Correct 9 ms 12672 KB Output is correct
47 Correct 9 ms 12672 KB Output is correct
48 Correct 9 ms 12672 KB Output is correct
49 Correct 9 ms 12672 KB Output is correct
50 Correct 9 ms 12672 KB Output is correct
51 Correct 8 ms 12672 KB Output is correct
52 Correct 8 ms 12672 KB Output is correct
53 Correct 9 ms 12672 KB Output is correct
54 Correct 9 ms 12672 KB Output is correct
55 Correct 9 ms 12672 KB Output is correct
56 Correct 9 ms 12672 KB Output is correct
57 Correct 9 ms 12672 KB Output is correct
58 Correct 10 ms 12672 KB Output is correct
59 Correct 9 ms 12672 KB Output is correct
60 Correct 9 ms 12672 KB Output is correct
61 Correct 9 ms 12672 KB Output is correct
62 Correct 9 ms 12672 KB Output is correct
63 Correct 9 ms 12672 KB Output is correct
64 Correct 9 ms 12672 KB Output is correct
65 Correct 26 ms 13240 KB Output is correct
66 Correct 35 ms 13184 KB Output is correct
67 Correct 32 ms 13184 KB Output is correct
68 Correct 32 ms 13184 KB Output is correct
69 Correct 13 ms 13088 KB Output is correct
70 Correct 15 ms 13056 KB Output is correct
71 Correct 15 ms 13184 KB Output is correct
72 Correct 15 ms 13184 KB Output is correct
73 Correct 15 ms 13056 KB Output is correct
74 Correct 16 ms 13184 KB Output is correct
75 Correct 16 ms 13184 KB Output is correct
76 Correct 15 ms 13056 KB Output is correct
77 Correct 52 ms 13696 KB Output is correct
78 Correct 58 ms 13696 KB Output is correct
79 Correct 79 ms 13816 KB Output is correct
80 Correct 66 ms 13696 KB Output is correct
81 Correct 76 ms 13948 KB Output is correct
82 Correct 68 ms 13816 KB Output is correct
83 Correct 67 ms 13688 KB Output is correct
84 Correct 49 ms 13696 KB Output is correct
85 Correct 25 ms 13440 KB Output is correct
86 Correct 23 ms 13568 KB Output is correct
87 Correct 29 ms 13820 KB Output is correct
88 Correct 22 ms 13696 KB Output is correct
89 Correct 25 ms 13568 KB Output is correct
90 Correct 25 ms 13696 KB Output is correct
91 Correct 25 ms 13696 KB Output is correct
92 Correct 24 ms 13568 KB Output is correct
93 Correct 209 ms 19448 KB Output is correct
94 Correct 77 ms 18940 KB Output is correct
95 Correct 47 ms 18896 KB Output is correct
96 Correct 228 ms 19580 KB Output is correct
97 Correct 217 ms 19576 KB Output is correct
98 Correct 198 ms 19576 KB Output is correct
99 Correct 69 ms 14592 KB Output is correct
100 Correct 125 ms 14712 KB Output is correct
101 Correct 179 ms 14968 KB Output is correct
102 Correct 195 ms 15096 KB Output is correct
103 Correct 20 ms 15872 KB Output is correct
104 Correct 21 ms 15736 KB Output is correct
105 Correct 55 ms 16504 KB Output is correct
106 Correct 239 ms 17400 KB Output is correct
107 Correct 31 ms 18816 KB Output is correct
108 Correct 130 ms 19704 KB Output is correct
109 Correct 611 ms 22252 KB Output is correct
110 Correct 1440 ms 21700 KB Output is correct
111 Correct 197 ms 15096 KB Output is correct
112 Correct 159 ms 14712 KB Output is correct
113 Correct 153 ms 15096 KB Output is correct
114 Correct 33 ms 14336 KB Output is correct
115 Correct 42 ms 14336 KB Output is correct
116 Correct 42 ms 14720 KB Output is correct
117 Correct 40 ms 14592 KB Output is correct
118 Correct 45 ms 14464 KB Output is correct
119 Correct 46 ms 14592 KB Output is correct
120 Correct 46 ms 14592 KB Output is correct
121 Correct 43 ms 14464 KB Output is correct
122 Correct 319 ms 16876 KB Output is correct
123 Correct 514 ms 17400 KB Output is correct
124 Correct 474 ms 17400 KB Output is correct
125 Correct 422 ms 17144 KB Output is correct
126 Correct 380 ms 16888 KB Output is correct
127 Correct 255 ms 16888 KB Output is correct
128 Correct 151 ms 16760 KB Output is correct
129 Correct 91 ms 15992 KB Output is correct
130 Correct 32 ms 15736 KB Output is correct
131 Correct 63 ms 16000 KB Output is correct
132 Correct 86 ms 16120 KB Output is correct
133 Correct 87 ms 16632 KB Output is correct
134 Correct 81 ms 16640 KB Output is correct
135 Correct 93 ms 16120 KB Output is correct
136 Correct 105 ms 16576 KB Output is correct
137 Correct 96 ms 16632 KB Output is correct
138 Correct 102 ms 16252 KB Output is correct
139 Correct 100 ms 16120 KB Output is correct
140 Correct 99 ms 16248 KB Output is correct
141 Correct 98 ms 16120 KB Output is correct
142 Correct 1233 ms 21972 KB Output is correct
143 Correct 1208 ms 22264 KB Output is correct
144 Correct 892 ms 21452 KB Output is correct
145 Correct 662 ms 20984 KB Output is correct
146 Correct 314 ms 20728 KB Output is correct
147 Correct 62 ms 18808 KB Output is correct
148 Correct 1242 ms 21980 KB Output is correct
149 Correct 1101 ms 21240 KB Output is correct
150 Correct 1365 ms 22112 KB Output is correct
151 Correct 195 ms 20984 KB Output is correct
152 Correct 212 ms 20856 KB Output is correct
153 Correct 229 ms 19576 KB Output is correct
154 Correct 236 ms 19704 KB Output is correct
155 Correct 228 ms 20600 KB Output is correct
156 Correct 209 ms 19704 KB Output is correct
157 Correct 232 ms 20728 KB Output is correct
158 Correct 224 ms 20728 KB Output is correct
159 Correct 230 ms 19832 KB Output is correct
160 Correct 262 ms 20856 KB Output is correct
161 Correct 216 ms 19320 KB Output is correct
162 Correct 227 ms 19704 KB Output is correct
163 Correct 236 ms 20600 KB Output is correct
164 Correct 235 ms 20600 KB Output is correct
165 Correct 270 ms 19836 KB Output is correct
166 Correct 228 ms 19320 KB Output is correct
167 Correct 207 ms 19064 KB Output is correct