QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#326290#7993. 哈密顿ckisekiWA 5ms7500kbC++202.6kb2024-02-12 19:46:402024-02-12 19:46:40

Judging History

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

  • [2024-02-12 19:46:40]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:7500kb
  • [2024-02-12 19:46:40]
  • 提交

answer

#pragma GCC optimize("Ofast,no-stack-protector")
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define F(i,n) for (int i = 0; i < n; ++i)
#define F1(i,n) for (int i = 1; i <= n; ++i)
#define dbg(x) cerr << #x << " = " << x << endl
#define dbgg(x) cerr << #x << " = " << x << ' '
#define T(x) x[pool]
#define mineq(x,y) { if ((x) > (y)) (x) = (y); }
#define maxeq(x,y) { if ((x) < (y)) (x) = (y); }
#define MEOW { cout << "meowwwww" << '\n'; system("pause"); }
#define int long long
using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>
ostream& operator <<(ostream &s, const vector<T> &c)
{
	s << "[ "; for (auto it : c) s << it << " "; s << "\b]\n";
	return s;
}

template<typename T>
ostream& operator <<(ostream &s, const pair<int, T> &c)
{
	s << "[ "; cout << c.fi << " , " << c.se << " ] ";
	return s;
}

const int maxn = 234567, mod = 1000000007;

#define fac_init() fact(maxn - 1, 1);
#define C(x,y) ((fact(x, 2) * fact(y, 3) % mod) * fact((x) - (y), 3) % mod)

int fact(int cur, int mode)
{
	static int f[maxn], g[maxn];
	if (mode == 1)
	{
		f[0] = 1;
		F1 (i, cur) f[i] = f[i - 1] * i % mod;
		g[cur] = 1;
		int a = f[cur], b = (mod - 2) << 1;
		while (b >>= 1)
		{
			if (b & 1) g[cur] = g[cur] * a % mod;
			a = a * a % mod;
		}
		for (int i = cur - 1; i >= 0; --i)
			g[i] = g[i + 1] * (i + 1) % mod;
		return 0;
	} else if (mode == 2) return f[cur];
	else return g[cur];
}

int n;
int a[maxn], b[maxn];
int c[maxn];

void input()
{
	ios::sync_with_stdio(false); cin.tie(0);
	cin >> n;
	F1 (i, n) cin >> a[i] >> b[i];
}

void solve()
{
	vpii v;
	F1 (i, n)
	{
		v.pb(mp(a[i], i));
		v.pb(mp(b[i], i));
	}
	sort(all(v));
	F1 (i, n) ++c[v[i - 1].se];
	int cnt = 0;
	F1 (i, n) if (c[i] == 1) ++cnt;
	int ans = 0;
	F1 (i, n) ans += v[i - 1].fi;
	do
	{
		if (cnt == n)
		{
			cnt = 0;
			F1 (i, n) if (v[i - 1].fi == a[v[i - 1].se]) ++cnt;
			if (cnt == n) break;
			cnt = 0;
			F1 (i, n) if (v[i - 1].fi == b[v[i - 1].se]) ++cnt;
			if (cnt == n) break;
			multiset<int> s;
			F1 (i, n) s.insert(v[i - 1].fi);
			int sum = ans;
			ans = 123456789123456789ll;
			F1 (i, n)
			{
				int cur = sum + max(a[i], b[i]);
				s.erase(min(a[i], b[i]));
				cur -= *s.rbegin();
				s.insert(min(a[i], b[i]));
				ans = min(ans, cur);
			}
		}
	} while (0);
	ans *= -2;
	F1 (i, n) ans += a[i] + b[i];
	cout << ans << '\n';
}

main()
{
	fac_init();
	input();
	solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 7292kb

input:

3
1 10
8 2
4 5

output:

10

result:

ok single line: '10'

Test #2:

score: -100
Wrong Answer
time: 5ms
memory: 7500kb

input:

2
732734236 669531729
368612323 916696032

output:

116957610

result:

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