#include <bits/stdc++.h>
#define ff(j, a, b) for(int j=a;j<b;j++)
#define pb push_back;
using namespace std;
typedef long long ll;
ll n, k;
ll a, b, path;
void load_path()
{
path=pow(2, n-1);
ff(j, 0, n-1)
{
char tmp;
cin >> tmp;
if(tmp=='R')
{
path+=pow(2, n-2-j);
}
}
}
ll bin_string_to_ll(string s)
{
ll res=1;
ff(j, 1, s.size())
{
res=res*2;
if(s[j]=='1')
{
res++;
}
}
return res;
}
ll switch_at_depth_q(ll q, ll pathing)
{
return ((1 << (n-q) )-1) ^ pathing;
}
ll check_pathing(ll x)
{
return (x<=b && x>=a) ? x : 0;
}
ll ena_je_budala_neopjevana(ll switches, ll depth, ll pathing)
{
if(switches==n-depth && switches>0)
{
return ena_je_budala_neopjevana(switches-1, depth+1, switch_at_depth_q(depth, pathing));
}
if(depth==1)
{
ll sol=ena_je_budala_neopjevana(switches, depth+1, pathing);
sol+=ena_je_budala_neopjevana(switches, depth+1, switch_at_depth_q(depth, pathing));
if(switches>0)
{
sol+=ena_je_budala_neopjevana(switches-1, depth+1, pathing);
sol+=ena_je_budala_neopjevana(switches-1, depth+1, switch_at_depth_q(depth, pathing));
}
return sol;
}
if(switches==0)
{
return check_pathing(pathing);
}
return ena_je_budala_neopjevana(switches, depth+1, pathing) + ena_je_budala_neopjevana(switches-1, depth+1, switch_at_depth_q(depth, pathing));
}
int main()
{
cin >> n >> k;
load_path();
string tmpstrng;
cin >> tmpstrng;
a=bin_string_to_ll(tmpstrng);
cin >> tmpstrng;
b=bin_string_to_ll(tmpstrng);
///zavrseno ucitavanje!!
/// XOR <=> ^
cout << ena_je_budala_neopjevana(k, 1, path);
return 0;
}
Compilation message
ljetopica.cpp: In function 'll bin_string_to_ll(std::__cxx11::string)':
ljetopica.cpp:2:34: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
#define ff(j, a, b) for(int j=a;j<b;j++)
ljetopica.cpp:32:8:
ff(j, 1, s.size())
~~~~~~~~~~~~~~
ljetopica.cpp:32:5: note: in expansion of macro 'ff'
ff(j, 1, s.size())
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
15 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |