QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#883834#10052. Just Long Neckties 2TianTian20080 101ms32592kbC++141.1kb2025-02-05 19:17:532025-02-05 19:17:53

Judging History

This is the latest submission verdict.

  • [2025-02-05 19:17:53]
  • Judged
  • Verdict: 0
  • Time: 101ms
  • Memory: 32592kb
  • [2025-02-05 19:17:53]
  • Submitted

answer

#include <bits/stdc++.h>

using namespace std;

namespace FastRead{
	char buf[1 << 20 | 5], *s = buf, *t = buf;
	#ifdef LOCAL
	#define gc() getchar()
	#else
	#define gc() s == t && (t = (s = buf) + fread(buf, 1, 1 << 20, stdin), s == t) ? EOF : *s ++ 
	#endif
	template <typename T>
	inline void Read(T &x)
	{
		x = 0;
		char ch = gc();
		while(ch < '0' || ch > '9') ch = gc();
		while('0' <= ch && ch <= '9') x = (x * 10) + (ch ^ 48), ch = gc();
	}
}
using FastRead::Read;

const int N = 5e6 + 5, M = 1 << 21 | 5;

int n, m;
int a[N];
int f[M];

int main()
{
	Read(n);
	for(int i = 1; i <= n; i ++ )
	{
		Read(a[i]);
		m = max(m, a[i]);
		a[i] -- ;
	}
	
	int ans = m;
	for(int i = 0; i < 1 << m; i ++ )
	{
		int k = __builtin_popcount(i);
		while(f[i] < n - 1 && (((i >> a[f[i] + 1]) | (i >> a[f[i] + 2])) & 1)) f[i] ++ ;
		if(f[i] >= n - 1) ans = k;
		for(int j = 1; j < m; j ++ )
			f[(i ^ (1 << (j - 1))) | (1 << j)] = max(f[(i ^ (1 << (j - 1))) | (1 << j)], f[i]);
		f[i | 1] = max(f[i | 1], f[i]);
	}
	
	printf("%d\n", ans);
	return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 27ms
memory: 9680kb

input:

15
2 19 3 6 1 18 20 9 17 19 18 4 15 7 16

output:

20

result:

wrong answer 1st lines differ - expected: '3', found: '20'

Subtask #2:

score: 0
Wrong Answer

Test #19:

score: 6
Accepted
time: 0ms
memory: 5840kb

input:

500
1 1 2 2 2 2 2 1 2 2 1 1 1 1 2 1 1 2 1 2 1 2 1 1 2 2 2 2 1 1 1 2 2 1 1 1 2 1 1 1 1 1 2 1 2 2 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 1 1 1 2 2 1 2 1 1 2 1 2 2 1 1 1 2 1 2 1 1 2 2 2 1 2 2 2 2 1 1 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 2 2 2 2 2 1 1 1 2 1 1 2 1 2 2 2 1 1 1 1 2 2 2 2 1 1 2 2 1 2 2 1 2 2 2 1 2 2 1 1 ...

output:

2

result:

ok single line: '2'

Test #20:

score: 6
Accepted
time: 0ms
memory: 7880kb

input:

500
1 2 1 1 2 2 1 2 1 1 2 1 2 1 1 1 1 2 2 1 1 2 2 2 1 1 1 1 2 2 1 2 1 2 2 2 1 1 2 2 2 1 1 1 1 2 1 1 2 1 1 2 2 1 2 2 1 1 1 1 2 2 2 2 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 1 1 2 2 1 1 1 1 2 2 2 2 1 1 1 1 1 2 1 2 2 2 2 1 2 1 2 2 1 1 1 2 2 1 1 1 2 2 1 2 2 2 1 1 1 2 2 1 1 2 2 2 2 1 1 ...

output:

2

result:

ok single line: '2'

Test #21:

score: 0
Wrong Answer
time: 0ms
memory: 7880kb

input:

500
2 1 2 2 2 2 2 2 2 1 2 2 1 2 1 2 1 2 1 2 2 1 2 1 2 2 2 1 2 2 1 2 2 2 2 1 2 2 1 2 1 2 2 2 2 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 1 2 2 1 2 1 2 2 1 2 2 1 2 2 1 2 1 2 1 2 1 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 1 2 2 2 2 2 1 2 1 2 2 1 2 2 2 1 2 2 1 2 1 2 1 2 1 2 2 1 2 2 1 2 1 2 1 2 1 2 1 2 2 2 1 2 1 2 2 2 2 1 2 ...

output:

2

result:

wrong answer 1st lines differ - expected: '1', found: '2'

Subtask #3:

score: 0
Wrong Answer

Test #34:

score: 12
Accepted
time: 0ms
memory: 7796kb

input:

500
2 5 4 4 4 1 1 4 5 1 1 2 2 1 4 3 3 1 4 5 4 3 1 1 3 4 4 2 2 3 1 1 1 1 3 3 5 2 1 2 1 1 4 1 4 4 1 2 2 5 3 4 2 3 2 3 5 3 3 1 5 3 4 5 1 2 5 5 2 1 5 1 4 2 2 2 1 2 1 2 2 1 4 2 3 5 1 2 5 2 1 2 5 3 3 5 3 1 3 4 3 3 1 3 4 4 5 1 2 2 2 3 2 5 3 5 3 1 4 5 1 1 5 3 3 5 4 3 1 5 1 5 5 1 5 5 2 4 3 2 5 3 3 2 4 3 1 3 ...

output:

5

result:

ok single line: '5'

Test #35:

score: 12
Accepted
time: 0ms
memory: 7884kb

input:

500
4 5 3 3 2 5 3 2 4 3 5 4 1 5 2 2 2 4 2 1 5 5 5 1 1 2 3 1 4 4 2 3 3 3 1 4 4 1 2 1 1 1 4 2 3 1 4 1 3 3 5 4 5 2 3 5 1 5 1 2 2 5 2 2 5 1 4 2 4 2 2 1 4 5 3 2 2 2 2 2 3 1 1 5 2 4 2 4 2 2 3 2 5 3 2 1 2 5 5 2 3 1 4 5 1 4 4 4 1 3 4 1 1 3 2 5 1 4 4 2 3 1 5 5 4 2 4 1 4 3 2 1 3 4 4 3 1 3 2 5 3 3 5 5 4 4 4 5 ...

output:

5

result:

ok single line: '5'

Test #36:

score: 0
Wrong Answer
time: 0ms
memory: 7876kb

input:

500
1 1 4 1 1 3 1 1 3 1 5 1 1 1 5 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 3 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 3 1 1 1 1 4 1 1 2 1 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 4 1 3 1 1 1 2 2 4 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 4 2 2 1 2 2 2 2 2 2 5 2 2 1 2 3 2 2 1 2 2 2 2 2 5 2 2 1 ...

output:

5

result:

wrong answer 1st lines differ - expected: '1', found: '5'

Subtask #4:

score: 0
Wrong Answer

Test #53:

score: 0
Wrong Answer
time: 0ms
memory: 8004kb

input:

500
2 1 12 3 13 13 7 9 7 3 14 10 9 13 6 3 9 1 10 10 7 13 6 9 10 13 3 7 15 12 14 4 1 5 4 3 8 7 3 14 5 1 6 13 1 3 4 10 5 8 3 6 2 4 10 1 13 5 6 13 12 10 14 15 8 9 13 10 9 14 4 9 13 12 4 7 12 4 2 14 6 12 5 4 6 12 13 6 2 12 10 5 6 5 1 1 5 1 5 12 11 3 6 13 11 10 1 8 14 9 5 5 15 1 15 3 15 10 4 6 9 14 1 5 1...

output:

15

result:

wrong answer 1st lines differ - expected: '10', found: '15'

Subtask #5:

score: 0
Wrong Answer

Test #73:

score: 26
Accepted
time: 5ms
memory: 10928kb

input:

500000
13 6 2 6 3 6 13 5 9 8 4 12 10 7 1 7 10 14 15 15 1 9 4 4 1 14 3 8 13 2 8 11 14 14 4 13 8 9 13 14 9 7 3 15 7 7 1 11 11 11 2 13 11 15 3 4 8 12 9 4 10 4 10 13 4 9 14 11 7 13 10 4 9 14 12 14 11 5 7 6 14 1 6 14 10 9 2 14 8 8 8 9 7 1 15 3 11 3 3 5 13 1 15 7 4 7 15 3 15 14 14 2 4 12 5 13 12 11 3 1 12...

output:

15

result:

ok single line: '15'

Test #74:

score: 26
Accepted
time: 5ms
memory: 10536kb

input:

500000
8 7 9 12 2 7 1 11 10 12 14 3 1 4 10 12 8 12 7 14 2 3 4 8 3 8 14 13 4 10 6 10 6 10 6 12 7 2 3 4 9 13 13 2 2 8 9 6 2 1 9 3 9 6 3 8 12 3 4 7 2 6 12 12 4 9 3 15 1 7 2 1 9 14 2 8 12 6 14 6 6 10 2 15 2 14 11 1 1 2 13 9 1 14 2 5 2 13 1 9 15 7 3 12 10 10 5 13 8 9 6 6 8 9 4 8 1 2 10 13 4 7 15 9 4 14 7...

output:

15

result:

ok single line: '15'

Test #75:

score: 0
Wrong Answer
time: 3ms
memory: 10564kb

input:

500000
1 6 1 1 1 1 1 1 1 4 1 9 1 1 1 1 1 1 1 1 1 1 10 1 1 11 1 1 1 10 1 13 1 1 1 1 6 1 1 1 1 9 1 1 1 1 14 1 1 1 4 1 1 11 1 1 7 1 12 1 1 1 8 1 1 1 3 1 1 1 1 15 1 1 1 1 11 1 8 1 1 1 1 1 8 1 1 1 1 8 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 11 1 13 1 1 1 13 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 5 1 1 10 1 1 1 1 1 ...

output:

15

result:

wrong answer 1st lines differ - expected: '1', found: '15'

Subtask #6:

score: 0
Wrong Answer

Test #93:

score: 10
Accepted
time: 57ms
memory: 15692kb

input:

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

output:

21

result:

ok single line: '21'

Test #94:

score: 10
Accepted
time: 64ms
memory: 15308kb

input:

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

output:

21

result:

ok single line: '21'

Test #95:

score: 0
Wrong Answer
time: 59ms
memory: 16100kb

input:

500000
1 1 1 14 1 1 14 1 1 1 1 1 1 1 1 1 1 12 1 1 1 1 13 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 12 1 1 1 12 1 1 1 1 1 1 1 1 1 5 1 1 1 20 1 1 1 1 1 1 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 1 17 1 3 1 1 1 1 13 1 1 1 1 1 17 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 19 1 5 1 1 11 1 1 1 1 1 15 1 16 1 1 1 8 1 1 17 1 1 1 20 1 1 1 1 1 1...

output:

21

result:

wrong answer 1st lines differ - expected: '1', found: '21'

Subtask #7:

score: 0
Wrong Answer

Test #122:

score: 18
Accepted
time: 97ms
memory: 32424kb

input:

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

output:

21

result:

ok single line: '21'

Test #123:

score: 18
Accepted
time: 101ms
memory: 32592kb

input:

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

output:

21

result:

ok single line: '21'

Test #124:

score: 0
Wrong Answer
time: 85ms
memory: 32460kb

input:

5000000
1 1 1 1 1 1 9 1 1 7 1 8 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 11 1 1 1 1 1 1 1 17 1 14 1 1 1 4 1 1 1 11 1 1 20 1 14 1 1 1 1 1 1 1 6 1 1 1 1 1 21 1 1 1 1 1 1 1 1 1 1 7 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 8 1 1 1 1 1 1 19 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 15 1 1 11 1 1 1 7 1 1 1 1 1 1 1 1 1 1 1 ...

output:

21

result:

wrong answer 1st lines differ - expected: '1', found: '21'