QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#172256#6320. Parallel Processing (Hard)ucup-team1209#WA 2ms6656kbC++202.3kb2023-09-09 18:26:432023-09-09 18:26:43

Judging History

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

  • [2023-09-09 18:26:43]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:6656kb
  • [2023-09-09 18:26:43]
  • 提交

answer

#include<bits/stdc++.h>
using std::cin;
using std::cout;
const int N = 100005;
using vec = std::vector<int>;
using vpi = std::vector<std::pair<int, int>>;
std::map<vec, int> map;
std::map<vec, vpi> deletes;
std::map<vec, vec> nxt;

int n;
int dfs(vec x) {
	if(x.empty()) return 0;
	if(map.count(x)) return map[x];

	int ans = 1e9;
	vpi del; vec nx;
	for(int i = 1;i < (1 << x.size());++i) {
		if(i & i >> 1) continue;
		int sum = 0;
		vec z;
		for(int j = 0;j < (int) x.size();++j) if(i >> j & 1) {
			sum += (j == (int) x.size() - 1 ? n : x[j + 1]) - x[j];
		} else {
			z.push_back(x[j]);
		}
		int co = (sum + 3) / 4 + dfs(z);
		if(co < ans) {
			ans = co;
			del.clear();
			for(int j = 0;j < (int) x.size();++j) if(i >> j & 1) {
				int nxt = j == (int) x.size() - 1 ? n : x[j + 1];
				for(int k = x[j];k < nxt;++k) del.emplace_back(x[j], k + 1);
			}
			nx = z;
		}
	}
	deletes[x] = del;
	nxt[x] = nx;
	return map[x] = ans;
}
std::string s[N];

int main() {
	cin >> n;
	vec v;
	for(int i = 1;i < n;++i) {
		v.push_back(i);
	}
	for(int i = 1;i <= n;++i) {
		if(i < 10) s[i] = '0' + i;
		else s[i] = 'a' + i - 10;
	}
	if(n >= 16) {
		if(n % 2) ++ n;
		int m = n / 4;
		vpi d;
		for(int i = 2;i <= m;++i) {
			for(int j = 0;j < 4;++j) {
				d.emplace_back(i - 1 + j * m, i + j * m);
			}
		}
		for(int i = 1;i < 4;++i) {
			if(n % 4) {
				if(i == 1) d.emplace_back(n - 1, n);
			}
			for(int j = m;j >= 1;--j) {
				d.emplace_back(i * m, i * m + j);
			}
		}
		if(n % 4) {
			d.emplace_back(n - 2, n - 1);
			d.emplace_back(n - 2, n);
		}
		for(;d.size() % 4;) d.emplace_back(2e3, 2e3);
		cout << d.size() / 4 << '\n';
		/*
		for(int j = 0;j < (int) d.size();j += 4) {
			std::set<int> s;
			for(int k = 0;k < 4;++k) {
				s.emplace(d[j + k].second);
			}
			// assert(s.size() == 4);
		}
		*/
		for(auto [u, v] : d) {
			cout << v << ' ' << u << ' ' << v << '\n';
			s[v] = s[u] + s[v];
		}
		// for(int i = 1;i <= n;++i) cout << s[i] << '\n';
		return 0;
	}
	dfs(v);
	cout << dfs(v) << '\n';
	return 0;
	for(;v.size();) {
		auto d = deletes[v];
		for(;d.size() % 4;) d.emplace_back(2e3, 2e3);

		for(auto [u, v] : d) {
			cout << v << ' ' << u << ' ' << v << '\n';
			s[v] = s[u] + s[v];
		}
		v = nxt[v];
	}
//	for(int i = 1;i <= n;++i) cout << s[i] << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

17

output:

7
2 1 2
6 5 6
10 9 10
14 13 14
3 2 3
7 6 7
11 10 11
15 14 15
4 3 4
8 7 8
12 11 12
16 15 16
18 17 18
8 4 8
7 4 7
6 4 6
5 4 5
12 8 12
11 8 11
10 8 10
9 8 9
16 12 16
15 12 15
14 12 14
13 12 13
17 16 17
18 16 18
2000 2000 2000

result:

ok AC

Test #2:

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

input:

18

output:

7
2 1 2
6 5 6
10 9 10
14 13 14
3 2 3
7 6 7
11 10 11
15 14 15
4 3 4
8 7 8
12 11 12
16 15 16
18 17 18
8 4 8
7 4 7
6 4 6
5 4 5
12 8 12
11 8 11
10 8 10
9 8 9
16 12 16
15 12 15
14 12 14
13 12 13
17 16 17
18 16 18
2000 2000 2000

result:

ok AC

Test #3:

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

input:

19

output:

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

result:

ok AC

Test #4:

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

input:

20

output:

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

result:

ok AC

Test #5:

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

input:

21

output:

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

result:

wrong answer L = 9 is larger than 8