QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#143248#6751. GameKidding_MaAC ✓11ms3940kbC++205.4kb2023-08-20 23:24:252023-08-20 23:24:29

Judging History

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

  • [2023-08-20 23:24:29]
  • 评测
  • 测评结果:AC
  • 用时:11ms
  • 内存:3940kb
  • [2023-08-20 23:24:25]
  • 提交

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 (mx * 2 <= sum) {
        cout << sum / 2 << '\n';
    } else {
        cout << sum - mx << '\n';
    }
    return 0;
}

详细

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: 3920kb

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: 0
Accepted
time: 7ms
memory: 3868kb

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:

50041744223374

result:

ok 1 number(s): "50041744223374"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

2
935731565 82105791

output:

82105791

result:

ok 1 number(s): "82105791"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3588kb

input:

3
171939825 807658157 660882486

output:

820240234

result:

ok 1 number(s): "820240234"

Test #6:

score: 0
Accepted
time: 1ms
memory: 3556kb

input:

3
587965118 408133317 80363283

output:

488496600

result:

ok 1 number(s): "488496600"

Test #7:

score: 0
Accepted
time: 1ms
memory: 3548kb

input:

3
587892759 387652767 805243353

output:

890394439

result:

ok 1 number(s): "890394439"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

3
323926161 274794059 912783085

output:

598720220

result:

ok 1 number(s): "598720220"

Test #9:

score: 0
Accepted
time: 1ms
memory: 3516kb

input:

4
469392609 458382533 411521312 498263282

output:

918779868

result:

ok 1 number(s): "918779868"

Test #10:

score: 0
Accepted
time: 9ms
memory: 3940kb

input:

200000
100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 1...

output:

19999900

result:

ok 1 number(s): "19999900"