QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#628167#5543. The Only Modeucup-team5062#TL 1731ms9440kbC++204.0kb2024-10-10 18:58:462024-10-10 18:58:49

Judging History

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

  • [2024-10-10 18:58:49]
  • 评测
  • 测评结果:TL
  • 用时:1731ms
  • 内存:9440kb
  • [2024-10-10 18:58:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

const int BACKET = 118;
int N;
int Answer[4];
int A[1 << 17];
int X[1 << 17];
int Y[1 << 17];
int Z[1 << 17];
int dp[BACKET + 2][BACKET + 2][BACKET + 2];

int Solve(int cl, int cr, int idx) {
	// Initialize
	if (idx == 0) {
		X[cl] = 0;
		Y[cl] = 0;
		Z[cl] = 0;
		for (int i = cl; i < N; i++) X[i + 1] = X[i] + (A[i] == 0 ? +1 : (A[i] == 1 ? -1 : 0));
		for (int i = cl; i < N; i++) Y[i + 1] = Y[i] + (A[i] == 0 ? +1 : (A[i] == 2 ? -1 : 0));
		for (int i = cl; i < N; i++) Z[i + 1] = Z[i] + (A[i] == 0 ? +1 : (A[i] == 3 ? -1 : 0));
	}
	if (idx == 1) {
		X[cl] = 0;
		Y[cl] = 0;
		Z[cl] = 0;
		for (int i = cl; i < N; i++) X[i + 1] = X[i] + (A[i] == 1 ? +1 : (A[i] == 2 ? -1 : 0));
		for (int i = cl; i < N; i++) Y[i + 1] = Y[i] + (A[i] == 1 ? +1 : (A[i] == 3 ? -1 : 0));
		for (int i = cl; i < N; i++) Z[i + 1] = Z[i] + (A[i] == 1 ? +1 : (A[i] == 0 ? -1 : 0));
	}
	if (idx == 2) {
		X[cl] = 0;
		Y[cl] = 0;
		Z[cl] = 0;
		for (int i = cl; i < N; i++) X[i + 1] = X[i] + (A[i] == 2 ? +1 : (A[i] == 3 ? -1 : 0));
		for (int i = cl; i < N; i++) Y[i + 1] = Y[i] + (A[i] == 2 ? +1 : (A[i] == 0 ? -1 : 0));
		for (int i = cl; i < N; i++) Z[i + 1] = Z[i] + (A[i] == 2 ? +1 : (A[i] == 1 ? -1 : 0));
	}
	if (idx == 3) {
		X[cl] = 0;
		Y[cl] = 0;
		Z[cl] = 0;
		for (int i = cl; i < N; i++) X[i + 1] = X[i] + (A[i] == 3 ? +1 : (A[i] == 0 ? -1 : 0));
		for (int i = cl; i < N; i++) Y[i + 1] = Y[i] + (A[i] == 3 ? +1 : (A[i] == 1 ? -1 : 0));
		for (int i = cl; i < N; i++) Z[i + 1] = Z[i] + (A[i] == 3 ? +1 : (A[i] == 2 ? -1 : 0));
	}

	// Get Min/Max
	int lx = 0, rx = 0;
	int ly = 0, ry = 0;
	int lz = 0, rz = 0;
	for (int i = cl; i < cr; i++) lx = min(lx, X[i]);
	for (int i = cl; i < cr; i++) rx = max(rx, X[i]);
	for (int i = cl; i < cr; i++) ly = min(ly, Y[i]);
	for (int i = cl; i < cr; i++) ry = max(ry, Y[i]);
	for (int i = cl; i < cr; i++) lz = min(lz, Z[i]);
	for (int i = cl; i < cr; i++) rz = max(rz, Z[i]);
	lx -= 1; ly -= 1; lz -= 1;
	int hx = rx - lx;
	int hy = ry - ly;
	int hz = rz - lz;

	// Get Ruiseki Max
	for (int i = cr; i <= N; i++) dp[max(0, min(hx, X[i] - lx - 1))][max(0, min(hy, Y[i] - ly - 1))][max(0, min(hz, Z[i] - lz - 1))] = i;
	for (int i = hx - 1; i >= 0; i--) {
		for (int j = hy; j >= 0; j--) {
			for (int k = hz; k >= 0; k--) dp[i][j][k] = max(dp[i][j][k], dp[i + 1][j][k]);
		}
	}
	for (int i = hx; i >= 0; i--) {
		for (int j = hy - 1; j >= 0; j--) {
			for (int k = hz; k >= 0; k--) dp[i][j][k] = max(dp[i][j][k], dp[i][j + 1][k]);
		}
	}
	for (int i = hx; i >= 0; i--) {
		for (int j = hy; j >= 0; j--) {
			for (int k = hz - 1; k >= 0; k--) dp[i][j][k] = max(dp[i][j][k], dp[i][j][k + 1]);
		}
	}

	// Solve
	int Answer = 0;
	for (int i = cl; i < cr; i++) {
		Answer = max(Answer, dp[X[i] - lx][Y[i] - ly][Z[i] - lz] - i);
	}
	for (int i = 0; i <= hx; i++) {
		for (int j = 0; j <= hy; j++) {
			for (int k = 0; k <= hz; k++) dp[i][j][k] = 0;
		}
	}
	return Answer;
}

int main() {
	// Step 1. Input
	scanf("%d", &N);
	for (int i = 0; i < N; i++) scanf("%d", &A[i]);

	// Step 2. Solve
	for (int i = 0; i < N; i += BACKET) {
		int cl = i;
		int cr = min(N, i + BACKET);
		for (int j = 0; j < 4; j++) Answer[j] = max(Answer[j], Solve(cl, cr, j));
	}

	// Step 3. Naive Solve
	for (int i = 0; i < N; i++) {
		int cnt[4] = {0, 0, 0, 0};
		for (int j = i; j < min(N, i + BACKET + 1); j++) {
			cnt[A[j]] += 1;
			if (cnt[0] > cnt[1] && cnt[0] > cnt[2] && cnt[0] > cnt[3]) Answer[0] = max(Answer[0], j - i + 1);
			if (cnt[1] > cnt[2] && cnt[1] > cnt[3] && cnt[1] > cnt[0]) Answer[1] = max(Answer[1], j - i + 1);
			if (cnt[2] > cnt[3] && cnt[2] > cnt[0] && cnt[2] > cnt[1]) Answer[2] = max(Answer[2], j - i + 1);
			if (cnt[3] > cnt[0] && cnt[3] > cnt[1] && cnt[3] > cnt[2]) Answer[3] = max(Answer[3], j - i + 1);
		}
	}

	// Step 4. Output
	cout << Answer[0] << " " << Answer[1] << " " << Answer[2] << " " << Answer[3] << endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 5784kb

input:

7
1 2 2 0 3 0 3

output:

4 1 5 3

result:

ok single line: '4 1 5 3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 5724kb

input:

12
2 0 1 0 2 1 1 0 2 3 3 3

output:

4 9 1 9

result:

ok single line: '4 9 1 9'

Test #3:

score: 0
Accepted
time: 0ms
memory: 5796kb

input:

2
0 2

output:

1 0 1 0

result:

ok single line: '1 0 1 0'

Test #4:

score: 0
Accepted
time: 0ms
memory: 5908kb

input:

12
3 0 2 2 1 0 2 1 3 3 2 3

output:

1 5 11 8

result:

ok single line: '1 5 11 8'

Test #5:

score: 0
Accepted
time: 1ms
memory: 5892kb

input:

1
1

output:

0 1 0 0

result:

ok single line: '0 1 0 0'

Test #6:

score: 0
Accepted
time: 7ms
memory: 6212kb

input:

4207
3 1 0 3 2 0 3 1 1 1 1 3 0 1 1 0 2 2 3 0 1 1 0 1 0 2 0 1 0 0 3 3 1 0 1 3 3 0 2 0 2 0 1 0 2 3 2 3 0 0 0 0 1 2 1 2 0 2 2 0 3 3 2 2 0 2 2 0 3 0 1 3 1 1 0 2 3 0 1 2 1 2 0 0 1 1 0 3 3 2 0 2 1 3 0 1 0 3 0 0 0 2 2 2 0 1 1 0 3 1 1 3 3 2 2 1 3 3 1 3 2 0 2 3 2 2 1 0 2 3 0 1 0 0 1 1 1 3 3 1 3 3 3 0 0 0 3 2...

output:

2330 1520 4207 1359

result:

ok single line: '2330 1520 4207 1359'

Test #7:

score: 0
Accepted
time: 1731ms
memory: 6832kb

input:

89925
0 0 0 3 0 3 0 2 3 2 3 1 0 0 0 2 2 1 3 3 0 0 1 0 0 3 0 1 0 0 1 1 0 0 1 2 1 3 1 2 1 2 2 1 0 2 2 3 0 0 1 0 2 3 2 3 0 0 1 0 0 1 2 1 3 0 0 0 2 1 1 0 1 3 2 2 0 0 2 3 2 3 3 1 3 3 0 2 0 2 2 0 2 1 3 0 1 1 0 0 1 0 3 1 2 2 2 0 2 0 2 3 2 0 0 2 3 3 1 0 1 2 2 2 1 2 0 0 3 2 3 0 1 1 3 3 0 0 0 3 0 2 0 0 2 3 1 ...

output:

89925 49888 75725 38162

result:

ok single line: '89925 49888 75725 38162'

Test #8:

score: 0
Accepted
time: 913ms
memory: 9016kb

input:

64937
1 1 0 2 1 1 3 1 1 1 2 0 3 1 1 2 1 2 2 1 0 2 1 1 1 1 1 0 3 1 0 2 1 0 0 0 0 2 1 2 1 2 2 1 2 3 2 1 2 1 3 0 1 3 0 0 1 3 1 2 2 2 0 3 3 1 3 0 3 3 2 0 1 1 2 0 3 3 3 2 1 0 1 0 1 3 0 0 2 1 0 3 3 1 2 3 2 1 1 0 0 3 1 1 2 1 0 2 1 0 0 1 1 3 0 1 2 1 3 2 0 3 1 2 1 2 0 0 0 1 1 2 3 3 2 1 1 1 2 1 3 1 2 2 2 0 1 ...

output:

64937 61901 51387 63870

result:

ok single line: '64937 61901 51387 63870'

Test #9:

score: 0
Accepted
time: 1180ms
memory: 8808kb

input:

73423
1 2 2 0 0 0 0 2 1 2 1 2 1 3 1 3 3 0 1 2 2 0 0 0 3 2 1 1 0 3 0 2 1 3 1 1 2 3 0 1 2 1 0 0 0 3 3 0 3 2 3 3 1 1 3 2 0 0 0 3 2 0 0 2 3 3 3 3 3 2 3 2 2 2 3 3 0 1 1 2 2 2 1 2 2 1 1 2 1 2 2 3 0 3 0 2 2 2 1 2 1 1 2 3 0 1 3 2 0 3 3 3 0 2 2 2 3 1 0 1 0 1 1 3 0 0 2 1 1 3 1 3 3 2 0 2 2 1 1 0 1 0 2 3 1 2 3 ...

output:

36577 18616 60210 73423

result:

ok single line: '36577 18616 60210 73423'

Test #10:

score: 0
Accepted
time: 1462ms
memory: 9440kb

input:

82517
2 1 1 0 2 0 3 1 3 1 3 3 2 2 3 0 3 2 2 0 2 1 0 2 2 3 2 0 1 0 1 2 2 1 1 1 3 2 2 0 1 0 0 3 3 1 1 0 3 1 3 1 2 3 3 3 3 3 2 1 3 1 3 0 2 0 2 0 2 2 2 2 2 1 2 1 3 3 2 3 2 3 0 2 0 1 0 0 3 2 1 1 0 1 2 1 1 0 1 3 1 3 3 2 2 3 0 2 1 3 2 1 0 1 2 3 2 2 3 3 1 0 2 0 3 2 3 0 1 2 0 3 3 0 2 1 1 3 3 2 2 0 2 2 1 1 2 ...

output:

50863 68187 40176 82517

result:

ok single line: '50863 68187 40176 82517'

Test #11:

score: 0
Accepted
time: 1355ms
memory: 9188kb

input:

79392
0 2 2 2 0 3 2 3 1 1 1 0 0 3 1 3 3 0 2 2 0 0 0 2 1 0 2 2 2 1 2 3 2 0 3 3 3 2 0 1 0 1 1 1 0 1 0 1 0 2 3 3 0 1 2 3 0 1 0 1 0 1 2 2 1 3 0 0 1 3 1 2 2 1 0 0 2 1 0 0 2 2 3 1 3 0 3 2 0 0 0 0 3 3 0 0 2 2 0 2 0 2 3 1 0 2 2 1 2 2 0 3 3 3 2 1 3 1 1 1 1 2 0 0 1 1 1 0 1 1 1 3 3 0 2 3 1 1 0 1 2 3 1 3 3 0 0 ...

output:

68113 34911 26794 79392

result:

ok single line: '68113 34911 26794 79392'

Test #12:

score: -100
Time Limit Exceeded

input:

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

output:


result: