답안 #198113

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198113 2020-01-24T18:15:29 Z model_code Amusement Park (CEOI19_amusementpark) C++17
100 / 100
2923 ms 457660 KB
#include <vector>
#include <algorithm>
#include <array>
#include <iostream>
#include <string>
using namespace std;

#define x first
#define y second
typedef std::pair<int,int> pii; 
template <unsigned int N> class Field {
    typedef unsigned int ui;
    typedef unsigned long long ull;
	inline ui pow(ui a, ui p){ui r=1,e=a;while(p){if(p&1){r=((ull)r*e)%N;}e=((ull)e*e)%N;p>>=1;}return r;}
	/*extended GCD(slow):ll t=0,nt=1,r=N,nr=a;while(nr){ll q=r/nr;t-=q*nt;swap(t,nt);r-=q*nr;swap(r,nr);}assert(r<=1);return(t<0)?t+N:t;*/
	inline ui inv(ui a){return pow(a,N-2);}
public:
    inline Field(int x = 0) : v(x) {}
	inline Field<N> pow(int p){return (*this)^p; }
	inline Field<N> operator^(int p){return {(int)pow(v,(ui)p)};}
    inline Field<N>&operator+=(const Field<N>&o) {if (v+o.v >= N) v += o.v - N; else v += o.v; return *this; }
    inline Field<N>&operator-=(const Field<N>&o) {if (v<o.v) v -= o.v-N; else v-=o.v; return *this; }
    inline Field<N>&operator*=(const Field<N>&o) {v=(ull)v*o.v % N; return *this; }
    inline Field<N>&operator/=(const Field<N>&o) { return *this*=inv(o.v); }
    inline Field<N> operator+(const Field<N>&o) const {Field<N>r{*this};return r+=o;}
    inline Field<N> operator-(const Field<N>&o) const {Field<N>r{*this};return r-=o;}
    inline Field<N> operator*(const Field<N>&o) const {Field<N>r{*this};return r*=o;}
    inline Field<N> operator/(const Field<N>&o) const {Field<N>r{*this};return r/=o;}
    inline Field<N> operator-() {if(v) return {(int)(N-v)}; else return {0};};
    inline Field<N>& operator++() { ++v; if (v==N) v=0; return *this; }
    inline Field<N> operator++(int) { Field<N>r{*this}; ++*this; return r; }
    inline Field<N>& operator--() { --v; if (v==-1) v=N-1; return *this; }
    inline Field<N> operator--(int) { Field<N>r{*this}; --*this; return r; }
    inline bool operator==(const Field<N>&o) const { return o.v==v; }
	inline bool operator!=(const Field<N>&o) const { return o.v!=v; }
	inline explicit operator ui() const { return v; }
	inline static vector<Field<N>>fact(int t){vector<Field<N>>F(t+1,1);for(int i=2;i<=t;++i){F[i]=F[i-1]*i;}return F;}
	inline static vector<Field<N>>invfact(int t){vector<Field<N>>F(t+1,1);Field<N> X{1};for(int i=2;i<=t;++i){X=X*i;}F[t]=1/X;for(int i=t-1;i>=2;--i){F[i]=F[i+1]*(i+1);}return F;}
private: ui v;
};
template<unsigned int N>istream &operator>>(std::istream&is,Field<N>&f){unsigned int v;is>>v;f=v;return is;}
template<unsigned int N>ostream &operator<<(std::ostream&os,const Field<N>&f){return os<<(unsigned int)f;}
template<unsigned int N>Field<N> operator+(int i,const Field<N>&f){return Field<N>(i)+f;}
template<unsigned int N>Field<N> operator-(int i,const Field<N>&f){return Field<N>(i)-f;}
template<unsigned int N>Field<N> operator*(int i,const Field<N>&f){return Field<N>(i)*f;}
template<unsigned int N>Field<N> operator/(int i,const Field<N>&f){return Field<N>(i)/f;}

typedef Field<998244353> FieldMod;
typedef pair<int,pair<FieldMod,FieldMod>> FF;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> E(N, 0), F(N, 0);
    for (int i = 0; i < M; ++i) {
        int u, v; cin >> u >> v;
        --u; --v;
        E[u] |= 1<<v;
        F[v] |= 1<<u;
    } 
    
    int g = 1<<N;
    int f = g-1;
    
    vector<vector<FF>> D(g);
    D[0].push_back({f, {1,0}});
    for (int sorted = 0; sorted < g; ++sorted) {
        sort(D[sorted].begin(),D[sorted].end(), [](const FF& a, const FF& b) { return a.x < b.x; });
        vector<FF> X;
        for (auto d: D[sorted]) {
            if (X.empty() || X.back().x != d.x) {
                X.push_back(d);
            } else {
                X.back().y.x += d.y.x;
                X.back().y.y += d.y.y;
            }
        }

        for (auto d : X) {
            int cands = d.x;
            for (int j = 0; j < N; ++j) {
                if (cands&(1<<j)) {
                    int newCands = (cands & (~((1<<(j+1))-1))) | ((E[j]|F[j]) &~sorted);
                    int newSorted = sorted | (1<<j);
                    D[newSorted].push_back({newCands, {d.y.x, d.y.y + d.y.x * __builtin_popcount(E[j]&sorted)}});
                }
            }
        }
    }

    FieldMod ans = 0;
    for (auto f: D[f]) ans += f.y.y;
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 5 ms 420 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 5 ms 420 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 128 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 292 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 5 ms 420 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 128 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 292 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 1 ms 376 KB Output is correct
36 Correct 2 ms 380 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 352 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 2 ms 380 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 2 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 380 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 3 ms 632 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 3 ms 508 KB Output is correct
59 Correct 3 ms 552 KB Output is correct
60 Correct 15 ms 552 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 5 ms 420 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 128 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 292 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 1 ms 376 KB Output is correct
36 Correct 2 ms 380 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 352 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 2 ms 380 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 2 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 380 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 3 ms 632 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 3 ms 508 KB Output is correct
59 Correct 3 ms 552 KB Output is correct
60 Correct 15 ms 552 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 500 KB Output is correct
65 Correct 44 ms 8012 KB Output is correct
66 Correct 63 ms 11332 KB Output is correct
67 Correct 59 ms 11080 KB Output is correct
68 Correct 63 ms 11636 KB Output is correct
69 Correct 17 ms 3576 KB Output is correct
70 Correct 22 ms 4616 KB Output is correct
71 Correct 22 ms 4764 KB Output is correct
72 Correct 23 ms 4700 KB Output is correct
73 Correct 30 ms 5244 KB Output is correct
74 Correct 26 ms 5240 KB Output is correct
75 Correct 25 ms 5240 KB Output is correct
76 Correct 24 ms 5240 KB Output is correct
77 Correct 90 ms 15472 KB Output is correct
78 Correct 118 ms 20308 KB Output is correct
79 Correct 164 ms 27856 KB Output is correct
80 Correct 144 ms 25644 KB Output is correct
81 Correct 165 ms 29000 KB Output is correct
82 Correct 156 ms 28400 KB Output is correct
83 Correct 157 ms 28732 KB Output is correct
84 Correct 120 ms 21212 KB Output is correct
85 Correct 44 ms 7324 KB Output is correct
86 Correct 50 ms 9856 KB Output is correct
87 Correct 50 ms 9976 KB Output is correct
88 Correct 61 ms 9976 KB Output is correct
89 Correct 58 ms 11104 KB Output is correct
90 Correct 59 ms 11100 KB Output is correct
91 Correct 58 ms 11112 KB Output is correct
92 Correct 54 ms 11128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 5 ms 420 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 256 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 348 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 128 KB Output is correct
17 Correct 2 ms 252 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 292 KB Output is correct
24 Correct 2 ms 256 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 2 ms 256 KB Output is correct
32 Correct 2 ms 376 KB Output is correct
33 Correct 2 ms 376 KB Output is correct
34 Correct 2 ms 376 KB Output is correct
35 Correct 1 ms 376 KB Output is correct
36 Correct 2 ms 380 KB Output is correct
37 Correct 2 ms 376 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 2 ms 376 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
41 Correct 2 ms 376 KB Output is correct
42 Correct 2 ms 376 KB Output is correct
43 Correct 2 ms 352 KB Output is correct
44 Correct 3 ms 504 KB Output is correct
45 Correct 3 ms 376 KB Output is correct
46 Correct 2 ms 380 KB Output is correct
47 Correct 2 ms 348 KB Output is correct
48 Correct 3 ms 376 KB Output is correct
49 Correct 2 ms 348 KB Output is correct
50 Correct 2 ms 348 KB Output is correct
51 Correct 2 ms 376 KB Output is correct
52 Correct 2 ms 376 KB Output is correct
53 Correct 2 ms 380 KB Output is correct
54 Correct 3 ms 504 KB Output is correct
55 Correct 3 ms 504 KB Output is correct
56 Correct 3 ms 632 KB Output is correct
57 Correct 3 ms 632 KB Output is correct
58 Correct 3 ms 508 KB Output is correct
59 Correct 3 ms 552 KB Output is correct
60 Correct 15 ms 552 KB Output is correct
61 Correct 3 ms 504 KB Output is correct
62 Correct 3 ms 504 KB Output is correct
63 Correct 3 ms 504 KB Output is correct
64 Correct 3 ms 500 KB Output is correct
65 Correct 44 ms 8012 KB Output is correct
66 Correct 63 ms 11332 KB Output is correct
67 Correct 59 ms 11080 KB Output is correct
68 Correct 63 ms 11636 KB Output is correct
69 Correct 17 ms 3576 KB Output is correct
70 Correct 22 ms 4616 KB Output is correct
71 Correct 22 ms 4764 KB Output is correct
72 Correct 23 ms 4700 KB Output is correct
73 Correct 30 ms 5244 KB Output is correct
74 Correct 26 ms 5240 KB Output is correct
75 Correct 25 ms 5240 KB Output is correct
76 Correct 24 ms 5240 KB Output is correct
77 Correct 90 ms 15472 KB Output is correct
78 Correct 118 ms 20308 KB Output is correct
79 Correct 164 ms 27856 KB Output is correct
80 Correct 144 ms 25644 KB Output is correct
81 Correct 165 ms 29000 KB Output is correct
82 Correct 156 ms 28400 KB Output is correct
83 Correct 157 ms 28732 KB Output is correct
84 Correct 120 ms 21212 KB Output is correct
85 Correct 44 ms 7324 KB Output is correct
86 Correct 50 ms 9856 KB Output is correct
87 Correct 50 ms 9976 KB Output is correct
88 Correct 61 ms 9976 KB Output is correct
89 Correct 58 ms 11104 KB Output is correct
90 Correct 59 ms 11100 KB Output is correct
91 Correct 58 ms 11112 KB Output is correct
92 Correct 54 ms 11128 KB Output is correct
93 Correct 624 ms 101740 KB Output is correct
94 Correct 212 ms 35200 KB Output is correct
95 Correct 97 ms 19672 KB Output is correct
96 Correct 670 ms 115476 KB Output is correct
97 Correct 674 ms 113360 KB Output is correct
98 Correct 590 ms 99208 KB Output is correct
99 Correct 135 ms 21040 KB Output is correct
100 Correct 243 ms 38124 KB Output is correct
101 Correct 368 ms 59576 KB Output is correct
102 Correct 415 ms 68608 KB Output is correct
103 Correct 25 ms 7544 KB Output is correct
104 Correct 33 ms 8056 KB Output is correct
105 Correct 125 ms 20408 KB Output is correct
106 Correct 514 ms 80124 KB Output is correct
107 Correct 50 ms 14712 KB Output is correct
108 Correct 268 ms 43372 KB Output is correct
109 Correct 1182 ms 173992 KB Output is correct
110 Correct 2753 ms 421580 KB Output is correct
111 Correct 503 ms 72956 KB Output is correct
112 Correct 393 ms 67564 KB Output is correct
113 Correct 394 ms 67044 KB Output is correct
114 Correct 82 ms 15580 KB Output is correct
115 Correct 122 ms 21360 KB Output is correct
116 Correct 114 ms 21508 KB Output is correct
117 Correct 110 ms 21624 KB Output is correct
118 Correct 133 ms 23868 KB Output is correct
119 Correct 134 ms 24028 KB Output is correct
120 Correct 132 ms 24184 KB Output is correct
121 Correct 126 ms 24184 KB Output is correct
122 Correct 705 ms 112072 KB Output is correct
123 Correct 1078 ms 171892 KB Output is correct
124 Correct 1112 ms 175960 KB Output is correct
125 Correct 1052 ms 171208 KB Output is correct
126 Correct 957 ms 158592 KB Output is correct
127 Correct 676 ms 116796 KB Output is correct
128 Correct 464 ms 81468 KB Output is correct
129 Correct 309 ms 54136 KB Output is correct
130 Correct 131 ms 25044 KB Output is correct
131 Correct 183 ms 33528 KB Output is correct
132 Correct 261 ms 46520 KB Output is correct
133 Correct 297 ms 46948 KB Output is correct
134 Correct 271 ms 47056 KB Output is correct
135 Correct 296 ms 52536 KB Output is correct
136 Correct 301 ms 52612 KB Output is correct
137 Correct 304 ms 53108 KB Output is correct
138 Correct 298 ms 52984 KB Output is correct
139 Correct 310 ms 54624 KB Output is correct
140 Correct 316 ms 54732 KB Output is correct
141 Correct 316 ms 55196 KB Output is correct
142 Correct 2675 ms 412448 KB Output is correct
143 Correct 2754 ms 423504 KB Output is correct
144 Correct 2115 ms 331588 KB Output is correct
145 Correct 1636 ms 262296 KB Output is correct
146 Correct 837 ms 145484 KB Output is correct
147 Correct 296 ms 52152 KB Output is correct
148 Correct 2659 ms 400932 KB Output is correct
149 Correct 2655 ms 417216 KB Output is correct
150 Correct 2923 ms 457660 KB Output is correct
151 Correct 517 ms 92584 KB Output is correct
152 Correct 550 ms 97156 KB Output is correct
153 Correct 675 ms 115460 KB Output is correct
154 Correct 675 ms 115448 KB Output is correct
155 Correct 701 ms 115936 KB Output is correct
156 Correct 685 ms 116528 KB Output is correct
157 Correct 705 ms 115892 KB Output is correct
158 Correct 688 ms 116768 KB Output is correct
159 Correct 768 ms 120320 KB Output is correct
160 Correct 761 ms 121444 KB Output is correct
161 Correct 721 ms 121344 KB Output is correct
162 Correct 828 ms 121208 KB Output is correct
163 Correct 725 ms 121548 KB Output is correct
164 Correct 737 ms 121876 KB Output is correct
165 Correct 721 ms 122616 KB Output is correct
166 Correct 744 ms 122780 KB Output is correct
167 Correct 730 ms 121992 KB Output is correct