QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#389558#7993. 哈密顿O_start#WA 1ms5688kbC++143.6kb2024-04-14 15:29:392024-04-14 15:29:39

Judging History

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

  • [2024-04-14 15:29:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5688kb
  • [2024-04-14 15:29:39]
  • 提交

answer

#pragma oucGCC optimize(2)
#include<iostream>
#include<queue>
#include<cmath>
#include<vector>
#include<queue>
#include<cstring>
#include<algorithm>
#include<set>
#include<unordered_set>
#include<stack>
#include<map>
#include<unordered_map>
using namespace std;
long long  k, p, q, m, n;
const int maxn = 200005;
const long long inf = 0xfffffffffffff;
const int mod = 1e9 + 7;
int t;
string s;
struct Node {
	long long num;
	int type;
	int id;
}a[maxn];
bool cmp(Node a, Node b) {
	return a.num > b.num;
}
bool flag[maxn][2] = { 0 };
long long fact[maxn], infact[maxn];
long long qpow(long long a, long long b) {
	if (b < 0) return 0;
	long long ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		b >>= 1;
		a = (a * a) % mod;
	}
	return ans;
}
void init() {
	fact[0] = 1, infact[0] = 1;
	for (int i = 1; i < maxn; i++) {
		fact[i] = i * fact[i - 1] % mod;
		infact[i] = infact[i - 1] % mod * qpow(i, mod - 2) % mod;
	}
}
long long inv(long long n) {
	return qpow(n, mod - 2);
}
long long frac_mod(long long a, long long b) {
	return (a * inv(b) % mod) % mod;
}
long long nCr(long long n, long long r) {
	if (r > n || r < 0)
		return 0;
	if (n == r)
		return 1;
	if (r == 0)
		return 1;
	return (fact[n] * infact[r]) % mod * infact[n - r] % mod;
}
long long gcd(long long da, long long xiao) {
	while (xiao != 0) {
		long long temp = xiao;
		xiao = da % xiao;
		da = temp;
	}
	return(da);
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> n;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long tmp;
		cin >> tmp;
		a[i * 2].num = tmp;
		a[i * 2].type = 0;
		a[i * 2].id = i;
		ans += tmp;
		cin >> tmp;
		a[i * 2+1].num = tmp;
		a[i * 2+1].type = 1;
		a[i * 2+1].id = i;
		ans += tmp;
	}
	if (n == 2) {
		cout << max(max(max(a[0].num + a[1].num, a[2].num + a[3].num), a[0].num + a[2].num), a[1].num + a[3].num) << '\n';
	}
	else if (n == 3) {
		vector<long long>rec;
		rec.push_back(a[0].num + a[2].num + a[4].num);
		rec.push_back(a[1].num + a[3].num + a[5].num);
		rec.push_back(a[0].num + a[2].num + a[1].num);
		rec.push_back(a[0].num + a[2].num + a[3].num);
		rec.push_back(a[0].num + a[4].num + a[1].num);
		rec.push_back(a[0].num + a[4].num + a[5].num);
		rec.push_back(a[2].num + a[4].num + a[3].num);
		rec.push_back(a[2].num + a[4].num + a[5].num);
		rec.push_back(a[1].num + a[3].num + a[0].num);
		rec.push_back(a[1].num + a[3].num + a[2].num);
		rec.push_back(a[1].num + a[5].num + a[0].num);
		rec.push_back(a[1].num + a[5].num + a[4].num);
		rec.push_back(a[3].num + a[5].num + a[2].num);
		rec.push_back(a[3].num + a[5].num + a[4].num);
		long long res = 0;
		for (auto i : rec)res = max(res, i);
		cout << res * 2LL - ans << '\n';
	}
	else {
		long long res = 0;
		sort(a, a + 2 * n, cmp);
		int num0 = 0;
		int num1 = 0;
		for (int i = 0; i < n; i++) {
			res += a[i].num;
			flag[a[i].id][a[i].type] = 1;
			if (a[i].type == 0)num0++;
			else num1++;
		}
		if (num0 == 1) {
			int tmp;
			for (int i = 0; i < n; i++) {
				if (flag[i][0] == 1) {
					tmp = i;
					break;
				}
			}
			if (flag[tmp][1] == 1) {
				cout << res * 2LL - ans << '\n';
			}
			else {
				res += a[n].num - a[n - 1].num;
				cout << res * 2LL - ans << '\n';
			}
		}
		else if (num1 == 1) {
			int tmp;
			for (int i = 0; i < n; i++) {
				if (flag[i][1] == 1) {
					tmp = i;
					break;
				}
			}
			if (flag[tmp][0] == 1) {
				cout << res * 2LL - ans << '\n';
			}
			else {
				res += a[n].num - a[n - 1].num;
				cout << res * 2LL - ans << '\n';
			}
		}
		else {
			cout << res * 2LL - ans << '\n';
		}
	}
}

詳細信息

Test #1:

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

input:

3
1 10
8 2
4 5

output:

10

result:

ok single line: '10'

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5688kb

input:

2
732734236 669531729
368612323 916696032

output:

1586227761

result:

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