답안 #866747

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
866747 2023-10-27T02:03:41 Z browntoad Lamps (JOI19_lamps) C++14
100 / 100
18 ms 31000 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i,n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pip pair<int, pii>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif

//const ll inf = 1ll<<60;
const int inf=2147483647;
const ll mod = 998244353;
const ll maxn=1e6+5;
const ll maxm=5e4+5;
const double PI=acos(-1);

ll pw(ll x, ll p, ll m=mod){
    ll ret=1;
    while (p>0){
        if (p&1){
            ret*=x;
            ret%=m;
        }
        x*=x;
        x%=m;
        p>>=1;
    }
    return ret;
}

ll inv(ll a, ll m=mod){
    return pw(a,m-2,m);
}
int dp[maxn][3];
bool chan[maxn][3];
int n;
signed main(){
    IOS();
    cin>>n;
    string a, b; cin>>a>>b;
    a = '0'+a; b = '0'+b;
    dp[0][0] = 1;
    dp[0][1] = inf;
    dp[0][2] = 0;
    REP1(i, n){
        bool x = a[i]-'0', y = b[i]-'0';
        chan[i][0] = (y!=0);
        chan[i][1] = (y!=1);
        chan[i][2] = (x!=y);
        REP(j, 3){
            dp[i][j] = inf;
            REP(l, 3){
                dp[i][j] = min(dp[i][j], dp[i-1][l] + (j!=2 && l!=j) + (!chan[i-1][l] && chan[i][j]));
            }
        }
    }
    cout<<min({dp[n][0], dp[n][1], dp[n][2]})<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2520 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2512 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2400 KB Output is correct
26 Correct 0 ms 2516 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2656 KB Output is correct
33 Correct 1 ms 2400 KB Output is correct
34 Correct 0 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2520 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2512 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2400 KB Output is correct
26 Correct 0 ms 2516 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2656 KB Output is correct
33 Correct 1 ms 2400 KB Output is correct
34 Correct 0 ms 2392 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2400 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2504 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2520 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2400 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2392 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 0 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 ms 2512 KB Output is correct
54 Correct 1 ms 2392 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2512 KB Output is correct
5 Correct 0 ms 2760 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 15 ms 30724 KB Output is correct
8 Correct 15 ms 30540 KB Output is correct
9 Correct 14 ms 30716 KB Output is correct
10 Correct 15 ms 30724 KB Output is correct
11 Correct 18 ms 30792 KB Output is correct
12 Correct 14 ms 30716 KB Output is correct
13 Correct 14 ms 30784 KB Output is correct
14 Correct 15 ms 30728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2520 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 0 ms 2512 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 1 ms 2392 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 ms 2396 KB Output is correct
17 Correct 0 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2392 KB Output is correct
22 Correct 1 ms 2392 KB Output is correct
23 Correct 0 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2400 KB Output is correct
26 Correct 0 ms 2516 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2396 KB Output is correct
29 Correct 1 ms 2396 KB Output is correct
30 Correct 0 ms 2396 KB Output is correct
31 Correct 1 ms 2396 KB Output is correct
32 Correct 0 ms 2656 KB Output is correct
33 Correct 1 ms 2400 KB Output is correct
34 Correct 0 ms 2392 KB Output is correct
35 Correct 1 ms 2396 KB Output is correct
36 Correct 1 ms 2396 KB Output is correct
37 Correct 1 ms 2400 KB Output is correct
38 Correct 0 ms 2396 KB Output is correct
39 Correct 0 ms 2396 KB Output is correct
40 Correct 0 ms 2504 KB Output is correct
41 Correct 1 ms 2396 KB Output is correct
42 Correct 1 ms 2520 KB Output is correct
43 Correct 0 ms 2396 KB Output is correct
44 Correct 0 ms 2396 KB Output is correct
45 Correct 0 ms 2400 KB Output is correct
46 Correct 0 ms 2396 KB Output is correct
47 Correct 1 ms 2396 KB Output is correct
48 Correct 1 ms 2396 KB Output is correct
49 Correct 1 ms 2392 KB Output is correct
50 Correct 0 ms 2396 KB Output is correct
51 Correct 0 ms 2396 KB Output is correct
52 Correct 1 ms 2396 KB Output is correct
53 Correct 0 ms 2512 KB Output is correct
54 Correct 1 ms 2392 KB Output is correct
55 Correct 0 ms 2396 KB Output is correct
56 Correct 1 ms 2396 KB Output is correct
57 Correct 1 ms 2396 KB Output is correct
58 Correct 1 ms 2512 KB Output is correct
59 Correct 1 ms 2396 KB Output is correct
60 Correct 0 ms 2396 KB Output is correct
61 Correct 0 ms 2396 KB Output is correct
62 Correct 0 ms 2512 KB Output is correct
63 Correct 0 ms 2760 KB Output is correct
64 Correct 0 ms 2396 KB Output is correct
65 Correct 15 ms 30724 KB Output is correct
66 Correct 15 ms 30540 KB Output is correct
67 Correct 14 ms 30716 KB Output is correct
68 Correct 15 ms 30724 KB Output is correct
69 Correct 18 ms 30792 KB Output is correct
70 Correct 14 ms 30716 KB Output is correct
71 Correct 14 ms 30784 KB Output is correct
72 Correct 15 ms 30728 KB Output is correct
73 Correct 17 ms 30676 KB Output is correct
74 Correct 16 ms 30712 KB Output is correct
75 Correct 15 ms 30724 KB Output is correct
76 Correct 15 ms 30708 KB Output is correct
77 Correct 14 ms 30732 KB Output is correct
78 Correct 15 ms 30532 KB Output is correct
79 Correct 14 ms 30716 KB Output is correct
80 Correct 15 ms 30728 KB Output is correct
81 Correct 15 ms 30760 KB Output is correct
82 Correct 14 ms 30980 KB Output is correct
83 Correct 15 ms 30740 KB Output is correct
84 Correct 14 ms 30724 KB Output is correct
85 Correct 14 ms 30724 KB Output is correct
86 Correct 14 ms 30600 KB Output is correct
87 Correct 15 ms 30720 KB Output is correct
88 Correct 15 ms 30684 KB Output is correct
89 Correct 14 ms 30744 KB Output is correct
90 Correct 15 ms 30708 KB Output is correct
91 Correct 15 ms 30708 KB Output is correct
92 Correct 15 ms 30728 KB Output is correct
93 Correct 16 ms 30676 KB Output is correct
94 Correct 15 ms 30712 KB Output is correct
95 Correct 15 ms 30716 KB Output is correct
96 Correct 14 ms 30612 KB Output is correct
97 Correct 14 ms 30712 KB Output is correct
98 Correct 14 ms 30728 KB Output is correct
99 Correct 15 ms 30720 KB Output is correct
100 Correct 14 ms 31000 KB Output is correct
101 Correct 15 ms 30728 KB Output is correct
102 Correct 15 ms 30716 KB Output is correct