QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#107781 | #1286. Ternary String Counting | Jerry_Jiang | WA | 85ms | 3524kb | C++14 | 1.2kb | 2023-05-22 20:02:16 | 2023-05-22 20:02:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template <typename T> inline void chMax(T &a,T b) {a = max(a, b);}
template <typename T> inline void chMin(T &a,T b) {a = min(a, b);}
const int maxN = 5005, maxM = 1e6 + 5, Mod = 1e9 + 7;
int n, m;
struct Restriction {
int l, r, x;
} R[maxM];
int cnt = 0, a[maxN];
bool app[3];
void dfs(int x) {
if(x == n + 1) {
bool flag = 1;
for(int i = 1; i <= m; i++) {
app[0] = app[1] = app[2] = 0;
for(int j = R[i].l; j <= R[i].r; j++) {
app[a[j]] = 1;
}
if(app[0] + app[1] + app[2] != R[i].x) {
flag = 0;
break;
}
}
cnt += flag;
return;
}
for(int i = 0; i <= 2; i++) {
a[x] = i;
dfs(x + 1);
}
}
void solve() {
cin >> n >> m;
for(int i = 1; i <= m; i++) {
cin >> R[i].l >> R[i].r >> R[i].x;
}
if(!m) {
int ans = 1;
for(int i = 1; i <= n; i++) ans = 3LL * ans % Mod;
cout << ans << "\n";
return;
}
dfs(1);
cout << cnt << "\n";
}
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int T; cin >> T;
while(T--) solve();
return 0;
}
/*
4
1 0
2 0
3 0
5 2
1 3 3
4 5 1
3
9
27
18
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3400kb
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: 85ms
memory: 3524kb
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 90 90 90 24390 24390 24390 24390 25158 25158 25158 26130 29046 29046 35526 36390 36390 36390 36390 36390 36390 36390 36390 36390 36396 36396 36396 36396 36396 36396 36492 36492 36498 36498 36498 36498 36498 36498 36498 36498 36606 36606 36606 36606 39522 39522 39522 39522 39522 39522 39522 39522 ...
result:
wrong answer 2nd words differ - expected: '0', found: '90'