# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
105569 |
2019-04-13T13:49:15 Z |
Pro_ktmr |
Lamps (JOI19_lamps) |
C++14 |
|
1000 ms |
209932 KB |
#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define MP make_pair
#define PB push_back
int N;
string A = "";
string B = "";
string allPatern[16] = {"","F","N","X","FN","NF","NX","XN","XF","FX","FNX","FXN","NFX","NXF","XFN","XNF"};
LL memo[16][16];
LL culc(int moto, int ato){
string A = allPatern[moto];
string B = allPatern[ato];
for(int i=3; i>=1; i--){ //length
for(int j=0; j+i-1<A.size(); j++){
for(int k=0; k+i-1<B.size(); k++){
for(int l=0; l<i; l++){
if(A[j+l] != B[k+l]) break;
if(l == i-1) return B.size()-i;
}
}
}
}
return B.size();
}
LL dp[1000000][16];
bool already[1000000][16] = {};
LL solve(int now, int order){
if(now == N) return 0;
if(already[now][order]) return dp[now][order];
already[now][order] = true;
//cout << now << " " << order << endl;
LL ans = LLONG_MAX;
for(int i=0; i<16; i++){
if(allPatern[i].back() == 'F' && B[now] == '1') continue;
if(allPatern[i].back() == 'N' && B[now] == '0') continue;
int tmp = A[now]-'0';
for(int j=0; j<allPatern[i].size(); j++){
if(allPatern[i][j] == 'F') tmp = 0;
if(allPatern[i][j] == 'N') tmp = 1;
if(allPatern[i][j] == 'X') tmp = tmp ^ 1;
}
if(tmp != B[now]-'0') continue;
ans = min(ans, memo[order][i]+solve(now+1,i));
}
return dp[now][order] = ans;
}
int main(){
scanf("%d", &N);
for(int i=0; i<16; i++){
for(int j=0; j<16; j++){
memo[i][j] = culc(i, j);
}
}
cin >> A >> B;
cout << solve(0, 0) << endl;
return 0;
}
Compilation message
lamp.cpp: In function 'long long int culc(int, int)':
lamp.cpp:22:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j+i-1<A.size(); j++){
~~~~~^~~~~~~~~
lamp.cpp:23:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0; k+i-1<B.size(); k++){
~~~~~^~~~~~~~~
lamp.cpp: In function 'long long int solve(int, int)':
lamp.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0; j<allPatern[i].size(); j++){
~^~~~~~~~~~~~~~~~~~~~
lamp.cpp: In function 'int main()':
lamp.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &N);
~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
768 KB |
Output is correct |
36 |
Correct |
5 ms |
896 KB |
Output is correct |
37 |
Correct |
5 ms |
896 KB |
Output is correct |
38 |
Correct |
6 ms |
1024 KB |
Output is correct |
39 |
Correct |
5 ms |
768 KB |
Output is correct |
40 |
Correct |
6 ms |
768 KB |
Output is correct |
41 |
Correct |
5 ms |
896 KB |
Output is correct |
42 |
Correct |
5 ms |
896 KB |
Output is correct |
43 |
Correct |
6 ms |
896 KB |
Output is correct |
44 |
Correct |
7 ms |
896 KB |
Output is correct |
45 |
Correct |
5 ms |
768 KB |
Output is correct |
46 |
Correct |
7 ms |
896 KB |
Output is correct |
47 |
Correct |
5 ms |
768 KB |
Output is correct |
48 |
Correct |
5 ms |
896 KB |
Output is correct |
49 |
Correct |
5 ms |
896 KB |
Output is correct |
50 |
Correct |
5 ms |
896 KB |
Output is correct |
51 |
Correct |
5 ms |
896 KB |
Output is correct |
52 |
Correct |
5 ms |
768 KB |
Output is correct |
53 |
Correct |
5 ms |
768 KB |
Output is correct |
54 |
Correct |
5 ms |
768 KB |
Output is correct |
55 |
Correct |
5 ms |
768 KB |
Output is correct |
56 |
Correct |
5 ms |
768 KB |
Output is correct |
57 |
Correct |
5 ms |
768 KB |
Output is correct |
58 |
Correct |
5 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Execution timed out |
1068 ms |
209932 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
2 ms |
384 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
35 |
Correct |
5 ms |
768 KB |
Output is correct |
36 |
Correct |
5 ms |
896 KB |
Output is correct |
37 |
Correct |
5 ms |
896 KB |
Output is correct |
38 |
Correct |
6 ms |
1024 KB |
Output is correct |
39 |
Correct |
5 ms |
768 KB |
Output is correct |
40 |
Correct |
6 ms |
768 KB |
Output is correct |
41 |
Correct |
5 ms |
896 KB |
Output is correct |
42 |
Correct |
5 ms |
896 KB |
Output is correct |
43 |
Correct |
6 ms |
896 KB |
Output is correct |
44 |
Correct |
7 ms |
896 KB |
Output is correct |
45 |
Correct |
5 ms |
768 KB |
Output is correct |
46 |
Correct |
7 ms |
896 KB |
Output is correct |
47 |
Correct |
5 ms |
768 KB |
Output is correct |
48 |
Correct |
5 ms |
896 KB |
Output is correct |
49 |
Correct |
5 ms |
896 KB |
Output is correct |
50 |
Correct |
5 ms |
896 KB |
Output is correct |
51 |
Correct |
5 ms |
896 KB |
Output is correct |
52 |
Correct |
5 ms |
768 KB |
Output is correct |
53 |
Correct |
5 ms |
768 KB |
Output is correct |
54 |
Correct |
5 ms |
768 KB |
Output is correct |
55 |
Correct |
5 ms |
768 KB |
Output is correct |
56 |
Correct |
5 ms |
768 KB |
Output is correct |
57 |
Correct |
5 ms |
768 KB |
Output is correct |
58 |
Correct |
5 ms |
896 KB |
Output is correct |
59 |
Correct |
2 ms |
256 KB |
Output is correct |
60 |
Correct |
2 ms |
384 KB |
Output is correct |
61 |
Correct |
3 ms |
256 KB |
Output is correct |
62 |
Correct |
2 ms |
256 KB |
Output is correct |
63 |
Correct |
2 ms |
384 KB |
Output is correct |
64 |
Correct |
3 ms |
384 KB |
Output is correct |
65 |
Execution timed out |
1068 ms |
209932 KB |
Time limit exceeded |
66 |
Halted |
0 ms |
0 KB |
- |