# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
129170 | 2019-07-11T18:46:45 Z | mahmoudbadawy | Lamps (JOI19_lamps) | C++17 | 384 ms | 4912 KB |
#include <bits/stdc++.h> using namespace std; string a,b; int n; int dis[(1<<18)]; int conv(string s) { int res=0; for(int i=0;i<s.size();i++) res=res*2+(s[i]-'0'); return res; } int main() { cin >> n >> a >> b; if(a==string(n,'0')) { int ans[2]={b[0]=='0',b[0]=='1'}; for(int i=1;i<b.size();i++) { if(b[i]!=b[i-1]) ans[b[i]-'0']++; } cout << min(ans[1],1+ans[0]) << endl; return 0; } queue<int> q; q.push(conv(a)); int bb=conv(b); memset(dis,-1,sizeof dis); dis[conv(a)]=0; while(q.size()) { int s=q.front(); q.pop(); if(s==bb) break; for(int i=0;i<n;i++) { int sd=s; for(int j=i;j<n;j++) { sd&=(~(1<<j)); if(dis[sd]!=-1) continue; dis[sd]=dis[s]+1; q.push(sd); } } for(int i=0;i<n;i++) { int sd=s; for(int j=i;j<n;j++) { sd|=(1<<j); if(dis[sd]!=-1) continue; dis[sd]=dis[s]+1; q.push(sd); } } for(int i=0;i<n;i++) { int sd=s; for(int j=i;j<n;j++) { sd^=(1<<j); if(dis[sd]!=-1) continue; dis[sd]=dis[s]+1; q.push(sd); } } } cout << dis[bb] << endl; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1400 KB | Output is correct |
2 | Correct | 3 ms | 1400 KB | Output is correct |
3 | Correct | 3 ms | 1400 KB | Output is correct |
4 | Correct | 3 ms | 1400 KB | Output is correct |
5 | Correct | 3 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1400 KB | Output is correct |
7 | Correct | 3 ms | 1400 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 384 ms | 1872 KB | Output is correct |
10 | Correct | 166 ms | 1528 KB | Output is correct |
11 | Correct | 2 ms | 252 KB | Output is correct |
12 | Correct | 33 ms | 1792 KB | Output is correct |
13 | Correct | 88 ms | 1656 KB | Output is correct |
14 | Correct | 68 ms | 1912 KB | Output is correct |
15 | Correct | 104 ms | 1656 KB | Output is correct |
16 | Correct | 262 ms | 2168 KB | Output is correct |
17 | Correct | 96 ms | 1656 KB | Output is correct |
18 | Correct | 38 ms | 1856 KB | Output is correct |
19 | Correct | 24 ms | 1528 KB | Output is correct |
20 | Correct | 233 ms | 1956 KB | Output is correct |
21 | Correct | 9 ms | 1500 KB | Output is correct |
22 | Correct | 32 ms | 1788 KB | Output is correct |
23 | Correct | 61 ms | 1528 KB | Output is correct |
24 | Correct | 4 ms | 1400 KB | Output is correct |
25 | Correct | 5 ms | 1400 KB | Output is correct |
26 | Correct | 211 ms | 1912 KB | Output is correct |
27 | Correct | 77 ms | 1656 KB | Output is correct |
28 | Correct | 29 ms | 1528 KB | Output is correct |
29 | Correct | 324 ms | 1856 KB | Output is correct |
30 | Correct | 117 ms | 1656 KB | Output is correct |
31 | Correct | 4 ms | 1404 KB | Output is correct |
32 | Correct | 42 ms | 1784 KB | Output is correct |
33 | Correct | 104 ms | 1784 KB | Output is correct |
34 | Correct | 26 ms | 1528 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1400 KB | Output is correct |
2 | Correct | 3 ms | 1400 KB | Output is correct |
3 | Correct | 3 ms | 1400 KB | Output is correct |
4 | Correct | 3 ms | 1400 KB | Output is correct |
5 | Correct | 3 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1400 KB | Output is correct |
7 | Correct | 3 ms | 1400 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 384 ms | 1872 KB | Output is correct |
10 | Correct | 166 ms | 1528 KB | Output is correct |
11 | Correct | 2 ms | 252 KB | Output is correct |
12 | Correct | 33 ms | 1792 KB | Output is correct |
13 | Correct | 88 ms | 1656 KB | Output is correct |
14 | Correct | 68 ms | 1912 KB | Output is correct |
15 | Correct | 104 ms | 1656 KB | Output is correct |
16 | Correct | 262 ms | 2168 KB | Output is correct |
17 | Correct | 96 ms | 1656 KB | Output is correct |
18 | Correct | 38 ms | 1856 KB | Output is correct |
19 | Correct | 24 ms | 1528 KB | Output is correct |
20 | Correct | 233 ms | 1956 KB | Output is correct |
21 | Correct | 9 ms | 1500 KB | Output is correct |
22 | Correct | 32 ms | 1788 KB | Output is correct |
23 | Correct | 61 ms | 1528 KB | Output is correct |
24 | Correct | 4 ms | 1400 KB | Output is correct |
25 | Correct | 5 ms | 1400 KB | Output is correct |
26 | Correct | 211 ms | 1912 KB | Output is correct |
27 | Correct | 77 ms | 1656 KB | Output is correct |
28 | Correct | 29 ms | 1528 KB | Output is correct |
29 | Correct | 324 ms | 1856 KB | Output is correct |
30 | Correct | 117 ms | 1656 KB | Output is correct |
31 | Correct | 4 ms | 1404 KB | Output is correct |
32 | Correct | 42 ms | 1784 KB | Output is correct |
33 | Correct | 104 ms | 1784 KB | Output is correct |
34 | Correct | 26 ms | 1528 KB | Output is correct |
35 | Runtime error | 5 ms | 2552 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
36 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 256 KB | Output is correct |
4 | Correct | 2 ms | 256 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 120 ms | 4180 KB | Output is correct |
8 | Correct | 125 ms | 4312 KB | Output is correct |
9 | Correct | 122 ms | 4752 KB | Output is correct |
10 | Correct | 142 ms | 4912 KB | Output is correct |
11 | Correct | 122 ms | 4840 KB | Output is correct |
12 | Correct | 128 ms | 4748 KB | Output is correct |
13 | Correct | 119 ms | 4840 KB | Output is correct |
14 | Correct | 119 ms | 4816 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1400 KB | Output is correct |
2 | Correct | 3 ms | 1400 KB | Output is correct |
3 | Correct | 3 ms | 1400 KB | Output is correct |
4 | Correct | 3 ms | 1400 KB | Output is correct |
5 | Correct | 3 ms | 1272 KB | Output is correct |
6 | Correct | 3 ms | 1400 KB | Output is correct |
7 | Correct | 3 ms | 1400 KB | Output is correct |
8 | Correct | 2 ms | 376 KB | Output is correct |
9 | Correct | 384 ms | 1872 KB | Output is correct |
10 | Correct | 166 ms | 1528 KB | Output is correct |
11 | Correct | 2 ms | 252 KB | Output is correct |
12 | Correct | 33 ms | 1792 KB | Output is correct |
13 | Correct | 88 ms | 1656 KB | Output is correct |
14 | Correct | 68 ms | 1912 KB | Output is correct |
15 | Correct | 104 ms | 1656 KB | Output is correct |
16 | Correct | 262 ms | 2168 KB | Output is correct |
17 | Correct | 96 ms | 1656 KB | Output is correct |
18 | Correct | 38 ms | 1856 KB | Output is correct |
19 | Correct | 24 ms | 1528 KB | Output is correct |
20 | Correct | 233 ms | 1956 KB | Output is correct |
21 | Correct | 9 ms | 1500 KB | Output is correct |
22 | Correct | 32 ms | 1788 KB | Output is correct |
23 | Correct | 61 ms | 1528 KB | Output is correct |
24 | Correct | 4 ms | 1400 KB | Output is correct |
25 | Correct | 5 ms | 1400 KB | Output is correct |
26 | Correct | 211 ms | 1912 KB | Output is correct |
27 | Correct | 77 ms | 1656 KB | Output is correct |
28 | Correct | 29 ms | 1528 KB | Output is correct |
29 | Correct | 324 ms | 1856 KB | Output is correct |
30 | Correct | 117 ms | 1656 KB | Output is correct |
31 | Correct | 4 ms | 1404 KB | Output is correct |
32 | Correct | 42 ms | 1784 KB | Output is correct |
33 | Correct | 104 ms | 1784 KB | Output is correct |
34 | Correct | 26 ms | 1528 KB | Output is correct |
35 | Runtime error | 5 ms | 2552 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
36 | Halted | 0 ms | 0 KB | - |