QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#356844#1286. Ternary String Countingjames1BadCreeperWA 2ms3740kbC++142.0kb2024-03-18 13:30:382024-03-18 13:30:39

Judging History

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

  • [2024-03-18 13:30:39]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3740kb
  • [2024-03-18 13:30:38]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 5; 
const int P = 1e9 + 7; 

inline void add(int &x, int k) { x = (x + k) % P; }
inline void sub(int &x, int k) { x = (x - k + P) % P; }

int n, m; 
int mnj[N], mxj[N], mnk[N], mxk[N], f[N][N]; 
int rs[N], cs[N], tmp[N], lk[N], rk[N]; 

inline void del(int j, int k) {
    sub(rs[j], f[j][k]); sub(cs[j], f[j][k]); 
    f[j][k] = 0; 
}

void solve(void) {
    cin >> n >> m; 
    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= n; ++j) f[i][j] = 0; 
        mnj[i] = mnk[i] = 0, mxj[i] = mxk[i] = n; 
        rs[i] = cs[i] = 0; lk[i] = 0; rk[i] = n; 
    }
    while (m--) {
        int l, r, x; cin >> l >> r >> x; 
        if (x == 1) mxj[r] = min(mxj[r], l - 1); 
        else if (x == 2) mnj[r] = max(mnj[r], l), mxk[r] = min(mxk[r], l - 1); 
        else mnk[r] = max(mnk[r], l); 
    }
    
    f[0][0] = rs[0] = cs[0] = 1; 
    int lj = 0; 
    for (int i = 1; i <= n; ++i) {
        if (mnj[i] <= i - 1 && i - 1 <= mxj[i]) {
            for (int k = 0; k < i; ++k) tmp[k] = (rs[k] + cs[k]) % P; 
            for (int k = mnk[i]; k <= min(mxk[i], max(0, i - 2)); ++k) // f[i][i - 1][k]
                add(f[i - 1][k], tmp[k]), 
                add(rs[i - 1], tmp[k]), 
                add(cs[k], tmp[k]); 
        }

        for (int j = lj; j < i; ++j)
            if (j < mnj[i] || j > mxj[i]) {
                for (int k = 0; k <= n; ++k) del(j, k); 
                lk[j] = n; rk[j] = 0; 
            } else {
                for (int k = lk[j]; k < mnk[i]; ++k) del(j, k); 
                for (int k = mxk[i] + 1; k <= rk[j]; ++k) del(j, k); 
                lk[j] = max(lk[j], mnk[i]); 
                rk[j] = min(rk[j], mxk[i]); 
            }
    }
    int ans = 0; 
    for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) add(ans, f[i][j]); 
    cout << ans << '\n'; 
}

int main(void) {
    ios::sync_with_stdio(0); 
    int T; 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: 3740kb

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: 2ms
memory: 3676kb

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:

72
0
0
0
22032
0
0
0
1146
0
0
1476
2916
0
8748
1026
0
1000000001
0
0
0
0
0
0
6
999999791
0
0
0
0
96
0
6
0
0
0
0
0
0
0
108
0
0
0
2538
1000000001
999999989
0
0
0
0
0
0
0
972
324
7938
0
0
0
0
0
1944
1728
0
0
0
18
0
0
999999989
0
0
0
0
540
0
0
0
5076
999999683
0
999999071
999999665
162
1944
0
0
0
0
0
54...

result:

wrong answer 1st words differ - expected: '90', found: '72'