답안 #954194

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954194 2024-03-27T11:33:25 Z browntoad Lamps (JOI19_lamps) C++14
100 / 100
17 ms 19304 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 double PI=acos(-1);
const ll maxn = 1e6+5;
const int inf = 1<<30;
 
inline char gc()
{
    const static int SZ = 1 << 16;
    static char buf[SZ], *p1, *p2;
    if (p1 == p2 && (p2 = buf + fread(p1 = buf, 1, SZ, stdin), p1 == p2))
        return -1;
    return *p1++;
}
void rd() {}
template <typename T, typename... U>
void rd(T &x, U &...y)
{
    x = 0;
    bool f = 0;
    char c = gc();
    while (!isdigit(c))
        f ^= !(c ^ 45), c = gc();
    while (isdigit(c))
        x = (x << 1) + (x << 3) + (c ^ 48), c = gc();
    f && (x = -x), rd(y...);
}
 
template <typename T>
void prt(T x)
{
    if (x < 0)
        putchar('-'), x = -x;
    if (x > 9)
        prt(x / 10);
    putchar((x % 10) ^ 48);
}
 
int dp[maxn][3];
bool chan[maxn][3];
int n;
char a[maxn];
char b[maxn];
 
signed main(){
    IOS();
    scanf("%d", &n);
    scanf("%s%s",a+1,b+1);
    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]));
            }
        }
    }
  	int ans = min({dp[n][0], dp[n][1], dp[n][2]});
    prt(ans);
 
}

Compilation message

lamp.cpp: In function 'int main()':
lamp.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
lamp.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     scanf("%s%s",a+1,b+1);
      |     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4572 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4572 KB Output is correct
