# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
792440 |
2023-07-25T04:55:36 Z |
vjudge1 |
Lamps (JOI19_lamps) |
C++14 |
|
837 ms |
4244 KB |
#include<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
using namespace std ;
const int N = 1e6 ;
int n ;
bool flag ;
char a[N + 1], b[N + 2] ;
int dist[N + 1] ;
void bfs()
{
int num = 0 ;
deque<int> d ;
for(int i = 0 ; i < n ; i++)
if(a[i] == '1')
num ^= (1 << i) ;
d.push_back(num) ;
dist[num] = 1 ;
while(d.size())
{
int now = d[0] ;
d.pop_front() ;
for(int i = 0 ; i < n ; i++)
for(int j = i ; j < n ; j++)
{
int num1 = now, num2 = now, num3 = now ;
for(int q = i ; q <= j ; q++)
{
num1 |= (1 << q) ;
if(now & (1 << q))num2 ^= (1 << q) ;
num3 ^= (1 << q) ;
}
if(!dist[num1])
{
d.push_back(num1) ;
dist[num1] = dist[now] + 1 ;
}
if(!dist[num2])
{
d.push_back(num2) ;
dist[num2] = dist[now] + 1 ;
}
if(!dist[num3])
{
d.push_back(num3) ;
dist[num3] = dist[now] + 1 ;
}
}
}
}
signed main()
{
ios_base::sync_with_stdio( 0 ) ;
cin.tie( 0 ) ;
cout.tie( 0 ) ;
cin >> n ;
for(int i = 0 ; i < n ; i++)
{
cin >> a[i] ;
if(a[i] == '1')
flag = 1 ;
}
for(int i = 0 ; i < n ; i++)
cin >> b[i] ;
if(!flag)
{
int ans = 0 ;
b[n] = '0' ;
for(int i = 0 ; i < n ; i++)
if(b[i] == '1' && b[i + 1] == '0')
ans++ ;
cout << ans ;
return 0 ;
}
if(n <= 18)
{
int num = 0 ;
bfs() ;
for(int i = 0 ; i < n ; i++)
if(b[i] == '1')num ^= (1 << i) ;
cout << dist[num] - 1 ;
return 0 ;
}
return 0 ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
768 ms |
1660 KB |
Output is correct |
10 |
Correct |
342 ms |
1048 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
824 ms |
1816 KB |
Output is correct |
13 |
Correct |
342 ms |
1140 KB |
Output is correct |
14 |
Correct |
796 ms |
1836 KB |
Output is correct |
15 |
Correct |
355 ms |
1092 KB |
Output is correct |
16 |
Correct |
813 ms |
1876 KB |
Output is correct |
17 |
Correct |
353 ms |
1120 KB |
Output is correct |
18 |
Correct |
825 ms |
1856 KB |
Output is correct |
19 |
Correct |
352 ms |
1084 KB |
Output is correct |
20 |
Correct |
791 ms |
1884 KB |
Output is correct |
21 |
Correct |
345 ms |
1112 KB |
Output is correct |
22 |
Correct |
805 ms |
1892 KB |
Output is correct |
23 |
Correct |
352 ms |
1096 KB |
Output is correct |
24 |
Correct |
837 ms |
1820 KB |
Output is correct |
25 |
Correct |
373 ms |
1124 KB |
Output is correct |
26 |
Correct |
836 ms |
1900 KB |
Output is correct |
27 |
Correct |
336 ms |
1084 KB |
Output is correct |
28 |
Correct |
147 ms |
720 KB |
Output is correct |
29 |
Correct |
779 ms |
1812 KB |
Output is correct |
30 |
Correct |
342 ms |
1092 KB |
Output is correct |
31 |
Correct |
154 ms |
712 KB |
Output is correct |
32 |
Correct |
776 ms |
1832 KB |
Output is correct |
33 |
Correct |
339 ms |
1084 KB |
Output is correct |
34 |
Correct |
144 ms |
676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
768 ms |
1660 KB |
Output is correct |
10 |
Correct |
342 ms |
1048 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
824 ms |
1816 KB |
Output is correct |
13 |
Correct |
342 ms |
1140 KB |
Output is correct |
14 |
Correct |
796 ms |
1836 KB |
Output is correct |
15 |
Correct |
355 ms |
1092 KB |
Output is correct |
16 |
Correct |
813 ms |
1876 KB |
Output is correct |
17 |
Correct |
353 ms |
1120 KB |
Output is correct |
18 |
Correct |
825 ms |
1856 KB |
Output is correct |
19 |
Correct |
352 ms |
1084 KB |
Output is correct |
20 |
Correct |
791 ms |
1884 KB |
Output is correct |
21 |
Correct |
345 ms |
1112 KB |
Output is correct |
22 |
Correct |
805 ms |
1892 KB |
Output is correct |
23 |
Correct |
352 ms |
1096 KB |
Output is correct |
24 |
Correct |
837 ms |
1820 KB |
Output is correct |
25 |
Correct |
373 ms |
1124 KB |
Output is correct |
26 |
Correct |
836 ms |
1900 KB |
Output is correct |
27 |
Correct |
336 ms |
1084 KB |
Output is correct |
28 |
Correct |
147 ms |
720 KB |
Output is correct |
29 |
Correct |
779 ms |
1812 KB |
Output is correct |
30 |
Correct |
342 ms |
1092 KB |
Output is correct |
31 |
Correct |
154 ms |
712 KB |
Output is correct |
32 |
Correct |
776 ms |
1832 KB |
Output is correct |
33 |
Correct |
339 ms |
1084 KB |
Output is correct |
34 |
Correct |
144 ms |
676 KB |
Output is correct |
35 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
20 ms |
3056 KB |
Output is correct |
8 |
Correct |
20 ms |
3148 KB |
Output is correct |
9 |
Correct |
19 ms |
4180 KB |
Output is correct |
10 |
Correct |
19 ms |
4124 KB |
Output is correct |
11 |
Correct |
19 ms |
4124 KB |
Output is correct |
12 |
Correct |
20 ms |
4244 KB |
Output is correct |
13 |
Correct |
19 ms |
4136 KB |
Output is correct |
14 |
Correct |
19 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
768 ms |
1660 KB |
Output is correct |
10 |
Correct |
342 ms |
1048 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
824 ms |
1816 KB |
Output is correct |
13 |
Correct |
342 ms |
1140 KB |
Output is correct |
14 |
Correct |
796 ms |
1836 KB |
Output is correct |
15 |
Correct |
355 ms |
1092 KB |
Output is correct |
16 |
Correct |
813 ms |
1876 KB |
Output is correct |
17 |
Correct |
353 ms |
1120 KB |
Output is correct |
18 |
Correct |
825 ms |
1856 KB |
Output is correct |
19 |
Correct |
352 ms |
1084 KB |
Output is correct |
20 |
Correct |
791 ms |
1884 KB |
Output is correct |
21 |
Correct |
345 ms |
1112 KB |
Output is correct |
22 |
Correct |
805 ms |
1892 KB |
Output is correct |
23 |
Correct |
352 ms |
1096 KB |
Output is correct |
24 |
Correct |
837 ms |
1820 KB |
Output is correct |
25 |
Correct |
373 ms |
1124 KB |
Output is correct |
26 |
Correct |
836 ms |
1900 KB |
Output is correct |
27 |
Correct |
336 ms |
1084 KB |
Output is correct |
28 |
Correct |
147 ms |
720 KB |
Output is correct |
29 |
Correct |
779 ms |
1812 KB |
Output is correct |
30 |
Correct |
342 ms |
1092 KB |
Output is correct |
31 |
Correct |
154 ms |
712 KB |
Output is correct |
32 |
Correct |
776 ms |
1832 KB |
Output is correct |
33 |
Correct |
339 ms |
1084 KB |
Output is correct |
34 |
Correct |
144 ms |
676 KB |
Output is correct |
35 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
36 |
Halted |
0 ms |
0 KB |
- |