답안 #582662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
582662 2022-06-24T08:25:39 Z 조영욱(#8372) Amusement Park (CEOI19_amusementpark) C++17
42 / 100
34 ms 16960 KB
#include <bits/stdc++.h>
using namespace std;

typedef pair<int,int> P;
P dp[1024][1024];
const int mod=998244353;
int n,m;
bool arr[15][15];

P pl(P a,P b){
    return P((a.first+b.first)%mod,(a.second+b.second)%mod);
}

long long p2[500];
int cnt=0;

P ans(int bit1,int bit2) {
if (bit1==(1<<n)-1) return P(1,0);
    if (dp[bit1][bit2].first!=-1) {
        return dp[bit1][bit2];
    }
    P ret=P(0,0);
    int sz=0;
    vector<int> v;
    for(int i=0;i<n;i++) {
        if (bit1&(1<<i)) {

        }
        else {
            v.push_back(i);
            sz++;
        }
    }
    for(int ind=1;ind<(1<<sz);ind++) {
        int bit=0;
        for(int i=0;i<n;i++) {
            if (ind&(1<<i)) {
                bit+=(1<<v[i]);
            }
        }
        bool f=true;
        long long cost=0;
        for(int i=0;i<n;i++) {
            if (bit&(1<<i)) {

            }
            else {
                continue;
            }
            bool flag=false;
            if (bit1==0) {
                flag=true;
            }
            for(int j=0;j<n;j++) {
                if (arr[i][j]||arr[j][i]) {
                    if (bit2&(1<<j)) {
                        flag=true;
                    }
                    if (bit1&(1<<j)) {
                        if (arr[i][j]) {
                            cost++;
                        }
                    }
                    else if (bit&(1<<j)) {
                        flag=false;
                        break;
                    }
                }
            }
            if (!flag) {
                f=false;
                break;
            }
        }
        if (!f) {
            continue;
        }
        P val=P(1,cost);
        P got=ans(bit1+bit,bit);
        P save;
        save.first=val.first*got.first;
        save.first%=mod;
        save.second=val.first*got.second+val.second*got.first;
        save.second%=mod;
        if (bit1==0&&bit2==0) {
            //printf("%d %lld %lld\n",bit,save.first,save.second);
        }
        ret=pl(ret,save);
    }
    return dp[bit1][bit2]=ret;
}

int main(void) {
    scanf("%d %d",&n,&m);
    p2[0]=1;
    for(int i=1;i<500;i++) {
        p2[i]=(p2[i-1]*2)%mod;
    }
    for(int i=0;i<(1<<n);i++) {
        for(int j=0;j<(1<<n);j++) {
            dp[i][j]=P(-1,-1);
        }
    }
    for(int i=0;i<m;i++) {
        int u,v;
        scanf("%d %d",&u,&v);
        u--;
        v--;
        arr[u][v]=true;
    }
    printf("%lld",ans(0,0).second);
}

Compilation message

amusementpark.cpp: In function 'int main()':
amusementpark.cpp:111:16: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
  111 |     printf("%lld",ans(0,0).second);
      |             ~~~^  ~~~~~~~~~~~~~~~
      |                |           |
      |                |           int
      |                long long int
      |             %d
amusementpark.cpp:94:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |     scanf("%d %d",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~
amusementpark.cpp:106:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         scanf("%d %d",&u,&v);
      |         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 2 ms 1332 KB Output is correct
33 Correct 2 ms 1236 KB Output is correct
34 Correct 2 ms 1236 KB Output is correct
35 Correct 2 ms 1236 KB Output is correct
36 Correct 2 ms 1236 KB Output is correct
37 Correct 2 ms 1236 KB Output is correct
38 Correct 2 ms 1236 KB Output is correct
39 Correct 5 ms 4308 KB Output is correct
40 Correct 5 ms 4308 KB Output is correct
41 Correct 6 ms 4408 KB Output is correct
42 Correct 8 ms 4408 KB Output is correct
43 Correct 12 ms 4308 KB Output is correct
44 Correct 7 ms 4308 KB Output is correct
45 Correct 8 ms 4404 KB Output is correct
46 Correct 8 ms 4308 KB Output is correct
47 Correct 6 ms 4308 KB Output is correct
48 Correct 7 ms 4308 KB Output is correct
49 Correct 9 ms 4308 KB Output is correct
50 Correct 8 ms 4308 KB Output is correct
51 Correct 10 ms 4408 KB Output is correct
52 Correct 12 ms 8504 KB Output is correct
53 Correct 16 ms 8504 KB Output is correct
54 Correct 20 ms 8508 KB Output is correct
55 Correct 23 ms 8504 KB Output is correct
56 Correct 32 ms 8488 KB Output is correct
57 Correct 24 ms 8508 KB Output is correct
58 Correct 25 ms 8404 KB Output is correct
59 Correct 20 ms 8508 KB Output is correct
60 Correct 16 ms 8404 KB Output is correct
61 Correct 24 ms 8404 KB Output is correct
62 Correct 27 ms 8404 KB Output is correct
63 Correct 27 ms 8404 KB Output is correct
64 Correct 34 ms 8404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 2 ms 1332 KB Output is correct
33 Correct 2 ms 1236 KB Output is correct
34 Correct 2 ms 1236 KB Output is correct
35 Correct 2 ms 1236 KB Output is correct
36 Correct 2 ms 1236 KB Output is correct
37 Correct 2 ms 1236 KB Output is correct
38 Correct 2 ms 1236 KB Output is correct
39 Correct 5 ms 4308 KB Output is correct
40 Correct 5 ms 4308 KB Output is correct
41 Correct 6 ms 4408 KB Output is correct
42 Correct 8 ms 4408 KB Output is correct
43 Correct 12 ms 4308 KB Output is correct
44 Correct 7 ms 4308 KB Output is correct
45 Correct 8 ms 4404 KB Output is correct
46 Correct 8 ms 4308 KB Output is correct
47 Correct 6 ms 4308 KB Output is correct
48 Correct 7 ms 4308 KB Output is correct
49 Correct 9 ms 4308 KB Output is correct
50 Correct 8 ms 4308 KB Output is correct
51 Correct 10 ms 4408 KB Output is correct
52 Correct 12 ms 8504 KB Output is correct
53 Correct 16 ms 8504 KB Output is correct
54 Correct 20 ms 8508 KB Output is correct
55 Correct 23 ms 8504 KB Output is correct
56 Correct 32 ms 8488 KB Output is correct
57 Correct 24 ms 8508 KB Output is correct
58 Correct 25 ms 8404 KB Output is correct
59 Correct 20 ms 8508 KB Output is correct
60 Correct 16 ms 8404 KB Output is correct
61 Correct 24 ms 8404 KB Output is correct
62 Correct 27 ms 8404 KB Output is correct
63 Correct 27 ms 8404 KB Output is correct
64 Correct 34 ms 8404 KB Output is correct
65 Runtime error 26 ms 16960 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 340 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 1 ms 468 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 724 KB Output is correct
26 Correct 1 ms 724 KB Output is correct
27 Correct 1 ms 724 KB Output is correct
28 Correct 1 ms 724 KB Output is correct
29 Correct 1 ms 724 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
31 Correct 1 ms 724 KB Output is correct
32 Correct 2 ms 1332 KB Output is correct
33 Correct 2 ms 1236 KB Output is correct
34 Correct 2 ms 1236 KB Output is correct
35 Correct 2 ms 1236 KB Output is correct
36 Correct 2 ms 1236 KB Output is correct
37 Correct 2 ms 1236 KB Output is correct
38 Correct 2 ms 1236 KB Output is correct
39 Correct 5 ms 4308 KB Output is correct
40 Correct 5 ms 4308 KB Output is correct
41 Correct 6 ms 4408 KB Output is correct
42 Correct 8 ms 4408 KB Output is correct
43 Correct 12 ms 4308 KB Output is correct
44 Correct 7 ms 4308 KB Output is correct
45 Correct 8 ms 4404 KB Output is correct
46 Correct 8 ms 4308 KB Output is correct
47 Correct 6 ms 4308 KB Output is correct
48 Correct 7 ms 4308 KB Output is correct
49 Correct 9 ms 4308 KB Output is correct
50 Correct 8 ms 4308 KB Output is correct
51 Correct 10 ms 4408 KB Output is correct
52 Correct 12 ms 8504 KB Output is correct
53 Correct 16 ms 8504 KB Output is correct
54 Correct 20 ms 8508 KB Output is correct
55 Correct 23 ms 8504 KB Output is correct
56 Correct 32 ms 8488 KB Output is correct
57 Correct 24 ms 8508 KB Output is correct
58 Correct 25 ms 8404 KB Output is correct
59 Correct 20 ms 8508 KB Output is correct
60 Correct 16 ms 8404 KB Output is correct
61 Correct 24 ms 8404 KB Output is correct
62 Correct 27 ms 8404 KB Output is correct
63 Correct 27 ms 8404 KB Output is correct
64 Correct 34 ms 8404 KB Output is correct
65 Runtime error 26 ms 16960 KB Execution killed with signal 11
66 Halted 0 ms 0 KB -