# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1092960 |
2024-09-25T14:06:52 Z |
anhthi |
Lamps (JOI19_lamps) |
C++14 |
|
224 ms |
67228 KB |
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
#define mp(x, y) make_pair(x, y)
#define sz(v) ((int) (v).size())
#define all(v) (v).begin(), (v).end()
#define MASK(i) (1LL << (i))
#define BIT(x, y) (((x) >> (y)) & 1)
#define pb push_back
#define max_rng *max_element
#define min_rng *min_element
#define rep(i, n) for(int i = 1, _n = (n); i <= _n; ++i)
#define forn(i, a, b) for(int i = (a), _b = (b); i <= _b; ++i)
#define ford(i, a, b) for(int i = (a), _b = (b); i >= _b; --i)
template <class X, class Y>
inline bool maximize(X &x, Y y) {
return (x < y ? x = y, true : false);
}
template <class X, class Y>
inline bool minimize(X &x, Y y) {
return (x > y ? x = y, true : false);
}
template <class X>
inline void compress(vector<X> &a) {
sort(all(a));
a.resize(unique(all(a)) - a.begin());
}
int ctz(ll x) { return __builtin_ctzll(x); }
int lg(ll x) { return 63 - __builtin_clzll(x); }
int popcount(ll x) { return __builtin_popcount(x); }
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) {
return l + abs((ll) rng()) % (r - l + 1);
}
const ll oo = (ll) 1e17;
const int inf = (int) 1e9, mod = (int) 1e9 + 7;
const int mxn = 1e6 + 5, mxm = 2e2 + 5, base = 307, LOG = 20;
void add(int &x, int y) { x += y; if (x >= mod) x -= mod; }
void sub(int &x, int y) { x -= y; if (x < 0) x += mod; }
int n;
string A, B;
vector<vector<int>> op;
int trans[16][2];
int f[16][16], g[10][10];
int dp[mxn][16];
void prepare() {
vector<int> p(3);
iota(all(p), 0);
do {
vector<int> cur;
for (int v : p) {
cur.pb(v);
op.pb(cur);
}
} while (next_permutation(all(p)));
op.pb(vector<int>());
compress(op);
memset(f, 0x3f, sizeof f);
forn(i, 0, sz(op) - 1) forn(j, 0, sz(op) - 1) {
const vector<int> &a = op[i];
const vector<int> &b = op[j];
forn(x, 1, sz(a)) forn(y, 1, sz(b)) {
g[x][y] = max(g[x][y-1], g[x-1][y]);
if (a[x - 1] == b[y - 1])
maximize(g[x][y], g[x - 1][y - 1] + 1);
}
f[i][j] = sz(b) - g[sz(a)][sz(b)];
}
forn(i, 0, sz(op) - 1) forn(j, 0, 1) {
int bit = j;
for (int o : op[i]) {
if (!o) bit = 0;
else if (o == 1) bit = 1;
else bit ^= 1;
}
trans[i][j] = bit;
}
return;
}
int main(void) {
// think what before starting to code
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#define TASK "partner"
if (fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
cin >> n >> A >> B;
prepare();
memset(dp, 0x3f, sizeof dp);
dp[0][0] = 0;
rep(i, n) {
int d1 = A[i-1] - '0', d2 = B[i-1] - '0';
forn(cur, 0, 15) if (trans[cur][d1] == d2) {
forn(pre, 0, 15) {
minimize(dp[i][cur], dp[i - 1][pre] + f[pre][cur]);
}
}
}
cout << min_rng(dp[n], dp[n] + 16);
return 0;
}
Compilation message
lamp.cpp: In function 'int main()':
lamp.cpp:112:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
112 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
lamp.cpp:113:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
63068 KB |
Output is correct |
2 |
Correct |
30 ms |
63068 KB |
Output is correct |
3 |
Correct |
31 ms |
62912 KB |
Output is correct |
4 |
Correct |
30 ms |
63068 KB |
Output is correct |
5 |
Correct |
28 ms |
63056 KB |
Output is correct |
6 |
Correct |
30 ms |
63056 KB |
Output is correct |
7 |
Correct |
29 ms |
63064 KB |
Output is correct |
8 |
Correct |
28 ms |
63320 KB |
Output is correct |
9 |
Correct |
27 ms |
63048 KB |
Output is correct |
10 |
Correct |
28 ms |
63060 KB |
Output is correct |
11 |
Correct |
33 ms |
63060 KB |
Output is correct |
12 |
Correct |
28 ms |
63068 KB |
Output is correct |
13 |
Correct |
29 ms |
63060 KB |
Output is correct |
14 |
Correct |
25 ms |
63068 KB |
Output is correct |
15 |
Correct |
24 ms |
63068 KB |
Output is correct |
16 |
Correct |
24 ms |
62908 KB |
Output is correct |
17 |
Correct |
29 ms |
63064 KB |
Output is correct |
18 |
Correct |
25 ms |
63064 KB |
Output is correct |
19 |
Correct |
24 ms |
62900 KB |
Output is correct |
20 |
Correct |
27 ms |
63056 KB |
Output is correct |
21 |
Correct |
26 ms |
62960 KB |
Output is correct |
22 |
Correct |
29 ms |
62980 KB |
Output is correct |
23 |
Correct |
28 ms |
63068 KB |
Output is correct |
24 |
Correct |
28 ms |
62980 KB |
Output is correct |
25 |
Correct |
30 ms |
63052 KB |
Output is correct |
26 |
Correct |
28 ms |
63060 KB |
Output is correct |
27 |
Correct |
29 ms |
63068 KB |
Output is correct |
28 |
Correct |
28 ms |
62840 KB |
Output is correct |
29 |
Correct |
27 ms |
63068 KB |
Output is correct |
30 |
Correct |
29 ms |
63056 KB |
Output is correct |
31 |
Correct |
29 ms |
62944 KB |
Output is correct |
32 |
Correct |
29 ms |
63008 KB |
Output is correct |
33 |
Correct |
28 ms |
63064 KB |
Output is correct |
34 |
Correct |
30 ms |
63056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
63068 KB |
Output is correct |
2 |
Correct |
30 ms |
63068 KB |
Output is correct |
3 |
Correct |
31 ms |
62912 KB |
Output is correct |
4 |
Correct |
30 ms |
63068 KB |
Output is correct |
5 |
Correct |
28 ms |
63056 KB |
Output is correct |
6 |
Correct |
30 ms |
63056 KB |
Output is correct |
7 |
Correct |
29 ms |
63064 KB |
Output is correct |
8 |
Correct |
28 ms |
63320 KB |
Output is correct |
9 |
Correct |
27 ms |
63048 KB |
Output is correct |
10 |
Correct |
28 ms |
63060 KB |
Output is correct |
11 |
Correct |
33 ms |
63060 KB |
Output is correct |
12 |
Correct |
28 ms |
63068 KB |
Output is correct |
13 |
Correct |
29 ms |
63060 KB |
Output is correct |
14 |
Correct |
25 ms |
63068 KB |
Output is correct |
15 |
Correct |
24 ms |
63068 KB |
Output is correct |
16 |
Correct |
24 ms |
62908 KB |
Output is correct |
17 |
Correct |
29 ms |
63064 KB |
Output is correct |
18 |
Correct |
25 ms |
63064 KB |
Output is correct |
19 |
Correct |
24 ms |
62900 KB |
Output is correct |
20 |
Correct |
27 ms |
63056 KB |
Output is correct |
21 |
Correct |
26 ms |
62960 KB |
Output is correct |
22 |
Correct |
29 ms |
62980 KB |
Output is correct |
23 |
Correct |
28 ms |
63068 KB |
Output is correct |
24 |
Correct |
28 ms |
62980 KB |
Output is correct |
25 |
Correct |
30 ms |
63052 KB |
Output is correct |
26 |
Correct |
28 ms |
63060 KB |
Output is correct |
27 |
Correct |
29 ms |
63068 KB |
Output is correct |
28 |
Correct |
28 ms |
62840 KB |
Output is correct |
29 |
Correct |
27 ms |
63068 KB |
Output is correct |
30 |
Correct |
29 ms |
63056 KB |
Output is correct |
31 |
Correct |
29 ms |
62944 KB |
Output is correct |
32 |
Correct |
29 ms |
63008 KB |
Output is correct |
33 |
Correct |
28 ms |
63064 KB |
Output is correct |
34 |
Correct |
30 ms |
63056 KB |
Output is correct |
35 |
Correct |
29 ms |
63060 KB |
Output is correct |
36 |
Correct |
29 ms |
63056 KB |
Output is correct |
37 |
Correct |
29 ms |
63060 KB |
Output is correct |
38 |
Correct |
28 ms |
63060 KB |
Output is correct |
39 |
Correct |
29 ms |
63060 KB |
Output is correct |
40 |
Correct |
28 ms |
63064 KB |
Output is correct |
41 |
Correct |
28 ms |
63060 KB |
Output is correct |
42 |
Correct |
28 ms |
62916 KB |
Output is correct |
43 |
Correct |
28 ms |
62860 KB |
Output is correct |
44 |
Correct |
28 ms |
62864 KB |
Output is correct |
45 |
Correct |
29 ms |
62860 KB |
Output is correct |
46 |
Correct |
29 ms |
63056 KB |
Output is correct |
47 |
Correct |
31 ms |
62972 KB |
Output is correct |
48 |
Correct |
29 ms |
63068 KB |
Output is correct |
49 |
Correct |
28 ms |
63068 KB |
Output is correct |
50 |
Correct |
30 ms |
62852 KB |
Output is correct |
51 |
Correct |
30 ms |
63060 KB |
Output is correct |
52 |
Correct |
29 ms |
63056 KB |
Output is correct |
53 |
Correct |
30 ms |
63060 KB |
Output is correct |
54 |
Correct |
29 ms |
63060 KB |
Output is correct |
55 |
Correct |
30 ms |
63056 KB |
Output is correct |
56 |
Correct |
29 ms |
63060 KB |
Output is correct |
57 |
Correct |
29 ms |
63056 KB |
Output is correct |
58 |
Correct |
28 ms |
63068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
63064 KB |
Output is correct |
2 |
Correct |
30 ms |
63056 KB |
Output is correct |
3 |
Correct |
34 ms |
62924 KB |
Output is correct |
4 |
Correct |
31 ms |
63060 KB |
Output is correct |
5 |
Correct |
29 ms |
63060 KB |
Output is correct |
6 |
Correct |
28 ms |
63060 KB |
Output is correct |
7 |
Correct |
190 ms |
66868 KB |
Output is correct |
8 |
Correct |
185 ms |
67024 KB |
Output is correct |
9 |
Correct |
192 ms |
66976 KB |
Output is correct |
10 |
Correct |
205 ms |
66984 KB |
Output is correct |
11 |
Correct |
191 ms |
66980 KB |
Output is correct |
12 |
Correct |
182 ms |
66980 KB |
Output is correct |
13 |
Correct |
182 ms |
66980 KB |
Output is correct |
14 |
Correct |
187 ms |
67128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
63068 KB |
Output is correct |
2 |
Correct |
30 ms |
63068 KB |
Output is correct |
3 |
Correct |
31 ms |
62912 KB |
Output is correct |
4 |
Correct |
30 ms |
63068 KB |
Output is correct |
5 |
Correct |
28 ms |
63056 KB |
Output is correct |
6 |
Correct |
30 ms |
63056 KB |
Output is correct |
7 |
Correct |
29 ms |
63064 KB |
Output is correct |
8 |
Correct |
28 ms |
63320 KB |
Output is correct |
9 |
Correct |
27 ms |
63048 KB |
Output is correct |
10 |
Correct |
28 ms |
63060 KB |
Output is correct |
11 |
Correct |
33 ms |
63060 KB |
Output is correct |
12 |
Correct |
28 ms |
63068 KB |
Output is correct |
13 |
Correct |
29 ms |
63060 KB |
Output is correct |
14 |
Correct |
25 ms |
63068 KB |
Output is correct |
15 |
Correct |
24 ms |
63068 KB |
Output is correct |
16 |
Correct |
24 ms |
62908 KB |
Output is correct |
17 |
Correct |
29 ms |
63064 KB |
Output is correct |
18 |
Correct |
25 ms |
63064 KB |
Output is correct |
19 |
Correct |
24 ms |
62900 KB |
Output is correct |
20 |
Correct |
27 ms |
63056 KB |
Output is correct |
21 |
Correct |
26 ms |
62960 KB |
Output is correct |
22 |
Correct |
29 ms |
62980 KB |
Output is correct |
23 |
Correct |
28 ms |
63068 KB |
Output is correct |
24 |
Correct |
28 ms |
62980 KB |
Output is correct |
25 |
Correct |
30 ms |
63052 KB |
Output is correct |
26 |
Correct |
28 ms |
63060 KB |
Output is correct |
27 |
Correct |
29 ms |
63068 KB |
Output is correct |
28 |
Correct |
28 ms |
62840 KB |
Output is correct |
29 |
Correct |
27 ms |
63068 KB |
Output is correct |
30 |
Correct |
29 ms |
63056 KB |
Output is correct |
31 |
Correct |
29 ms |
62944 KB |
Output is correct |
32 |
Correct |
29 ms |
63008 KB |
Output is correct |
33 |
Correct |
28 ms |
63064 KB |
Output is correct |
34 |
Correct |
30 ms |
63056 KB |
Output is correct |
35 |
Correct |
29 ms |
63060 KB |
Output is correct |
36 |
Correct |
29 ms |
63056 KB |
Output is correct |
37 |
Correct |
29 ms |
63060 KB |
Output is correct |
38 |
Correct |
28 ms |
63060 KB |
Output is correct |
39 |
Correct |
29 ms |
63060 KB |
Output is correct |
40 |
Correct |
28 ms |
63064 KB |
Output is correct |
41 |
Correct |
28 ms |
63060 KB |
Output is correct |
42 |
Correct |
28 ms |
62916 KB |
Output is correct |
43 |
Correct |
28 ms |
62860 KB |
Output is correct |
44 |
Correct |
28 ms |
62864 KB |
Output is correct |
45 |
Correct |
29 ms |
62860 KB |
Output is correct |
46 |
Correct |
29 ms |
63056 KB |
Output is correct |
47 |
Correct |
31 ms |
62972 KB |
Output is correct |
48 |
Correct |
29 ms |
63068 KB |
Output is correct |
49 |
Correct |
28 ms |
63068 KB |
Output is correct |
50 |
Correct |
30 ms |
62852 KB |
Output is correct |
51 |
Correct |
30 ms |
63060 KB |
Output is correct |
52 |
Correct |
29 ms |
63056 KB |
Output is correct |
53 |
Correct |
30 ms |
63060 KB |
Output is correct |
54 |
Correct |
29 ms |
63060 KB |
Output is correct |
55 |
Correct |
30 ms |
63056 KB |
Output is correct |
56 |
Correct |
29 ms |
63060 KB |
Output is correct |
57 |
Correct |
29 ms |
63056 KB |
Output is correct |
58 |
Correct |
28 ms |
63068 KB |
Output is correct |
59 |
Correct |
29 ms |
63064 KB |
Output is correct |
60 |
Correct |
30 ms |
63056 KB |
Output is correct |
61 |
Correct |
34 ms |
62924 KB |
Output is correct |
62 |
Correct |
31 ms |
63060 KB |
Output is correct |
63 |
Correct |
29 ms |
63060 KB |
Output is correct |
64 |
Correct |
28 ms |
63060 KB |
Output is correct |
65 |
Correct |
190 ms |
66868 KB |
Output is correct |
66 |
Correct |
185 ms |
67024 KB |
Output is correct |
67 |
Correct |
192 ms |
66976 KB |
Output is correct |
68 |
Correct |
205 ms |
66984 KB |
Output is correct |
69 |
Correct |
191 ms |
66980 KB |
Output is correct |
70 |
Correct |
182 ms |
66980 KB |
Output is correct |
71 |
Correct |
182 ms |
66980 KB |
Output is correct |
72 |
Correct |
187 ms |
67128 KB |
Output is correct |
73 |
Correct |
194 ms |
66992 KB |
Output is correct |
74 |
Correct |
184 ms |
67100 KB |
Output is correct |
75 |
Correct |
184 ms |
67060 KB |
Output is correct |
76 |
Correct |
181 ms |
66980 KB |
Output is correct |
77 |
Correct |
195 ms |
66976 KB |
Output is correct |
78 |
Correct |
192 ms |
67016 KB |
Output is correct |
79 |
Correct |
185 ms |
66984 KB |
Output is correct |
80 |
Correct |
181 ms |
66932 KB |
Output is correct |
81 |
Correct |
191 ms |
67228 KB |
Output is correct |
82 |
Correct |
196 ms |
67112 KB |
Output is correct |
83 |
Correct |
197 ms |
66984 KB |
Output is correct |
84 |
Correct |
207 ms |
66992 KB |
Output is correct |
85 |
Correct |
198 ms |
67120 KB |
Output is correct |
86 |
Correct |
195 ms |
67120 KB |
Output is correct |
87 |
Correct |
196 ms |
66980 KB |
Output is correct |
88 |
Correct |
196 ms |
67120 KB |
Output is correct |
89 |
Correct |
193 ms |
66932 KB |
Output is correct |
90 |
Correct |
190 ms |
66992 KB |
Output is correct |
91 |
Correct |
220 ms |
67052 KB |
Output is correct |
92 |
Correct |
208 ms |
66952 KB |
Output is correct |
93 |
Correct |
216 ms |
66980 KB |
Output is correct |
94 |
Correct |
211 ms |
66976 KB |
Output is correct |
95 |
Correct |
208 ms |
66984 KB |
Output is correct |
96 |
Correct |
198 ms |
66992 KB |
Output is correct |
97 |
Correct |
198 ms |
67116 KB |
Output is correct |
98 |
Correct |
211 ms |
67120 KB |
Output is correct |
99 |
Correct |
224 ms |
66980 KB |
Output is correct |
100 |
Correct |
217 ms |
66980 KB |
Output is correct |
101 |
Correct |
209 ms |
67224 KB |
Output is correct |
102 |
Correct |
221 ms |
67116 KB |
Output is correct |