27 Correct 1 ms 4452 KB Output is correct
28 Correct 1 ms 4644 KB Output is correct
29 Correct 1 ms 4456 KB Output is correct
30 Correct 1 ms 4456 KB Output is correct
31 Correct 1 ms 4456 KB Output is correct
32 Correct 1 ms 4452 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4572 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4572 KB Output is correct
27 Correct 1 ms 4452 KB Output is correct
28 Correct 1 ms 4644 KB Output is correct
29 Correct 1 ms 4456 KB Output is correct
30 Correct 1 ms 4456 KB Output is correct
31 Correct 1 ms 4456 KB Output is correct
32 Correct 1 ms 4452 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4568 KB Output is correct
35 Correct 1 ms 4448 KB Output is correct
36 Correct 1 ms 4448 KB Output is correct
37 Correct 1 ms 4452 KB Output is correct
38 Correct 1 ms 4448 KB Output is correct
39 Correct 1 ms 4448 KB Output is correct
40 Correct 1 ms 4448 KB Output is correct
41 Correct 1 ms 4452 KB Output is correct
42 Correct 1 ms 4448 KB Output is correct
43 Correct 1 ms 4448 KB Output is correct
44 Correct 1 ms 4572 KB Output is correct
45 Correct 1 ms 4452 KB Output is correct
46 Correct 1 ms 4448 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4448 KB Output is correct
49 Correct 1 ms 4448 KB Output is correct
50 Correct 1 ms 4460 KB Output is correct
51 Correct 1 ms 4452 KB Output is correct
52 Correct 1 ms 4452 KB Output is correct
53 Correct 1 ms 4452 KB Output is correct
54 Correct 1 ms 4448 KB Output is correct
55 Correct 1 ms 4564 KB Output is correct
56 Correct 1 ms 4448 KB Output is correct
57 Correct 1 ms 4452 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4452 KB Output is correct
2 Correct 1 ms 4452 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4448 KB Output is correct
5 Correct 1 ms 4452 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 17 ms 18792 KB Output is correct
8 Correct 16 ms 19036 KB Output is correct
9 Correct 14 ms 19028 KB Output is correct
10 Correct 14 ms 19044 KB Output is correct
11 Correct 14 ms 18912 KB Output is correct
12 Correct 14 ms 19028 KB Output is correct
13 Correct 14 ms 19040 KB Output is correct
14 Correct 14 ms 19044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4572 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4572 KB Output is correct
27 Correct 1 ms 4452 KB Output is correct
28 Correct 1 ms 4644 KB Output is correct
29 Correct 1 ms 4456 KB Output is correct
30 Correct 1 ms 4456 KB Output is correct
31 Correct 1 ms 4456 KB Output is correct
32 Correct 1 ms 4452 KB Output is correct
33 Correct 1 ms 4448 KB Output is correct
34 Correct 1 ms 4568 KB Output is correct
35 Correct 1 ms 4448 KB Output is correct
36 Correct 1 ms 4448 KB Output is correct
37 Correct 1 ms 4452 KB Output is correct
38 Correct 1 ms 4448 KB Output is correct
39 Correct 1 ms 4448 KB Output is correct
40 Correct 1 ms 4448 KB Output is correct
41 Correct 1 ms 4452 KB Output is correct
42 Correct 1 ms 4448 KB Output is correct
43 Correct 1 ms 4448 KB Output is correct
44 Correct 1 ms 4572 KB Output is correct
45 Correct 1 ms 4452 KB Output is correct
46 Correct 1 ms 4448 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4448 KB Output is correct
49 Correct 1 ms 4448 KB Output is correct
50 Correct 1 ms 4460 KB Output is correct
51 Correct 1 ms 4452 KB Output is correct
52 Correct 1 ms 4452 KB Output is correct
53 Correct 1 ms 4452 KB Output is correct
54 Correct 1 ms 4448 KB Output is correct
55 Correct 1 ms 4564 KB Output is correct
56 Correct 1 ms 4448 KB Output is correct
57 Correct 1 ms 4452 KB Output is correct
58 Correct 1 ms 4444 KB Output is correct
59 Correct 1 ms 4452 KB Output is correct
60 Correct 1 ms 4452 KB Output is correct
61 Correct 1 ms 4444 KB Output is correct
62 Correct 1 ms 4448 KB Output is correct
63 Correct 1 ms 4452 KB Output is correct
64 Correct 1 ms 4444 KB Output is correct
65 Correct 17 ms 18792 KB Output is correct
66 Correct 16 ms 19036 KB Output is correct
67 Correct 14 ms 19028 KB Output is correct
68 Correct 14 ms 19044 KB Output is correct
69 Correct 14 ms 18912 KB Output is correct
70 Correct 14 ms 19028 KB Output is correct
71 Correct 14 ms 19040 KB Output is correct
72 Correct 14 ms 19044 KB Output is correct
73 Correct 14 ms 18944 KB Output is correct
74 Correct 14 ms 18816 KB Output is correct
75 Correct 14 ms 19040 KB Output is correct
76 Correct 14 ms 19284 KB Output is correct
77 Correct 14 ms 18884 KB Output is correct
78 Correct 14 ms 19032 KB Output is correct
79 Correct 17 ms 19304 KB Output is correct
80 Correct 14 ms 19008 KB Output is correct
81 Correct 14 ms 19040 KB Output is correct
82 Correct 13 ms 19040 KB Output is correct
83 Correct 14 ms 19044 KB Output is correct
84 Correct 13 ms 19032 KB Output is correct
85 Correct 14 ms 19036 KB Output is correct
86 Correct 14 ms 19048 KB Output is correct
87 Correct 14 ms 18928 KB Output is correct
88 Correct 14 ms 19000 KB Output is correct
89 Correct 15 ms 19048 KB Output is correct
90 Correct 14 ms 19040 KB Output is correct
91 Correct 14 ms 18972 KB Output is correct
92 Correct 14 ms 19056 KB Output is correct
93 Correct 14 ms 19036 KB Output is correct
94 Correct 13 ms 19032 KB Output is correct
95 Correct 16 ms 19044 KB Output is correct
96 Correct 17 ms 19036 KB Output is correct
97 Correct 14 ms 19024 KB Output is correct
98 Correct 14 ms 19024 KB Output is correct
99 Correct 14 ms 19016 KB Output is correct
100 Correct 13 ms 19032 KB Output is correct
101 Correct 14 ms 19292 KB Output is correct
102 Correct 14 ms 19028 KB Output is correct