답안 #823165

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
823165 2023-08-12T08:43:18 Z BidoTeima Lamps (JOI19_lamps) C++17
47 / 100
1000 ms 65300 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int>vec[20];  
int cost[16][16];
int calc(int current, int target){
    if(cost[current][target]!=-1)
        return cost[current][target];
    vector<int>X=vec[current];
    vector<int>Y=vec[target];
        int m = X.size();
    int n = Y.size();
    int L[m + 1][n + 1];
 
    for (int i = 0; i <= m; i++) {
        for (int j = 0; j <= n; j++) {
            if (i == 0 || j == 0)
                L[i][j] = 0;
 
            else if (X[i - 1] == Y[j - 1])
                L[i][j] = L[i - 1][j - 1] + 1;
 
            else
                L[i][j] = max(L[i - 1][j], L[i][j - 1]);
        }
    }
    return cost[current][target]=n-L[m][n];
}
int main()
{        
    memset(cost,-1,sizeof(cost));
    int n;
    string a,b;
    cin>>n>>a>>b;
    for(char&ch:a)ch-='0';
    for(char&ch:b)ch-='0';
    map<vector<int>,int>ind{};
    vector<int>vmsk[20];
    int mask[20];
    int to[2][20];
    int cur=0;
    for(int i = 0; i < 8; i++){
        vector<int>v;
        int msk=0;
        for(int j = 0; j < 3; j++){
            if(i&(1<<j))v.push_back(j),msk+=(1<<j);
        }
        vmsk[msk]=v;
        do{
            vec[cur]=v;
            ind[v]=cur;
            mask[cur]=msk;
            ++cur;
        }while(next_permutation(v.begin(),v.end()));
    }
    int dp[16][n+1];
    for(int i = 0; i < 16; i++){
        for(int j = 0; j < n + 1; j++){
            dp[i][j]=1e6+1;
        }
    }
    for(int i = 0; i < 16; i++){ 
        int val = a[0];
        for(int x : vec[i]){
            if(x==0)val=0;
            else if(x==1)val=1;
            else val ^= 1;
        }
        if(val==b[0]){
            dp[i][0]=vec[i].size();
            //assert(vec[i].size());
        }
        to[a[0]][i]=val;
        val=a[0]^1;
        for(int x : vec[i]){
            if(x==0)val=0;
            else if(x==1)val=1;
            else val ^= 1;
        }
        to[a[0]^1][i]=val;
    }
    /*for(int i = 0; i < n; i++){
        for(int j = 0; j < cur; j++){
            assert(dp[j][i]);
        }
    }*/
    for(int i = 0; i + 1 < n; i++){
        for(int j = 0; j < 16; j++){
            for(int k = 0; k < 16; k++){
                if(to[a[i+1]][k]==b[i+1])
                    dp[k][i+1]=min(dp[k][i+1],dp[j][i]+calc(j,k));
            }
        }
    }
    int ans = 1e9;
    for(int j = 0; j < 16; j++){
        ans=min(ans,dp[j][n-1]);
    }
    assert(cur==16);
    cout<<ans;
    return 0;
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:73:16: warning: array subscript has type 'char' [-Wchar-subscripts]
   73 |         to[a[0]][i]=val;
      |                ^
lamp.cpp:90:29: warning: array subscript has type 'char' [-Wchar-subscripts]
   90 |                 if(to[a[i+1]][k]==b[i+1])
      |                             ^
lamp.cpp:39:9: warning: variable 'mask' set but not used [-Wunused-but-set-variable]
   39 |     int mask[20];
      |         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 308 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 308 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 3 ms 432 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 3 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 4 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 432 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 3 ms 340 KB Output is correct
48 Correct 3 ms 428 KB Output is correct
49 Correct 3 ms 340 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 432 KB Output is correct
53 Correct 3 ms 428 KB Output is correct
54 Correct 2 ms 432 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 300 KB Output is correct
7 Correct 987 ms 65272 KB Output is correct
8 Correct 975 ms 65284 KB Output is correct
9 Correct 953 ms 65300 KB Output is correct
10 Correct 949 ms 65268 KB Output is correct
11 Correct 954 ms 65280 KB Output is correct
12 Correct 958 ms 65272 KB Output is correct
13 Execution timed out 1004 ms 65268 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 304 KB Output is correct
19 Correct 0 ms 300 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 304 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 300 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 0 ms 308 KB Output is correct
31 Correct 0 ms 212 KB Output is correct
32 Correct 1 ms 304 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 1 ms 308 KB Output is correct
35 Correct 3 ms 432 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 3 ms 340 KB Output is correct
38 Correct 3 ms 340 KB Output is correct
39 Correct 2 ms 340 KB Output is correct
40 Correct 2 ms 340 KB Output is correct
41 Correct 4 ms 340 KB Output is correct
42 Correct 2 ms 340 KB Output is correct
43 Correct 3 ms 384 KB Output is correct
44 Correct 2 ms 432 KB Output is correct
45 Correct 2 ms 340 KB Output is correct
46 Correct 3 ms 340 KB Output is correct
47 Correct 3 ms 340 KB Output is correct
48 Correct 3 ms 428 KB Output is correct
49 Correct 3 ms 340 KB Output is correct
50 Correct 2 ms 340 KB Output is correct
51 Correct 2 ms 340 KB Output is correct
52 Correct 2 ms 432 KB Output is correct
53 Correct 3 ms 428 KB Output is correct
54 Correct 2 ms 432 KB Output is correct
55 Correct 2 ms 340 KB Output is correct
56 Correct 2 ms 340 KB Output is correct
57 Correct 2 ms 348 KB Output is correct
58 Correct 2 ms 340 KB Output is correct
59 Correct 0 ms 212 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 0 ms 212 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 0 ms 212 KB Output is correct
64 Correct 0 ms 300 KB Output is correct
65 Correct 987 ms 65272 KB Output is correct
66 Correct 975 ms 65284 KB Output is correct
67 Correct 953 ms 65300 KB Output is correct
68 Correct 949 ms 65268 KB Output is correct
69 Correct 954 ms 65280 KB Output is correct
70 Correct 958 ms 65272 KB Output is correct
71 Execution timed out 1004 ms 65268 KB Time limit exceeded
72 Halted 0 ms 0 KB -