QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356780#1286. Ternary String Countingjames1BadCreeperWA 1ms4004kbC++142.6kb2024-03-18 11:46:492024-03-18 11:46:49

Judging History

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

  • [2024-03-18 11:46:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4004kb
  • [2024-03-18 11:46:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int _ = 5e3 + 7;
const int mod = 1e9 + 7;
int T, n, m, lsum[_], csum[_], minj[_], maxj[_], mink[_], maxk[_], f[_][_];
int t[_], lj, rk[_], lk[_];
int dif(int x, int y) { return ((x - y) % mod + mod) % mod; }
void del(int j, int k)
{
    lsum[j] = dif(lsum[j], f[j][k]);
    csum[k] = dif(csum[k], f[j][k]);
    f[j][k] = 0;
}
void clear(int i)
{
    for (int j = lj; j <= i - 1; j++)
    {
        if (j < minj[i] || j > maxj[i])
        {
            for (int k = 0; k <= n; k++)
                del(j, k);
            lk[j] = n;
            rk[j] = 0;
        }
        else
        {
            for (int k = lk[j]; k < mink[i]; k++)
                del(j, k);
            for (int k = rk[j]; k > maxk[i]; k--)
                del(j, k);
            lk[j] = max(lk[j], mink[i]);
            rk[j] = min(rk[j], maxk[i]);
        }
    }
    lj = max(lj, minj[i]);
}
int main(void) {
    cin >> T;
    while (T--) {
        scanf("%d%d", &n, &m);
        for (int i = 0; i <= n; i++)
        { // 初始化
            for (int j = 0; j <= n; j++)
                f[i][j] = 0;
            lsum[i] = csum[i] = 0;
            minj[i] = mink[i] = 0;
            maxj[i] = maxk[i] = n;
            lk[i] = 0;
            rk[i] = n;
        }
        int l, r, x;
        for (int i = 1; i <= m; i++)
        { // 限制 j 和 k 的取值范围.
            scanf("%d%d%d", &l, &r, &x);
            if (x == 1) {
                maxj[r] = min(maxj[r], l - 1); 
                maxk[r] = max(maxk[r], l - 1); 
            } else if (x == 2) {
                minj[r] = max(minj[r], l);
                maxk[r] = min(maxk[r], l - 1);
            } else {
                minj[r] = max(minj[r], l + 1);
                mink[r] = max(mink[r], l);
            }
        }
        lj = 0;
        f[0][0] = 1;
        lsum[0] = csum[0] = 1;
        for (int i = 1; i <= n; i++)
        {
            for (int k = 0; k < i; k++) t[k] = (lsum[k] + csum[k]) % mod;
            if (minj[i] <= i - 1 && maxj[i] >= i - 1) {
                for (int k = mink[i]; k <= min(maxk[i], max(0, i - 2)); k++)
                { // 更新 f[i][i-1][k]
                    f[i - 1][k] = (f[i - 1][k] + t[k]) % mod;
                    csum[k] = (csum[k] + t[k]) % mod;
                    lsum[i - 1] = (lsum[i - 1] + t[k]) % mod;
                }
            }
            clear(i); // 将不合法的状态清零
        }
        int ans = 0;
        for (int i = 0; i <= n; i++)
            ans = (ans + lsum[i]) % 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: 4004kb

input:

4
1 0
2 0
3 0
5 2
1 3 3
4 5 1

output:

3
9
27
18

result:

ok 4 tokens

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3952kb

input:

741
5 3
1 5 3
3 4 2
1 4 3
4 3
2 4 2
1 4 1
2 3 3
10 3
9 10 2
3 6 3
1 9 1
3 4
2 3 2
1 3 2
2 3 3
1 3 3
10 4
6 6 1
9 10 2
4 8 3
4 10 3
6 3
1 4 3
2 4 2
2 2 2
4 3
1 4 1
1 1 2
2 3 1
5 3
4 5 2
4 5 1
1 4 3
9 3
2 3 2
1 9 2
2 4 2
4 3
1 3 3
2 3 2
1 2 3
8 4
5 8 1
4 8 1
3 5 3
1 3 3
9 3
4 5 1
1 5 3
3 8 2
8 3
5 7 2...

output:

90
0
0
0
24300
0
0
0
768
0
0
972
2916
0
6480
864
0
0
0
0
0
0
0
0
6
0
0
0
0
0
324
0
6
0
0
0
0
0
0
0
108
0
0
0
2916
0
0
0
0
0
0
0
0
0
0
324
8748
108
0
0
0
0
0
4320
0
0
0
18
0
0
0
0
0
0
0
0
0
0
0
1992
0
0
450
0
162
1656
0
0
0
0
0
54
0
18
0
0
0
0
744
0
1620
324
0
0
36
36
0
0
60
6
54
0
0
0
0
0
0
0
0
243
...

result:

wrong answer 31st words differ - expected: '96', found: '324'