QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#107783#1286. Ternary String CountingJerry_JiangTL 83ms3408kbC++141.2kb2023-05-22 20:03:082023-05-22 20:03:12

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-22 20:03:12]
  • 评测
  • 测评结果:TL
  • 用时:83ms
  • 内存:3408kb
  • [2023-05-22 20:03:08]
  • 提交

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;
	}
	cnt = 0;
	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
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3408kb

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: 0
Accepted
time: 83ms
memory: 3328kb

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
96
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
0
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
810...

result:

ok 741 tokens

Test #3:

score: -100
Time Limit Exceeded

input:

332
17 5
4 9 1
4 6 1
7 17 1
5 5 1
5 6 3
13 5
10 12 3
8 13 2
1 10 3
2 9 1
9 10 1
19 5
11 13 1
9 17 2
1 7 1
4 4 2
3 9 1
15 4
8 11 2
9 14 3
10 12 2
4 5 2
12 4
3 9 2
7 8 1
1 7 3
6 7 3
16 5
4 14 3
1 5 1
2 10 1
2 12 3
6 9 3
20 4
10 17 3
4 20 3
17 19 3
8 17 1
20 5
11 11 1
9 13 1
1 5 3
17 17 3
3 18 3
17 5
1...

output:


result: