QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#359588#5173. 染色zyc0704190 611ms8476kbC++141.5kb2024-03-20 19:18:152024-03-20 19:18:15

Judging History

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

  • [2024-03-20 19:18:15]
  • 评测
  • 测评结果:0
  • 用时:611ms
  • 内存:8476kb
  • [2024-03-20 19:18:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 3;
const int B = 10;

inline int read() {
	char ch = getchar(); int x = 0;
	while (!isdigit(ch)) {ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - 48; ch = getchar();}
	return x;
}

int n, T, a[N], dp[N][15], pre[N][15];

int main() {
	n = read(); T = read();
	for (int i = 1; i <= n; ++i) a[i] = read();
	pre[1][0] = a[1];
	for (int j = 1; j < B; ++j) pre[1][j] = -1;
	for (int i = 2; i <= n; ++i) {
		pre[i][0] = a[i];
		if (a[i] == a[i - 1]) for (int j = 1; j < B; ++j) pre[i][j] = pre[i - 1][j];
		else for (int j = 1; j < B; ++j) pre[i][j] = pre[i - 1][j - 1];
	}
//	for (int i = 1; i <= n; ++i) {
//		for (int j = 0; j < B; ++j)
//			printf("%d ", pre[i][j]);
//		puts("");
//	}
	int l, r;
	while (T--) {
		l = read(); r = read();
		if (l > r) swap(l, r);
		for (int i = 0; i < B; ++i) dp[l][i] = 1e9;
		dp[l][0] = 0;
		for (int i = l; i < r; ++i) {
			for (int j = 0; j < B; ++j) dp[i + 1][j] = 1e9;
			for (int p = 0; p < B; ++p) {
				if (pre[i][p] == -1) continue;
				for (int q = 0; q < B; ++q) {
					if (pre[i + 1][q] == -1) continue;
//					printf("{%d} %d\n", i + 1, q);
					dp[i + 1][q] = min(dp[i + 1][q], dp[i][p] + (pre[i][p] != pre[i + 1][q]) + (!!q));
				}
			}
			for (int j = 0; j < B; ++j) dp[i + 1][j]++;
//			for (int j = 0; j < B; ++j) printf("dp[%d][%d] = %d\n", i + 1, j, dp[i + 1][j]);
		}
		int ans = 1e9;
		for (int j = 0; j < B; ++j) ans = min(ans, dp[r][j]);
		printf("%d\n", ans);
	}
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 31ms
memory: 8476kb

input:

10000 100
84 85 52 2 78 53 20 21 23 76 37 44 18 5 37 8 81 65 46 58 69 1 69 37 53 46 37 35 35 89 1 77 35 6 46 59 89 46 25 55 50 38 61 67 44 23 29 24 46 4 42 15 34 77 20 34 83 79 12 50 69 26 38 14 9 66 80 72 22 26 9 68 35 38 19 84 92 30 83 62 100 71 81 60 7 37 64 50 33 60 86 75 45 78 32 53 3 48 87 60 ...

output:

3684
4600
6006
8432
734
7050
184
7364
494
1145
253
2263
13310
6292
456
7561
2179
10546
1804
2696
4833
295
6040
632
6693
6216
11484
2732
3179
7882
17893
512
5525
17948
9622
6183
5019
14672
673
468
15714
12749
8925
7880
11054
6639
6434
5050
9156
8577
2183
10360
2713
12617
4995
2157
8862
1921
6517
2850...

result:

wrong answer 1st words differ - expected: '3668', found: '3684'

Subtask #2:

score: 0
Time Limit Exceeded

Test #7:

score: 0
Time Limit Exceeded

input:

100000 100000
3 2 3 3 3 3 2 3 2 1 3 1 1 1 3 2 1 3 1 2 2 1 3 1 2 2 1 1 1 3 2 1 3 3 3 3 1 1 1 2 3 3 2 1 1 1 3 1 3 1 3 2 1 3 2 3 3 2 3 3 2 3 3 3 3 3 2 3 2 3 1 3 3 3 3 3 3 3 1 2 3 3 1 3 1 1 2 2 3 1 1 2 3 2 3 1 3 2 1 3 2 3 2 1 1 3 3 1 3 1 2 2 2 3 2 3 2 3 2 1 1 3 1 3 2 2 3 3 3 1 2 2 3 3 2 1 3 1 2 2 2 3 2 ...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 611ms
memory: 8248kb

input:

5000 5000
256 63 197 36 75 66 33 72 27 75 66 248 29 166 209 252 141 95 84 226 147 249 116 94 192 256 199 273 182 166 116 274 27 211 154 144 283 23 53 110 215 11 164 284 161 221 251 96 43 47 18 115 12 51 156 61 116 209 93 98 47 165 174 106 83 67 184 75 12 290 183 197 112 240 67 56 215 148 104 5 141 2...

output:

1335
2720
1762
2634
4806
5042
2980
1337
891
5123
7886
4901
946
933
817
7340
7734
5377
3849
3256
4519
1593
2563
40
908
304
4393
3919
3848
5793
4653
1675
441
1427
3658
5303
570
121
2063
7686
9200
2065
3149
3718
2910
422
734
4045
179
3262
1453
1614
7195
3038
6009
8161
1552
3842
367
4517
3331
1759
824
2...

result:

wrong answer 1st words differ - expected: '1322', found: '1335'

Subtask #4:

score: 0
Time Limit Exceeded

Test #23:

score: 0
Time Limit Exceeded

input:

1000000 1000000
1105 3246 1880 3554 818 2331 2576 4140 149 4562 3498 3536 3400 4788 4363 4742 1216 4218 4032 1701 1489 4889 1761 3022 3145 4945 3067 4304 5016 4624 1612 13 1335 3613 1086 2210 386 3464 1156 3352 4341 5006 3465 3900 622 654 1826 2983 1250 4164 3335 4308 2995 1982 1347 4335 2535 5054 4...

output:


result: