# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
107662 |
2019-04-25T12:13:29 Z |
Saboon |
Lamps (JOI19_lamps) |
C++14 |
|
1000 ms |
256972 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6 + 10;
int dp[maxn][65];
int mab(int fi, int se, int th){
return fi + se * 4 + 16 * th;
}
int transform(int x, int query){
if (query == 0)
return x;
else if (query == 1)
return 0;
else if (query == 2)
return 1;
else
return 1 ^ x;
}
int transfer(int q, int fi, int se, int th){
q = transform(q, fi);
q = transform(q, se);
q = transform(q, th);
return q;
}
bool C(int x){
return x > 0;
}
int lcs[5][5];
int pd[5][5][5][5][5][5];
int cost(int fi, int se, int th, int all){
int Fi = (all / 1) % 4;
int Se = (all / 4) % 4;
int Th = (all / 16) % 4;
if (pd[fi][se][th][Fi][Se][Th] != -1)
return pd[fi][se][th][Fi][Se][Th];
vector<int> a = {fi, se, th};
vector<int> b = {Fi, Se, Th};
int cnt = C(Fi) + C(Se) + C(Th);
for (int i = 1; i <= 3; i++){
for (int j = 1; j <= 3; j++){
lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
if (a[i - 1] == 0 or b[i - 1] == 0)
continue;
lcs[i][j] = max(lcs[i][j], (lcs[i - 1][j - 1] + 1) * (a[i - 1] == b[j - 1]));
}
}
// cout << fi << " " << se << " " << th << " ----- " << cnt - lcs[3][3] << " -----> " << Fi << " " << Se << " " << Th << endl;
return pd[fi][se][th][Fi][Se][Th] = cnt - lcs[3][3];
}
vector<int> go[2][2];
int main(){
ios_base::sync_with_stdio(false);
memset(pd, -1, sizeof pd);
int n;
string s, t;
cin >> n >> s >> t;
memset(dp, 63, sizeof dp);
dp[0][0] = 0;
int answer = n;
for (int i = 0; i <= 3; i++){
for (int j = 0; j <= 3; j++){
for (int k = 0; k <= 3; k++){
int nex = transfer(0, i, j, k);
go[0][nex].push_back(mab(i, j, k));
nex = transfer(1, i, j, k);
go[1][nex].push_back(mab(i, j, k));
}
}
}
for (int i = 1; i <= n; i++){
int me = (int)(s[i - 1] - '0');
int nex = (int)(t[i - 1] - '0');
for (auto it : go[me][nex]){
for (int x = 0; x <= 3; x++){
for (int y = 0; y <= 3; y++){
for (int z = 0; z <= 3; z++){
dp[i][it] = min(dp[i][it], dp[i - 1][mab(x, y, z)] + cost(x, y, z, it));
}
}
}
if (i == n)
answer = min(answer, dp[i][it]);
}
}
cout << answer << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
254840 KB |
Output is correct |
2 |
Correct |
231 ms |
254712 KB |
Output is correct |
3 |
Correct |
202 ms |
254784 KB |
Output is correct |
4 |
Correct |
214 ms |
254840 KB |
Output is correct |
5 |
Correct |
221 ms |
254840 KB |
Output is correct |
6 |
Correct |
207 ms |
254836 KB |
Output is correct |
7 |
Correct |
197 ms |
254888 KB |
Output is correct |
8 |
Correct |
220 ms |
254840 KB |
Output is correct |
9 |
Correct |
213 ms |
254840 KB |
Output is correct |
10 |
Correct |
212 ms |
254840 KB |
Output is correct |
11 |
Correct |
204 ms |
254840 KB |
Output is correct |
12 |
Correct |
208 ms |
254840 KB |
Output is correct |
13 |
Correct |
205 ms |
254840 KB |
Output is correct |
14 |
Correct |
214 ms |
254812 KB |
Output is correct |
15 |
Correct |
208 ms |
254840 KB |
Output is correct |
16 |
Correct |
228 ms |
254840 KB |
Output is correct |
17 |
Correct |
189 ms |
254840 KB |
Output is correct |
18 |
Correct |
191 ms |
254880 KB |
Output is correct |
19 |
Correct |
233 ms |
254812 KB |
Output is correct |
20 |
Correct |
212 ms |
254840 KB |
Output is correct |
21 |
Correct |
223 ms |
254968 KB |
Output is correct |
22 |
Correct |
223 ms |
254940 KB |
Output is correct |
23 |
Correct |
197 ms |
254840 KB |
Output is correct |
24 |
Correct |
197 ms |
254956 KB |
Output is correct |
25 |
Correct |
220 ms |
254772 KB |
Output is correct |
26 |
Correct |
216 ms |
254840 KB |
Output is correct |
27 |
Correct |
224 ms |
254900 KB |
Output is correct |
28 |
Correct |
212 ms |
254732 KB |
Output is correct |
29 |
Correct |
195 ms |
254768 KB |
Output is correct |
30 |
Correct |
213 ms |
254840 KB |
Output is correct |
31 |
Correct |
210 ms |
254840 KB |
Output is correct |
32 |
Correct |
235 ms |
254712 KB |
Output is correct |
33 |
Correct |
226 ms |
254840 KB |
Output is correct |
34 |
Correct |
208 ms |
254792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
254840 KB |
Output is correct |
2 |
Correct |
231 ms |
254712 KB |
Output is correct |
3 |
Correct |
202 ms |
254784 KB |
Output is correct |
4 |
Correct |
214 ms |
254840 KB |
Output is correct |
5 |
Correct |
221 ms |
254840 KB |
Output is correct |
6 |
Correct |
207 ms |
254836 KB |
Output is correct |
7 |
Correct |
197 ms |
254888 KB |
Output is correct |
8 |
Correct |
220 ms |
254840 KB |
Output is correct |
9 |
Correct |
213 ms |
254840 KB |
Output is correct |
10 |
Correct |
212 ms |
254840 KB |
Output is correct |
11 |
Correct |
204 ms |
254840 KB |
Output is correct |
12 |
Correct |
208 ms |
254840 KB |
Output is correct |
13 |
Correct |
205 ms |
254840 KB |
Output is correct |
14 |
Correct |
214 ms |
254812 KB |
Output is correct |
15 |
Correct |
208 ms |
254840 KB |
Output is correct |
16 |
Correct |
228 ms |
254840 KB |
Output is correct |
17 |
Correct |
189 ms |
254840 KB |
Output is correct |
18 |
Correct |
191 ms |
254880 KB |
Output is correct |
19 |
Correct |
233 ms |
254812 KB |
Output is correct |
20 |
Correct |
212 ms |
254840 KB |
Output is correct |
21 |
Correct |
223 ms |
254968 KB |
Output is correct |
22 |
Correct |
223 ms |
254940 KB |
Output is correct |
23 |
Correct |
197 ms |
254840 KB |
Output is correct |
24 |
Correct |
197 ms |
254956 KB |
Output is correct |
25 |
Correct |
220 ms |
254772 KB |
Output is correct |
26 |
Correct |
216 ms |
254840 KB |
Output is correct |
27 |
Correct |
224 ms |
254900 KB |
Output is correct |
28 |
Correct |
212 ms |
254732 KB |
Output is correct |
29 |
Correct |
195 ms |
254768 KB |
Output is correct |
30 |
Correct |
213 ms |
254840 KB |
Output is correct |
31 |
Correct |
210 ms |
254840 KB |
Output is correct |
32 |
Correct |
235 ms |
254712 KB |
Output is correct |
33 |
Correct |
226 ms |
254840 KB |
Output is correct |
34 |
Correct |
208 ms |
254792 KB |
Output is correct |
35 |
Correct |
227 ms |
254776 KB |
Output is correct |
36 |
Correct |
250 ms |
254968 KB |
Output is correct |
37 |
Correct |
275 ms |
254940 KB |
Output is correct |
38 |
Correct |
310 ms |
254872 KB |
Output is correct |
39 |
Correct |
252 ms |
254840 KB |
Output is correct |
40 |
Correct |
261 ms |
254776 KB |
Output is correct |
41 |
Correct |
253 ms |
254892 KB |
Output is correct |
42 |
Correct |
270 ms |
254792 KB |
Output is correct |
43 |
Correct |
260 ms |
254840 KB |
Output is correct |
44 |
Correct |
250 ms |
254916 KB |
Output is correct |
45 |
Correct |
245 ms |
254840 KB |
Output is correct |
46 |
Correct |
273 ms |
254800 KB |
Output is correct |
47 |
Correct |
265 ms |
254840 KB |
Output is correct |
48 |
Correct |
266 ms |
254968 KB |
Output is correct |
49 |
Correct |
292 ms |
254940 KB |
Output is correct |
50 |
Correct |
262 ms |
254980 KB |
Output is correct |
51 |
Correct |
249 ms |
254876 KB |
Output is correct |
52 |
Correct |
259 ms |
254868 KB |
Output is correct |
53 |
Correct |
231 ms |
254808 KB |
Output is correct |
54 |
Correct |
239 ms |
254788 KB |
Output is correct |
55 |
Correct |
235 ms |
254968 KB |
Output is correct |
56 |
Correct |
236 ms |
254968 KB |
Output is correct |
57 |
Correct |
241 ms |
254936 KB |
Output is correct |
58 |
Correct |
232 ms |
254940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
208 ms |
254840 KB |
Output is correct |
2 |
Correct |
216 ms |
254784 KB |
Output is correct |
3 |
Correct |
205 ms |
254968 KB |
Output is correct |
4 |
Correct |
210 ms |
254768 KB |
Output is correct |
5 |
Correct |
208 ms |
254828 KB |
Output is correct |
6 |
Correct |
208 ms |
254840 KB |
Output is correct |
7 |
Execution timed out |
1048 ms |
256972 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
207 ms |
254840 KB |
Output is correct |
2 |
Correct |
231 ms |
254712 KB |
Output is correct |
3 |
Correct |
202 ms |
254784 KB |
Output is correct |
4 |
Correct |
214 ms |
254840 KB |
Output is correct |
5 |
Correct |
221 ms |
254840 KB |
Output is correct |
6 |
Correct |
207 ms |
254836 KB |
Output is correct |
7 |
Correct |
197 ms |
254888 KB |
Output is correct |
8 |
Correct |
220 ms |
254840 KB |
Output is correct |
9 |
Correct |
213 ms |
254840 KB |
Output is correct |
10 |
Correct |
212 ms |
254840 KB |
Output is correct |
11 |
Correct |
204 ms |
254840 KB |
Output is correct |
12 |
Correct |
208 ms |
254840 KB |
Output is correct |
13 |
Correct |
205 ms |
254840 KB |
Output is correct |
14 |
Correct |
214 ms |
254812 KB |
Output is correct |
15 |
Correct |
208 ms |
254840 KB |
Output is correct |
16 |
Correct |
228 ms |
254840 KB |
Output is correct |
17 |
Correct |
189 ms |
254840 KB |
Output is correct |
18 |
Correct |
191 ms |
254880 KB |
Output is correct |
19 |
Correct |
233 ms |
254812 KB |
Output is correct |
20 |
Correct |
212 ms |
254840 KB |
Output is correct |
21 |
Correct |
223 ms |
254968 KB |
Output is correct |
22 |
Correct |
223 ms |
254940 KB |
Output is correct |
23 |
Correct |
197 ms |
254840 KB |
Output is correct |
24 |
Correct |
197 ms |
254956 KB |
Output is correct |
25 |
Correct |
220 ms |
254772 KB |
Output is correct |
26 |
Correct |
216 ms |
254840 KB |
Output is correct |
27 |
Correct |
224 ms |
254900 KB |
Output is correct |
28 |
Correct |
212 ms |
254732 KB |
Output is correct |
29 |
Correct |
195 ms |
254768 KB |
Output is correct |
30 |
Correct |
213 ms |
254840 KB |
Output is correct |
31 |
Correct |
210 ms |
254840 KB |
Output is correct |
32 |
Correct |
235 ms |
254712 KB |
Output is correct |
33 |
Correct |
226 ms |
254840 KB |
Output is correct |
34 |
Correct |
208 ms |
254792 KB |
Output is correct |
35 |
Correct |
227 ms |
254776 KB |
Output is correct |
36 |
Correct |
250 ms |
254968 KB |
Output is correct |
37 |
Correct |
275 ms |
254940 KB |
Output is correct |
38 |
Correct |
310 ms |
254872 KB |
Output is correct |
39 |
Correct |
252 ms |
254840 KB |
Output is correct |
40 |
Correct |
261 ms |
254776 KB |
Output is correct |
41 |
Correct |
253 ms |
254892 KB |
Output is correct |
42 |
Correct |
270 ms |
254792 KB |
Output is correct |
43 |
Correct |
260 ms |
254840 KB |
Output is correct |
44 |
Correct |
250 ms |
254916 KB |
Output is correct |
45 |
Correct |
245 ms |
254840 KB |
Output is correct |
46 |
Correct |
273 ms |
254800 KB |
Output is correct |
47 |
Correct |
265 ms |
254840 KB |
Output is correct |
48 |
Correct |
266 ms |
254968 KB |
Output is correct |
49 |
Correct |
292 ms |
254940 KB |
Output is correct |
50 |
Correct |
262 ms |
254980 KB |
Output is correct |
51 |
Correct |
249 ms |
254876 KB |
Output is correct |
52 |
Correct |
259 ms |
254868 KB |
Output is correct |
53 |
Correct |
231 ms |
254808 KB |
Output is correct |
54 |
Correct |
239 ms |
254788 KB |
Output is correct |
55 |
Correct |
235 ms |
254968 KB |
Output is correct |
56 |
Correct |
236 ms |
254968 KB |
Output is correct |
57 |
Correct |
241 ms |
254936 KB |
Output is correct |
58 |
Correct |
232 ms |
254940 KB |
Output is correct |
59 |
Correct |
208 ms |
254840 KB |
Output is correct |
60 |
Correct |
216 ms |
254784 KB |
Output is correct |
61 |
Correct |
205 ms |
254968 KB |
Output is correct |
62 |
Correct |
210 ms |
254768 KB |
Output is correct |
63 |
Correct |
208 ms |
254828 KB |
Output is correct |
64 |
Correct |
208 ms |
254840 KB |
Output is correct |
65 |
Execution timed out |
1048 ms |
256972 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |