QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644131#9346. Binary NumbersplanckconstantTL 0ms3792kbC++141.5kb2024-10-16 11:09:532024-10-16 11:09:55

Judging History

你现在查看的是最新测评结果

  • [2024-10-16 11:09:55]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3792kb
  • [2024-10-16 11:09:53]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod=100000007;
ll dp[(1<<19)][19][19];
void solve()
{
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>>a(n+5);
    for(int i=1;i<=n;i++){
        cin>>a[i].first>>a[i].second;
    }
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            for(int k=0;k<=m;k++){
                dp[i][j][k]=0;
            }
        }
    }
    dp[0][m][0]=1;
    auto get_lca=[&m](int a,int b)->int{
        int ans=0;
        for(int i=m-1;i>=0;i--){
            if((a>>i)^(b>>i)){
                break;
            }
            ans++;
        }
        return ans;
    };
    for(int i=1;i<=n;i++){
        for(int j=a[i].first;j<=a[i].second;j++){
            int k1=get_lca(j,a[i].second);
            int k2=m;
            if(i!=n)
                k2=get_lca(j,a[i+1].first);
            int k3=get_lca(j,a[i].first);
            int k4=0;
            if(i!=1)
                k4=get_lca(j,a[i-1].second);
            for(int k=0;k<=m;k++){
                for(int o=0;o<=m;o++){
                    if(k4<=k&&k3>=o){
                        dp[i][k1][k2]=(dp[i][k1][k2]+dp[i-1][k][o]*j%mod)%mod;
                    }
                }
            }
        }
    }
    ll re=0;
    for(int i=0;i<=m;i++){
        re=(re+dp[n][i][m])%mod;
    }
    cout<<re<<'\n';
}
signed main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T=1;
    cin >> T;
    while(T--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3792kb

input:

1
2 2
0 1
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: -100
Time Limit Exceeded

input:

20
4 6
0 1
2 3
4 6
7 7
8 11
12 15
9 39
0 31
32 47
48 51
52 63
64 87
88 92
93 95
96 127
128 143
144 159
160 167
168 175
176 191
192 207
208 255
256 263
264 271
272 283
284 287
288 289
290 295
296 303
304 319
320 351
352 357
358 367
368 375
376 383
384 391
392 399
400 403
404 407
408 415
416 443
444 4...

output:


result: