답안 #910916

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
910916 2024-01-18T09:27:37 Z Darren0724 Lamps (JOI19_lamps) C++17
4 / 100
49 ms 37972 KB
#pragma GCC optimize("Ofast","O3","unroll-loops")
#pragma GCC target("avx2")
#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e9;

int32_t main() {
    LCBorz;
    int n;cin>>n;
    vector<int> s(n+1),t(n+1);
    for(int i=1;i<=n;i++){
        char c;cin>>c;
        s[i]=c-'0';
    }
    for(int i=1;i<=n;i++){
        char c;cin>>c;
        t[i]=c-'0';
    }
    vector dp(6,vector(n+1,INF));
    dp[0][0]=0;
    // 0->none 1->no0 2->no1 3->flip 4->flip0 5-> flip1
    int a[6][6]={
        0,1,1,1,INF,INF,
        0,0,1,1,INF,INF,
        0,1,0,0,INF,INF,
        0,1,1,0,1,1,
        0,0,1,0,0,1,
        0,1,0,0,1,0
    };
    for(int i=1;i<=n;i++){
        if(s[i]==0&&t[i]==0){
            for(int k:{0,1,4}){
                for(int j=0;j<6;j++){
                    dp[k][i]=min(dp[k][i],dp[j][i-1]+a[j][k]);
                }
            } 
        }
        if(s[i]==1&&t[i]==0){
            for(int k:{1,3,4}){
                for(int j=0;j<6;j++){
                    dp[k][i]=min(dp[k][i],dp[j][i-1]+a[j][k]);
                }
            } 
        }
        if(s[i]==0&&t[i]==1){
            for(int k:{2,3,5}){
                for(int j=0;j<6;j++){
                    dp[k][i]=min(dp[k][i],dp[j][i-1]+a[j][k]);
                }
            } 
        }
        if(s[i]==1&&t[i]==1){
            for(int k:{0,2,5}){
                for(int j=0;j<6;j++){
                    dp[k][i]=min(dp[k][i],dp[j][i-1]+a[j][k]);
                }
            } 
        }
    }
    int ans=INF;
    for(int i=0;i<6;i++){
        ans=min(ans,dp[i][n]);
    }
    cout<<ans<<endl;
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 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 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Incorrect 0 ms 456 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 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 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Incorrect 0 ms 456 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 40 ms 37460 KB Output is correct
8 Correct 47 ms 37456 KB Output is correct
9 Correct 49 ms 37972 KB Output is correct
10 Correct 46 ms 37588 KB Output is correct
11 Correct 45 ms 37452 KB Output is correct
12 Correct 48 ms 37464 KB Output is correct
13 Correct 44 ms 37444 KB Output is correct
14 Correct 45 ms 37456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 600 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 456 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 456 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 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 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Incorrect 0 ms 456 KB Output isn't correct
29 Halted 0 ms 0 KB -