답안 #1109864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1109864 2024-11-08T01:39:39 Z ljtunas Lamps (JOI19_lamps) C++17
100 / 100
266 ms 192496 KB
// author : anhtun_hi , nqg
#include <bits/stdc++.h>
#define ll long long
#define ii pair<ll, ll>
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define reset(h, v)    memset(h, v, sizeof h)
#define Forv(i, a)     for(auto& i : a)
#define For(i, a, b)   for(int i = a; i <= b; ++i)
#define Ford(i, a, b)  for(int i = a; i >= b; --i)
#define c_bit(i)     __builtin_popcountll(i)
#define Bit(mask, i)    ((mask >> i) & 1LL)
#define onbit(mask, i)  ((mask) bitor (1LL << i))
#define offbit(mask, i) ((mask) &~ (1LL << i))
using namespace std;
namespace std {
    template <typename T, int D>
    struct _vector : public vector <_vector <T, D - 1>> {
        static_assert(D >= 1, "Dimension must be positive!");
        template <typename... Args>
        _vector(int n = 0, Args... args) : vector <_vector <T, D - 1>> (n, _vector <T, D - 1> (args...)) {}
    };
    template <typename T> struct _vector <T, 1> : public vector <T> {
        _vector(int n = 0, const T& val = T()) : vector <T> (n, val) {}
    };
    template <class A, class B> bool minimize(A &a, B b){return a > b ? a = b, true : false;}
    template <class A, class B> bool maximize(A &a, B b){return a < b ? a = b, true : false;}
}
const int dx[] = {0, 0, +1, -1}, dy[] = {-1, +1, 0, 0}, LOG = 20, base = 311, inf = 1e9 + 5;
const int MAXN = 1e6 + 5;
const  ll  mod = 1e9 + 7;
const  ll   oo = 1e18;

//#define int long long

int n; ll dp[MAXN][2][2][2];
string a, b;

ll solve(int i, bool j, bool h, bool k)
{
    if(i > n) return 0;
    if (~dp[i][j][h][k]) return dp[i][j][h][k];
    ll res = oo;
    int cur = a[i] - '0';
    if(j) cur = 0;
    if(h) cur = 1;
    if(k) cur ^= 1;
    if(cur == b[i] - '0'){
        For(_j, 0, 1) For(_h, 0, 1) if(!(_j == _h &&_j == 1)) For(_k, 0, 1){
            minimize(res, solve(i + 1, _j, _h, _k) + (_j && _j != j) + (_h && _h != h) + (_k && _k != k));
        }
    }
    return dp[i][j][h][k] = res;
}

void Solve() {
    cin >> n >> a >> b;
    a = '0' + a, b = '0' + b;
    reset(dp, -1);
    cout << solve(0, 0, 0, 0) << '\n';
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(0);
    if(fopen("JOI19_lamps.inp", "r")) {
        freopen("JOI19_lamps.inp", "r", stdin);
        freopen("JOI19_lamps.out", "w", stdout);
    }

    int t = 1;
//    cin >> t;

    for (int test = 1; test <= t; test++) {
        Solve();
    }
    return 0;
}

Compilation message

