답안 #1059260

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1059260 2024-08-14T19:53:48 Z oscar1f Lamps (JOI19_lamps) C++17
51 / 100
449 ms 262144 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int TAILLE_MAX=1000*1000+5,INFINI=1000*1000*1000;
int taille;
char carac;
int init[TAILLE_MAX],obj[TAILLE_MAX];
int memo[TAILLE_MAX][2][3][2];

int calcTransi(int xorSous,int milieu,int xorSur,int nouvSous,int nouvMil,int nouvSur) {
    int ans=0;
    if (xorSous==0 and nouvSous==1) {
        ans++;
    }
    if (milieu!=nouvMil and nouvMil!=2) {
        ans++;
    }
    if (xorSur==0 and nouvSur==1) {
        ans++;
    }
    return ans;
}

int calcVal(int val,int xorSous,int milieu,int xorSur) {
    val^=xorSous;
    if (milieu!=2) {
        val=milieu;
    }
    val^=xorSur;
    return val;
}

int dyna(int pos,int xorSous,int milieu,int xorSur) {
    if (pos==taille) {
        return 0;
    }
    int ans=memo[pos][xorSous][milieu][xorSur];
    if (ans!=INFINI) {
        return ans;
    }
    int coutTransi;
    for (int j=0;j<2;j++) {
        for (int k=0;k<3;k++) {
            for (int l=0;l<2;l++) {
                if (milieu!=k or milieu==2) {
                    coutTransi=min(calcTransi(xorSous,milieu,xorSur,j,k,l),calcTransi(xorSur,milieu,xorSous,j,k,l));
                }
                else {
                    coutTransi=calcTransi(xorSous,milieu,xorSur,j,k,l);
                }
                if (calcVal(init[pos],j,k,l)==obj[pos]) {
                    ans=min(ans,coutTransi+dyna(pos+1,j,k,l));
                }
            }
        }
    }
    memo[pos][xorSous][milieu][xorSur]=ans;
    return ans;
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>taille;
    for (int i=0;i<taille;i++) {
        cin>>carac;
        if (carac=='1') {
            init[i]=1;
        }
    }
    for (int i=0;i<taille;i++) {
        cin>>carac;
        if (carac=='1') {
            obj[i]=1;
        }
    }
    for (int i=0;i<taille;i++) {
        for (int j=0;j<2;j++) {
            for (int k=0;k<3;k++) {
                for (int l=0;l<2;l++) {
                    memo[i][j][k][l]=INFINI;
                }
            }
        }
    }
    cout<<dyna(0,0,2,0)<<endl;
    return 0;
}
 
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 356 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 356 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 860 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 1 ms 860 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 1 ms 972 KB Output is correct
49 Correct 1 ms 976 KB Output is correct
50 Correct 1 ms 860 KB Output is correct
51 Correct 1 ms 860 KB Output is correct
52 Correct 1 ms 1016 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
54 Correct 1 ms 860 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 856 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 424 ms 253036 KB Output is correct
8 Correct 389 ms 260692 KB Output is correct
9 Correct 414 ms 260692 KB Output is correct
10 Correct 383 ms 260692 KB Output is correct
11 Correct 398 ms 260632 KB Output is correct
12 Correct 391 ms 260692 KB Output is correct
13 Correct 449 ms 257616 KB Output is correct
14 Correct 406 ms 260616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 356 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 468 KB Output is correct
32 Correct 0 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 1 ms 860 KB Output is correct
37 Correct 1 ms 860 KB Output is correct
38 Correct 1 ms 860 KB Output is correct
39 Correct 1 ms 860 KB Output is correct
40 Correct 1 ms 860 KB Output is correct
41 Correct 1 ms 860 KB Output is correct
42 Correct 1 ms 860 KB Output is correct
43 Correct 1 ms 860 KB Output is correct
44 Correct 1 ms 860 KB Output is correct
45 Correct 1 ms 860 KB Output is correct
46 Correct 1 ms 860 KB Output is correct
47 Correct 1 ms 860 KB Output is correct
48 Correct 1 ms 972 KB Output is correct
49 Correct 1 ms 976 KB Output is correct
50 Correct 1 ms 860 KB Output is correct
51 Correct 1 ms 860 KB Output is correct
52 Correct 1 ms 1016 KB Output is correct
53 Correct 1 ms 860 KB Output is correct
54 Correct 1 ms 860 KB Output is correct
55 Correct 1 ms 860 KB Output is correct
56 Correct 1 ms 856 KB Output is correct
57 Correct 1 ms 860 KB Output is correct
58 Correct 1 ms 860 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 0 ms 348 KB Output is correct
61 Correct 0 ms 348 KB Output is correct
62 Correct 0 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 0 ms 348 KB Output is correct
65 Correct 424 ms 253036 KB Output is correct
66 Correct 389 ms 260692 KB Output is correct
67 Correct 414 ms 260692 KB Output is correct
68 Correct 383 ms 260692 KB Output is correct
69 Correct 398 ms 260632 KB Output is correct
70 Correct 391 ms 260692 KB Output is correct
71 Correct 449 ms 257616 KB Output is correct
72 Correct 406 ms 260616 KB Output is correct
73 Correct 393 ms 260688 KB Output is correct
74 Runtime error 118 ms 262144 KB Execution killed with signal 9
75 Halted 0 ms 0 KB -