Submission #147663

#TimeUsernameProblemLanguageResultExecution timeMemory
147663xDWaffleLjetopica (COI19_ljetopica)C++11
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> #define ff(j, a, b) for(long long j=a;j<b;j++) #define pb push_back; #define MOD 1000000007 using namespace std; typedef long long ll; ll n, k; ll a, b, path; void load_path() { path=1; ff(j, 0, n-1) { char tmp; cin >> tmp; path=path*2; if(tmp=='R') { path++; } path=path%MOD; } } ll bin_string_to_ll(string s) { ll res=0; ff(j, 0, (ll)s.size()) { res=res*2; if(s[j]=='1') { res++; } res=res%MOD; } 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)))%MOD; } 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%MOD; } if(switches==0) { return check_pathing(pathing)%MOD; } return (ena_je_budala_neopjevana(switches, depth+1, pathing) + ena_je_budala_neopjevana(switches-1, depth+1, switch_at_depth_q(depth, pathing)))%MOD; } 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 << (int)ena_je_budala_neopjevana(k, 1, path) << endl; cout << (a%MOD+b%MOD)%MOD; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...