lamp.cpp: In function 'int32_t main()':
lamp.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen("JOI19_lamps.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:68:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |         freopen("JOI19_lamps.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 63056 KB Output is correct
2 Correct 9 ms 63056 KB Output is correct
3 Correct 11 ms 62892 KB Output is correct
4 Correct 9 ms 62924 KB Output is correct
5 Correct 9 ms 63056 KB Output is correct
6 Correct 9 ms 63056 KB Output is correct
7 Correct 10 ms 63056 KB Output is correct
8 Correct 9 ms 63056 KB Output is correct
9 Correct 9 ms 63056 KB Output is correct
10 Correct 9 ms 63056 KB Output is correct
11 Correct 9 ms 62940 KB Output is correct
12 Correct 9 ms 63056 KB Output is correct
13 Correct 9 ms 63056 KB Output is correct
14 Correct 9 ms 63224 KB Output is correct
15 Correct 9 ms 63056 KB Output is correct
16 Correct 9 ms 63056 KB Output is correct
17 Correct 9 ms 63056 KB Output is correct
18 Correct 9 ms 62888 KB Output is correct
19 Correct 9 ms 63056 KB Output is correct
20 Correct 9 ms 63056 KB Output is correct
21 Correct 9 ms 63056 KB Output is correct
22 Correct 9 ms 63072 KB Output is correct
23 Correct 9 ms 62952 KB Output is correct
24 Correct 9 ms 63056 KB Output is correct
25 Correct 10 ms 63056 KB Output is correct
26 Correct 9 ms 63056 KB Output is correct
27 Correct 10 ms 63056 KB Output is correct
28 Correct 9 ms 63056 KB Output is correct
29 Correct 9 ms 63056 KB Output is correct
30 Correct 9 ms 63056 KB Output is correct
31 Correct 10 ms 63056 KB Output is correct
32 Correct 10 ms 63056 KB Output is correct
33 Correct 10 ms 63056 KB Output is correct
34 Correct 10 ms 63056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 63056 KB Output is correct
2 Correct 9 ms 63056 KB Output is correct
3 Correct 11 ms 62892 KB Output is correct
4 Correct 9 ms 62924 KB Output is correct
5 Correct 9 ms 63056 KB Output is correct
6 Correct 9 ms 63056 KB Output is correct
7 Correct 10 ms 63056 KB Output is correct
8 Correct 9 ms 63056 KB Output is correct
9 Correct 9 ms 63056 KB Output is correct
10 Correct 9 ms 63056 KB Output is correct
11 Correct 9 ms 62940 KB Output is correct
12 Correct 9 ms 63056 KB Output is correct
13 Correct 9 ms 63056 KB Output is correct
14 Correct 9 ms 63224 KB Output is correct
15 Correct 9 ms 63056 KB Output is correct
16 Correct 9 ms 63056 KB Output is correct
17 Correct 9 ms 63056 KB Output is correct
18 Correct 9 ms 62888 KB Output is correct
19 Correct 9 ms 63056 KB Output is correct
20 Correct 9 ms 63056 KB Output is correct
21 Correct 9 ms 63056 KB Output is correct
22 Correct 9 ms 63072 KB Output is correct
23 Correct 9 ms 62952 KB Output is correct
24 Correct 9 ms 63056 KB Output is correct
25 Correct 10 ms 63056 KB Output is correct
26 Correct 9 ms 63056 KB Output is correct
27 Correct 10 ms 63056 KB Output is correct
28 Correct 9 ms 63056 KB Output is correct
29 Correct 9 ms 63056 KB Output is correct
30 Correct 9 ms 63056 KB Output is correct
31 Correct 10 ms 63056 KB Output is correct
32 Correct 10 ms 63056 KB Output is correct
33 Correct 10 ms 63056 KB Output is correct
34 Correct 10 ms 63056 KB Output is correct
35 Correct 10 ms 63312 KB Output is correct
36 Correct 10 ms 63312 KB Output is correct
37 Correct 9 ms 63312 KB Output is correct
38 Correct 10 ms 63312 KB Output is correct
39 Correct 10 ms 63312 KB Output is correct
40 Correct 10 ms 63188 KB Output is correct
41 Correct 11 ms 63312 KB Output is correct
42 Correct 10 ms 63312 KB Output is correct
43 Correct 10 ms 63312 KB Output is correct
44 Correct 10 ms 63312 KB Output is correct
45 Correct 11 ms 63312 KB Output is correct
46 Correct 10 ms 63312 KB Output is correct
47 Correct 10 ms 63312 KB Output is correct
48 Correct 10 ms 63312 KB Output is correct
49 Correct 9 ms 63312 KB Output is correct
50 Correct 10 ms 63312 KB Output is correct
51 Correct 9 ms 63312 KB Output is correct
52 Correct 10 ms 63312 KB Output is correct
53 Correct 10 ms 63312 KB Output is correct
54 Correct 12 ms 63324 KB Output is correct
55 Correct 10 ms 63312 KB Output is correct
56 Correct 10 ms 63312 KB Output is correct
57 Correct 9 ms 63312 KB Output is correct
58 Correct 10 ms 63312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 63056 KB Output is correct
2 Correct 8 ms 62964 KB Output is correct
3 Correct 9 ms 63056 KB Output is correct
4 Correct 8 ms 63056 KB Output is correct
5 Correct 9 ms 63056 KB Output is correct
6 Correct 9 ms 62964 KB Output is correct
7 Correct 232 ms 192300 KB Output is correct
8 Correct 244 ms 192308 KB Output is correct
9 Correct 231 ms 192172 KB Output is correct
10 Correct 229 ms 192496 KB Output is correct
11 Correct 224 ms 192252 KB Output is correct
12 Correct 238 ms 192288 KB Output is correct
13 Correct 232 ms 192336 KB Output is correct
14 Correct 236 ms 192240 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 63056 KB Output is correct
2 Correct 9 ms 63056 KB Output is correct
3 Correct 11 ms 62892 KB Output is correct
4 Correct 9 ms 62924 KB Output is correct
5 Correct 9 ms 63056 KB Output is correct
6 Correct 9 ms 63056 KB Output is correct
7 Correct 10 ms 63056 KB Output is correct
8 Correct 9 ms 63056 KB Output is correct
9 Correct 9 ms 63056 KB Output is correct
10 Correct 9 ms 63056 KB Output is correct
11 Correct 9 ms 62940 KB Output is correct
12 Correct 9 ms 63056 KB Output is correct
13 Correct 9 ms 63056 KB Output is correct
14 Correct 9 ms 63224 KB Output is correct
15 Correct 9 ms 63056 KB Output is correct
16 Correct 9 ms 63056 KB Output is correct
17 Correct 9 ms 63056 KB Output is correct
18 Correct 9 ms 62888 KB Output is correct
19 Correct 9 ms 63056 KB Output is correct
20 Correct 9 ms 63056 KB Output is correct
21 Correct 9 ms 63056 KB Output is correct
22 Correct 9 ms 63072 KB Output is correct
23 Correct 9 ms 62952 KB Output is correct
24 Correct 9 ms 63056 KB Output is correct
25 Correct 10 ms 63056 KB Output is correct
26 Correct 9 ms 63056 KB Output is correct
27 Correct 10 ms 63056 KB Output is correct
28 Correct 9 ms 63056 KB Output is correct
29 Correct 9 ms 63056 KB Output is correct
30 Correct 9 ms 63056 KB Output is correct
31 Correct 10 ms 63056 KB Output is correct
32 Correct 10 ms 63056 KB Output is correct
33 Correct 10 ms 63056 KB Output is correct
34 Correct 10 ms 63056 KB Output is correct
35 Correct 10 ms 63312 KB Output is correct
36 Correct 10 ms 63312 KB Output is correct
37 Correct 9 ms 63312 KB Output is correct
38 Correct 10 ms 63312 KB Output is correct
39 Correct 10 ms 63312 KB Output is correct
40 Correct 10 ms 63188 KB Output is correct
41 Correct 11 ms 63312 KB Output is correct
42 Correct 10 ms 63312 KB Output is correct
43 Correct 10 ms 63312 KB Output is correct
44 Correct 10 ms 63312 KB Output is correct
45 Correct 11 ms 63312 KB Output is correct
46 Correct 10 ms 63312 KB Output is correct
47 Correct 10 ms 63312 KB Output is correct
48 Correct 10 ms 63312 KB Output is correct
49 Correct 9 ms 63312 KB Output is correct
50 Correct 10 ms 63312 KB Output is correct
51 Correct 9 ms 63312 KB Output is correct
52 Correct 10 ms 63312 KB Output is correct
53 Correct 10 ms 63312 KB Output is correct
54 Correct 12 ms 63324 KB Output is correct
55 Correct 10 ms 63312 KB Output is correct
56 Correct 10 ms 63312 KB Output is correct
57 Correct 9 ms 63312 KB Output is correct
58 Correct 10 ms 63312 KB Output is correct
59 Correct 9 ms 63056 KB Output is correct
60 Correct 8 ms 62964 KB Output is correct
61 Correct 9 ms 63056 KB Output is correct
62 Correct 8 ms 63056 KB Output is correct
63 Correct 9 ms 63056 KB Output is correct
64 Correct 9 ms 62964 KB Output is correct
65 Correct 232 ms 192300 KB Output is correct
66 Correct 244 ms 192308 KB Output is correct
67 Correct 231 ms 192172 KB Output is correct
68 Correct 229 ms 192496 KB Output is correct
69 Correct 224 ms 192252 KB Output is correct
70 Correct 238 ms 192288 KB Output is correct
71 Correct 232 ms 192336 KB Output is correct
72 Correct 236 ms 192240 KB Output is correct
73 Correct 227 ms 192244 KB Output is correct
74 Correct 237 ms 192236 KB Output is correct
75 Correct 235 ms 192240 KB Output is correct
76 Correct 234 ms 192236 KB Output is correct
77 Correct 237 ms 192240 KB Output is correct
78 Correct 245 ms 192244 KB Output is correct
79 Correct 222 ms 192232 KB Output is correct
80 Correct 246 ms 192368 KB Output is correct
81 Correct 254 ms 192244 KB Output is correct
82 Correct 244 ms 192132 KB Output is correct
83 Correct 266 ms 192312 KB Output is correct
84 Correct 241 ms 192244 KB Output is correct
85 Correct 246 ms 192356 KB Output is correct
86 Correct 247 ms 192184 KB Output is correct
87 Correct 239 ms 192240 KB Output is correct
88 Correct 227 ms 192244 KB Output is correct
89 Correct 226 ms 192492 KB Output is correct
90 Correct 237 ms 192240 KB Output is correct
91 Correct 228 ms 192248 KB Output is correct
92 Correct 229 ms 192320 KB Output is correct
93 Correct 221 ms 192240 KB Output is correct
94 Correct 244 ms 192244 KB Output is correct
95 Correct 222 ms 192256 KB Output is correct
96 Correct 221 ms 192204 KB Output is correct
97 Correct 234 ms 192444 KB Output is correct
98 Correct 229 ms 192124 KB Output is correct
99 Correct 225 ms 192496 KB Output is correct
100 Correct 245 ms 192264 KB Output is correct
101 Correct 248 ms 192244 KB Output is correct
102 Correct 237 ms 192244 KB Output is correct