QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#628347#9346. Binary Numbersliuyz11WA 63ms79764kbC++201.7kb2024-10-10 19:46:042024-10-10 19:46:05

Judging History

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

  • [2024-10-10 19:46:05]
  • 评测
  • 测评结果:WA
  • 用时:63ms
  • 内存:79764kb
  • [2024-10-10 19:46:04]
  • 提交

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 res = x ^ y, s = 0;
    // printf("%d  %d  %d\n", x, y, res);
    repd(i, m - 1, 0){
        if((res >> i) & 1) break;
        else s++;
    }
    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 + 1)
                rep(k, 0, m + 1) sum[i][j][k] = 0;
        }
        rep(i, 1, n){
            scanf("%d%d", &l[i], &r[i]);
        }
        r[0] = 0;
        l[n + 1] = 1 << m;
        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]);
                int w1 = judge(j, l[i + 1]), v1 = judge(j, r[i]);
                // printf("%d : %d  %d\n", j, w0, v0);
                int s = 0;
                rep(p, 0, w0)
                    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 + 1)
            rep(k, 0, m + 1) 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: 0ms
memory: 5936kb

input:

1
2 2
0 1
2 3

output:

5

result:

ok single line: '5'

Test #2:

score: -100
Wrong Answer
time: 63ms
memory: 79764kb

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
496341250
754047900
5040
28188720
575181680
805603084
685858152
824671851
649673041
2268
147499198
1
478212216
706032500
516995748
28
252576307

result:

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