QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#389549 | #7993. 哈密顿 | O_start# | WA | 1ms | 5744kb | C++14 | 3.3kb | 2024-04-14 15:20:11 | 2024-04-14 15:20:11 |
Judging History
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 {
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 {
if (n == 3) {
if (a[n].id == a[n-1].id) {
res += a[n+1].num - a[n - 1].num;
cout << res * 2LL - ans << '\n';
}
else {
res += a[n].num - a[n - 1].num;
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 {
if (n == 3) {
if (a[n].id == a[n - 1].id) {
res += a[n + 1].num - a[n - 1].num;
cout << res * 2LL - ans << '\n';
}
else {
res += a[n].num - a[n - 1].num;
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';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5716kb
input:
3 1 10 8 2 4 5
output:
10
result:
ok single line: '10'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5744kb
input:
2 732734236 669531729 368612323 916696032
output:
1586227761
result:
wrong answer 1st lines differ - expected: '484881202', found: '1586227761'