QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#143245 | #6751. Game | Kidding_Ma | WA | 11ms | 3932kb | C++20 | 5.4kb | 2023-08-20 23:18:36 | 2023-08-20 23:18:38 |
Judging History
answer
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
using i128 = __int128;
namespace cpstd {
#define range(a) begin(a), end(a)
template <class T>
T max(const vector<T> &a) {
return *std::max_element(a.begin(), a.end());
}
template <class T>
T min(const vector<T> &a) {
return *std::min_element(a.begin(), a.end());
}
template <class T>
struct Fenwick {
int n;
std::vector<T> a;
Fenwick(const int &n = 0) : n(n), a(n, T()) {}
void modify(int i, T x) {
for (i++; i <= n; i += i & -i) {
a[i - 1] += x;
}
}
T get(int i) {
T res = T();
for (; i > 0; i -= i & -i) {
res += a[i - 1];
}
return res;
}
T sum(int l, int r) { // [l, r)
return get(r) - get(l);
}
T kth(T k) {
int x = 0;
for (int i = 1 << std::__lg(n); i; i >>= 1) {
if (x + i <= n && k >= a[x + i - 1]) {
x += i;
k -= a[x - 1];
}
}
return x;
}
};
template <class T>
T exgcd(T a, T b, T &x, T &y) {
if (!b) {
x = 1, y = 0;
return a;
}
T g = exgcd(b, a % b, y, x);
y -= a / b * x;
return g;
}
template <class T>
T floor_sum(T n, T m, T a, T b) {
T ans = 0;
if (a < 0) {
T a2 = (a % m + m) % m;
ans -= n * (n - 1) / 2 * ((a2 - a) / m);
a = a2;
}
if (b < 0) {
T b2 = (b % m + m) % m;
ans -= n * ((b2 - b) / m);
b = b2;
}
while (1) {
if (a >= m) {
ans += n * (n - 1) / 2 * (a / m);
a %= m;
}
if (b >= m) {
ans += n * (b / m);
b %= m;
}
T y_max = a * n + b;
if (y_max < m) {
break;
}
n = y_max / m;
b = y_max % m;
swap(m, a);
}
return ans;
}
template <class T, class U1, class U2>
T power(T a, U1 b, U2 p) {
T res = 1;
for (; b; b >>= 1, a = a * a % p) {
if (b & 1) {
res = res * a % p;
}
}
return res;
}
template <class T, class U>
T power(T a, U b) {
T res = 1;
for (; b; b >>= 1, a = a * a) {
if (b & 1) {
res = res * a;
}
}
return res;
}
__int128 abs(const __int128 &v) {
return (v < 0 ? -v : v);
}
std::mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
istream &operator>>(istream &is, __int128 &v) {
std::string s;
is >> s;
v = 0;
for (auto &si : s) {
v = v * 10 + si - '0';
}
return is;
}
ostream &operator<<(ostream &os, const __int128 &v) {
if (v <= 1000000000000000000) {
return os << (long long) (v);
}
return os << (long long) (v / 1000000000000000000) << std::setw(18) << std::setfill('0') << (long long) (v % 1000000000000000000);
}
template <class T>
T crt(const vector<T> &r, const vector<T> &m) {
int n = r.size();
T r0 = 0, m0 = 1;
for (int i = 0; i < n; i++) {
T m1 = m[i];
T r1 = r[i] % m1;
if (r1 < 0) {
r1 += m1;
}
if (m0 < m1) {
std::swap(r0, r1);
std::swap(m0, m1);
}
if (!(m0 % m1)) {
if (r0 % m1 != r1) {
return -1;
}
continue;
}
T x, y;
T g = exgcd(m0, m1, x, y);
if ((r1 - r0) % g) {
return -1;
}
T u1 = m1 / g;
r0 += (r1 - r0) / g % u1 * x % u1 * m0;
m0 *= u1;
if (r0 < 0) {
r0 += m0;
}
}
return r0;
}
constexpr int B = 777;
constexpr long long P = 100000000000031;
long long *p;
void initHash(int N) {
p = new long long [N + 1];
for (int i = 0; i <= N; i++) {
p[i] = 0;
}
p[0] = 1;
for (int i = 1; i <= N; i++) {
p[i] = p[i - 1] * B % P;
}
}
struct StringHash {
std::vector<long long> h;
StringHash() : h(1) {}
void push_back(char ch) {
h.push_back((h.back() * B + ch) % P);
}
long long get(int l, int r) { // [l, r)
return (h[r] + __int128(h[l]) * (P - p[r - l])) % P;
}
};
struct UnionFind {
int n;
std::vector<int> f, sz;
UnionFind(const int &n = 0) : n(n), f(n), sz(n, 1) {
std::iota(f.begin(), f.end(), 0);
}
int get(int x) {
while (x != f[x]) {
x = f[x] = f[f[x]];
}
return x;
}
bool unite(int x, int y) {
x = get(x), y = get(y);
if (x != y) {
f[y] = x;
sz[x] += sz[y];
return 1;
}
return 0;
}
bool united(int x, int y) {
return get(x) == get(y);
}
int size(int x) {
x = get(x);
return sz[x];
}
};
}
using namespace cpstd;
void solve() {
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
i64 sum = 0;
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum += a[i];
mx = max(mx, a[i]);
}
if (sum % 2 == 0 && mx <= sum / 2) {
cout << sum / 2 << '\n';
} else {
cout << sum - mx << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3460kb
input:
2 7 5
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 11ms
memory: 3896kb
input:
200000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
10000050000
result:
ok 1 number(s): "10000050000"
Test #3:
score: -100
Wrong Answer
time: 6ms
memory: 3932kb
input:
200000 861662489 745782129 265647834 549189505 370940221 849264541 392033409 728418798 198339990 783085331 609804410 358855280 393622065 778945552 40954966 557170903 603005334 323311229 205757461 358768170 600992776 530531842 353294276 91047369 31457845 490614287 352572900 59552090 942395591 4363418...
output:
100082488451252
result:
wrong answer 1st numbers differ - expected: '50041744223374', found: '100082488451252'