Submission #147658

# Submission time Handle Problem Language Result Execution time Memory
147658 2019-08-30T11:19:09 Z JovanK26 Ljetopica (COI19_ljetopica) C++14
14 / 100
500 ms 4728 KB
#include <bits/stdc++.h>

    using namespace std;
    long long n,k;
    string path;
    string a;
    string b;
    long long aval=0;
    long long bval=0;
    long long rez=0;
    bool vis[100000007];
    bool check(vector<int> v,string s)
    {
        for(int i=0;i<v.size();i++)
        {
            if(v[i]==0 && s[i]=='1')return 1;
            if(v[i]==1 && s[i]=='0')return 0;
        }
    }
    void solve(long long start,long long kk,long long nn,bool chk)
    {
        if(nn==path.size())
        {
            if(kk==0 && !vis[start] && start>=aval && start<=bval)
            {
                rez+=start;
                rez%=1000000007;
                vis[start]=1;
                //cout << start << endl;
            }
            return;
        }
        if(kk==0)
        {
            if(!chk)
            {
                if(path[nn]=='L')solve(2*start,kk,nn+1,chk);
                else
                {
                    solve(2*start+1,kk,nn+1,chk);
                }
            }
            else
            {
                if(path[nn]=='R')solve(2*start,kk,nn+1,chk);
                else
                {
                    solve(2*start+1,kk,nn+1,chk);
                }
            }

        }
        else
        {
            if(!chk)
            {
                if(path[nn]=='L')
                {
                    solve(2*start,kk,nn+1,chk);
                    solve(2*start+1,kk-1,nn+1,chk^1);
                }
                else
                {
                    solve(2*start+1,kk,nn+1,chk);
                    solve(2*start,kk-1,nn+1,chk^1);
                }

            }
            else
            {
                if(path[nn]=='R')
                {
                    solve(2*start,kk,nn+1,chk);
                    solve(2*start+1,kk-1,nn+1,chk^1);
                }
                else
                {
                    solve(2*start+1,kk,nn+1,chk);
                    solve(2*start,kk-1,nn+1,chk^1);
                }
            }
        }
    }
    int main()
    {
        cin >> n >> k;
        cin >> path;
        cin >> a;
        cin >> b;
        if(k>0)
        {
            long long br=0;
        for(long long i=a.size()-1;i>=0;i--)
        {
            if(a[i]=='1')aval+=(1<<br);
            br++;
        }
        br=0;
        for(long long i=b.size()-1;i>=0;i--)
        {
            if(b[i]=='1')bval+=(1<<br);
            br++;
        }
           solve(1,k,0,0);
           solve(1,k,0,1);
           cout << rez;
        }
        else
        {
            long long av=0;
            long long bv=0;
            long long br=0;
            for(long long i=a.size()-1;i>=0;i--)
        {
            if(a[i]=='1')
            {
                av+=(1<<br);
                av%=1000000007;
            }
            br++;
        }
        br=0;
        for(long long i=b.size()-1;i>=0;i--)
        {
            if(b[i]=='1')
            {
                bv+=(1<<br);
                bv%=1000000007;
            }
            br++;
        }
        cout << (av+bv)%1000000007;
        }
        return 0;
    }

Compilation message

ljetopica.cpp: In function 'bool check(std::vector<int>, std::__cxx11::string)':
ljetopica.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int i=0;i<v.size();i++)
                     ~^~~~~~~~~
ljetopica.cpp: In function 'void solve(long long int, long long int, long long int, bool)':
ljetopica.cpp:22:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(nn==path.size())
            ~~^~~~~~~~~~~~~
ljetopica.cpp: In function 'bool check(std::vector<int>, std::__cxx11::string)':
ljetopica.cpp:19:5: warning: control reaches end of non-void function [-Wreturn-type]
     }
     ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 4728 KB Output is correct
2 Correct 16 ms 404 KB Output is correct
3 Correct 229 ms 1028 KB Output is correct
4 Correct 230 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 36 ms 1860 KB Output is correct
7 Correct 8 ms 3192 KB Output is correct
8 Correct 237 ms 496 KB Output is correct
9 Correct 16 ms 632 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 15 ms 1056 KB Output is correct
12 Correct 9 ms 376 KB Output is correct
13 Correct 232 ms 504 KB Output is correct
14 Correct 31 ms 504 KB Output is correct
15 Correct 61 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1075 ms 380 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -