QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628362#9346. Binary Numbersliuyz11WA 73ms78224kbC++201.7kb2024-10-10 19:51:232024-10-10 19:51:25

Judging History

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

  • [2024-10-10 19:51:25]
  • 评测
  • 测评结果:WA
  • 用时:73ms
  • 内存:78224kb
  • [2024-10-10 19:51:23]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(x, l, r) for(int x = l; x <= r; x++)
#define repd(x, r, l) for(int x = r; x >= l; x--)
#define clr(x, y) memset(x, y, sizeof(x))
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;

const int MAXN = 2e5 + 5;
const int MAXM = 25;
const int mod = 1e9 + 7;

int n, m;
int sum[MAXN][MAXM][MAXM], l[MAXN], r[MAXN];

int judge(int x, int y){
    int s = 0;
    // printf("%d  %d  %d\n", x, y, res);
    repd(i, m - 1, 0){
        if((x >> i & 1) == (y >> i & 1)) s++;
        else break;
    }
    return s;
}

int main(){
    // rep(i, 1, 100){
    //     rep(j, i, 100) printf("%d ", judge(i, j));
    //     puts("");
    // }
    int t;
    scanf("%d", &t);
    while(t--){
        scanf("%d%d", &m, &n);
        rep(i, 0, n){
            rep(j, 0, m)
                rep(k, 0, m) sum[i][j][k] = 0;
        }
        rep(i, 1, n){
            scanf("%d%d", &l[i], &r[i]);
        }
        sum[0][0][m] = 1;
        rep(i, 1, n){
            rep(j, l[i], r[i]){
                int w0 = judge(j, l[i]), v0 = judge(j, r[i - 1]);
                if(i == 1) v0 = 0;
                int w1 = judge(j, l[i + 1]), v1 = judge(j, r[i]);
                if(i == n) w1 = 0;
                // printf("%d : %d  %d\n", j, w0, v0);
                int s = 0;
                repd(p, w0, 0)
                    rep(q, v0, m + 1)  s = (s + sum[i - 1][p][q]) % mod;
                sum[i][w1][v1] = (sum[i][w1][v1] + 1ll * s * j % mod) % mod;
            }
        }
        int ans = 0;
        rep(j, 0, m)
            rep(k, 0, m) ans = (ans + sum[n][j][k]) % mod;
        printf("%d\n", ans);
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5936kb

input:

1
2 2
0 1
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: -100
Wrong Answer
time: 73ms
memory: 78224kb

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:

430920
87171513
728801388
135659943
729244931
334055705
351633063
575181680
805603084
147342282
813072809
110161009
2268
27188180
1
707445594
840443763
648965545
28
252576307

result:

wrong answer 2nd lines differ - expected: '27651757', found: '87171513'