QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#331006#6537. One, Two, Three5abWA 2ms8048kbC++202.9kb2024-02-17 22:02:502024-02-17 22:02:51

Judging History

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

  • [2024-02-17 22:02:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:8048kb
  • [2024-02-17 22:02:50]
  • 提交

answer

/* name: 6537
 * author: 5ab
 * created at: 2024-02-17
 */
#include <iostream>
#include <cassert>
#include <deque>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = long long;
const int N = 6e6, INF = 1045141919;

int a[N], s[N + 1][4], t[N][4];
// s: >= l 的第一个 x
// t: <= l 的第一个 x

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int n, c[4] = {}, cnt[4];
	
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		for (int j = 1; j <= 3; j++)
			s[i][j] = c[j];
		c[a[i]]++;
	}
	for (int j = 1; j <= 3; j++)
		s[n][j] = c[j];
	copy(c, c + 4, cnt);
	for (int i = n - 1; i >= 0; i--)
	{
		for (int j = 1; j <= 3; j++)
			t[i][j] = c[j] - 1;
		c[a[i]]--;
	}
	
	int xl = 0, yl = 0;
	for (int i = 0, j = n - 1; i < j; i++, j--)
	{
		while (i < n && a[i] != 1)
			i++;
		while (j >= 0 && a[j] != 3)
			j--;
		if (i >= j)
			break;
		xl++;
	}
	for (int i = 0, j = n - 1; i < j; i++, j--)
	{
		while (i < n && a[i] != 3)
			i++;
		while (j >= 0 && a[j] != 1)
			j--;
		if (i >= j)
			break;
		yl++;
	}
	int xyl = xl + yl;
	
	int xlm = -INF, ylm = -INF, xylm = -INF;
	for (int i = 0; i < n; i++)
	{
		chmax(xlm, s[i][2] - s[i][1]);
		chmin(xl, s[i + 1][2] - t[i][3] - xlm + cnt[3] - 1);
		chmax(ylm, s[i][2] - s[i][3]);
		chmin(yl, s[i + 1][2] - t[i][1] - ylm + cnt[1] - 1);
		chmax(xylm, s[i][2] - s[i][1] - s[i][3]);
		chmin(xyl, s[i + 1][2] - t[i][3] - t[i][1] - xylm + cnt[1] + cnt[3] - 2);
	}
	cout << min(xyl, xl + yl) << endl;
	
	xyl = xl + yl - xyl;
	int d = min(xyl, yl);
	yl -= d, xyl -= d;
	xl -= min(xyl, xl);
	
	// cerr << xl << " " << yl << endl;
	
	deque<int> sp1, sp3, tp1, tp3;
	
	c[1] = c[3] = 0;
	for (int i = 0; i < n; i++)
	{
		if (c[1] < xl && a[i] == 1)
			sp1.push_back(i);
		if (c[3] < yl && a[i] == 3)
			sp3.push_back(i);
		c[a[i]]++;
	}
	c[1] = c[3] = 0;
	for (int i = n - 1; i >= 0; i--)
	{
		if (c[1] < yl && a[i] == 1)
			tp1.push_front(i);
		if (c[3] < xl && a[i] == 3)
			tp3.push_front(i);
		c[a[i]]++;
	}
	
	auto popX = [&](int i)
	{
		cout << sp1.front() << " " << i << " " << tp3.front() << "\n";
		sp1.pop_front(), tp3.pop_front();
	};
	auto popY = [&](int i)
	{
		cout << sp3.front() << " " << i << " " << tp1.front() << "\n";
		sp3.pop_front(), tp1.pop_front();
	};
	
	for (int i = 0; i < n; i++)
		if (a[i] == 2)
		{
			if (!sp1.empty() && sp1.front() < i)
			{
				if (!sp3.empty() && sp3.front() < i)
				{
					if (tp1.front() < tp3.front())
						popY(i);
					else
						popX(i);
				}
				else
					popX(i);
			}
			else if (!sp3.empty() && sp3.front() < i)
				popY(i);
		}
	
	return 0;
}
// started coding at: 02-17 21:26:26

详细

Test #1:

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

input:

6
3 1 2 2 3 1

output:

2
1 2 4
0 3 5

result:

ok count=2

Test #2:

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

input:

6
2 1 3 1 3 2

output:

0

result:

ok count=0

Test #3:

score: 0
Accepted
time: 2ms
memory: 7740kb

input:

3000
1 1 1 1 1 3 1 1 3 3 1 3 1 1 2 3 1 1 2 1 2 1 3 3 3 1 1 2 1 2 2 3 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 3 3 1 1 2 1 1 2 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 1 2 3 1 1 1 1 3 3 2 1 3 1 1 2 3 1 2 3 1 1 1 2 1 1 1 1 2 3 2 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 3 1 3 3 1 1 1 1 3 1 1 2 1 1 1 3 3 1 1 1 1 2 1 1 1 1 1 2 3 3 1...

output:

499
0 14 604
1 18 607
2 20 616
3 27 624
4 29 627
6 30 639
7 39 651
10 46 661
12 51 673
13 54 681
16 60 687
17 67 697
19 71 699
21 79 704
25 84 706
26 87 714
28 92 727
32 97 728
33 99 730
34 105 735
35 113 736
36 128 740
37 138 743
38 144 744
40 148 747
41 162 750
42 167 754
43 168 755
44 176 758
45 ...

result:

ok count=499

Test #4:

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

input:

3000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1
0 1374 2901

result:

ok count=1

Test #5:

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

input:

3000
2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...

output:

1
1755 1756 2819

result:

ok count=1

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 7724kb

input:

1500
1 1 1 2 1 1 1 2 2 2 2 2 1 1 3 1 2 2 3 1 2 2 2 2 1 2 1 2 1 1 3 1 2 2 2 2 1 1 3 1 1 2 2 3 2 1 3 1 1 2 2 2 1 2 2 2 2 2 1 2 3 2 3 2 3 2 1 3 2 1 2 3 2 2 3 2 3 1 1 3 1 3 1 3 3 3 1 3 3 3 1 1 3 1 3 1 3 1 1 1 3 1 3 1 3 3 1 1 1 3 1 1 3 1 1 1 1 1 3 3 3 3 1 3 1 1 1 1 3 3 3 3 3 3 1 3 1 1 1 3 1 3 1 1 1 1 3 1...

output:

494
0 3 542
1 7 544
2 8 545
4 9 547
5 10 550
6 11 554
14 16 541
12 17 557
18 20 543
13 21 558
15 22 559
19 23 563
24 25 564
26 27 566
30 32 546
28 33 570
29 34 573
31 35 576
38 41 548
36 42 577
43 44 549
46 49 551
37 50 580
39 51 581
40 53 582
45 54 599
47 55 601
48 56 602
52 57 607
58 59 608
60 61 ...

result:

wrong answer the number of matches is different