Submission #72383

# Submission time Handle Problem Language Result Execution time Memory
72383 2018-08-26T07:35:30 Z team(#2159, comfile) Dstorv (FXCUP3_dstorv) C++17
0 / 100
1000 ms 430120 KB
#include <bits/stdc++.h>
#define M 1000000007
using namespace std;
typedef long long ll;
ll n,r,h,A,b;
string s;
int cnt,a[5010],c[5010],w[5010];
vector<int> v;
ll pw(ll x,ll y){
    ll tmp=1;
    while(y){
        if(y%2) tmp=tmp*x%M;
        y /= 2;
        x=x*x%M;
    }
    return tmp;
}
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
void dfs(vector<int> vv){
    if(vv.size()<=(A+b)){
         int ct=0;int flg=0;
        for(int j=0;j<vv.size()-1;j++) if(vv[j]==1 && vv[j+1]==2){
            flg=1;break;
        }
        if(flg) return;
        for(int j=0;j<vv.size();j++) if(vv[j]==1) ct++;
        if(ct==A) cnt++;
        return;
    }
    vector<int> tmp,pos;pos.clear();
    memset(c,0,sizeof(c));
    int cr=0;
    for(int j=0;j<vv.size()-1;j++){
        if(vv[j]==1 && vv[j+1]==2){
           w[j]=cr++;pos.push_back(j);c[j]=1;
        }
    }
    for(int i=0;i<(1<<pos.size());i++){
        tmp.clear();
        for(int j=0;j<vv.size();j++){
            if(c[j]){
                if(i&(1<<w[j])) tmp.push_back(1);
                else tmp.push_back(2);
                j++;
            }
            else {
                tmp.push_back(vv[j]);
            }
        }
        dfs(tmp);
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n>>r>>h;cin>>s;cin>>A>>b;
    ll tmp=gcd(r,h); r/=tmp; h/= tmp;
    int tot=0;
    for(int i=0;i<n;i++){
        if(s[i]=='R') a[i]=1;
        else a[i]=2,tot++;
    }
    for(int i=0;i<n;i++) v.push_back(a[i]);
    dfs(v);
    if((n-tot)>=A && tot>=b){
        ll x1=cnt; ll x2=(r+h);
        if(!cnt) cout<<"0"<<'\n';
        else {
            for(int i=0;i<n-A-b;i++){
                x1/=gcd(x1,r+h);
            }
            x1=x1*pw(r,n-tot-A)%M*pw(h,tot-b)%M;
            cout<<pw(pw((r+h)/gcd(r+h,cnt),n-A-b),M-2)*pw(h,tot-b)%M*pw(r,n-tot-A)%M<<'\n';
        }
    }
    else cout<<"0"<<'\n';
    return 0;
}

Compilation message

dstorv.cpp: In function 'void dfs(std::vector<int>)':
dstorv.cpp:20:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     if(vv.size()<=(A+b)){
        ~~~~~~~~~^~~~~~~
dstorv.cpp:22:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<vv.size()-1;j++) if(vv[j]==1 && vv[j+1]==2){
                     ~^~~~~~~~~~~~
dstorv.cpp:26:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<vv.size();j++) if(vv[j]==1) ct++;
                     ~^~~~~~~~~~
dstorv.cpp:33:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<vv.size()-1;j++){
                 ~^~~~~~~~~~~~
dstorv.cpp:40:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for(int j=0;j<vv.size();j++){
                     ~^~~~~~~~~~
dstorv.cpp: In function 'int main()':
dstorv.cpp:65:23: warning: unused variable 'x2' [-Wunused-variable]
         ll x1=cnt; ll x2=(r+h);
                       ^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Execution timed out 1093 ms 339088 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1111 ms 430120 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 356 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Execution timed out 1093 ms 339088 KB Time limit exceeded
5 Halted 0 ms 0 KB -