QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#107807 | #1286. Ternary String Counting | lonytree | WA | 2ms | 3492kb | C++14 | 2.4kb | 2023-05-22 21:02:15 | 2023-05-22 21:02:17 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N = 5005, mod = 1e9 + 7;
int T, n, m;
int a[N], b[N], c[N], d[N];
int f[N][N], sum1[N], sum2[N], tsum1[N], tsum2[N];
int solve(){
cin >> n >> m;
for (int i = 1; i <= n; i++){
a[i] = c[i] = 0;
b[i] = d[i] = n + 1;
}
for (int i = 1; i <= m; i++){
int l, r, x;
cin >> l >> r >> x;
if (x == 3) a[r] = max(l, a[r]);
else if (x == 2){
b[r] = min(l, b[r]);
c[r] = max(l, c[r]);
}else d[r] = min(l, d[r]);
}
for (int i = 1; i <= n; i++)
if (a[i] >= b[i] || c[i] >= d[i])
return 0;
for (int i = 0; i <= n; i++){
sum1[i] = sum2[i] = 0;
for (int j = 0; j <= n; j++)
f[i][j] = 0;
}
f[0][0] = 1;
sum1[0] = sum2[0] = 1;
int l1 = 0, l2 = 0, r1 = n, r2 = n;
for (int i = 1; i <= n; i++){
for (int j = 0; j <= n; j++){
tsum1[j] = sum1[j];
tsum2[j] = sum2[j];
}
for (int j = 0; j < i; j++){
f[j][i - 1] = (f[j][i - 1] + tsum1[j]) % mod;
sum1[j] = (sum1[j] + tsum1[j]) % mod;
sum2[i - 1] = (sum2[i - 1] + tsum1[j]) % mod;
}
for (int k = 0; k < i; k++){
f[k][i - 1] = (f[k][i - 1] + tsum2[k]) % mod;
sum1[k] = (sum1[k] + tsum2[k]) % mod;
sum2[i - 1] = (sum2[i - 1] + tsum2[k]) % mod;
}
int nl1 = max(l1, a[i]), nl2 = max(l2, c[i]), nr1 = min(r1, b[i] - 1), nr2 = min(r2, d[i] - 1);
if (nl1 > nr1 || nl2 > nr2) return 0;
auto clear = [&](int x, int y){
sum1[x] = (sum1[x] - f[x][y]) % mod;
sum2[y] = (sum2[y] - f[x][y]) % mod;
f[x][y] = 0;
};
for (int x = l1; x < nl1; x++)
for (int y = l2; y <= r2; y++)
clear(x, y);
for (int x = nr1 + 1; x <= r1; x++)
for (int y = l2; y <= r2; y++)
clear(x, y);
for (int x = nl1; x <= nr1; x++){
for (int y = l2; y < nl2; y++)
clear(x, y);
for (int y = nr2 + 1; y < r2; y++)
clear(x, y);
}
// cout << i << ' ' << l1 << ' ' << r1 << ' ' << l2 << ' ' << r2 << endl;
l1 = nl1, r1 = nr1, l2 = nl2, r2 = nr2;
// cout << i << ' ' << l1 << ' ' << r1 << ' ' << l2 << ' ' << r2 << endl;
}
int ans = 0;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
ans = (ans + f[i][j]) % mod;
return (ans + mod) % mod;
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> T;
while (T--) cout << solve() << endl;
return 0;
}
/*
a <= j < b
c <= k < d
a < b <= c < d
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3396kb
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: 0ms
memory: 3492kb
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 0 0 0 0 12738 0 0 2898 2916 0 23814 27054 0 0 0 0 0 0 0 0 0 0 0 0 0 0 420 0 0 0 0 0 0 0 0 0 162 0 0 2106 2916 240 0 0 0 0 0 0 0 24 0 0 8748 0 0 0 0 0 0 6354 0 0 0 0 0 0 216 0 0 24 0 0 0 0 0 4824 0 6480 594 234 648 10170 0 0 0 0 0 0 0 180 0 0 0 0 0 0 0 756 0 0 0 0 24 0 0 0 1836 0 216 0 0 0 0...
result:
wrong answer 5th words differ - expected: '24300', found: '0'