QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#759805#5080. Folding Stickgugugaga#WA 0ms3624kbC++204.4kb2024-11-18 12:14:462024-11-18 12:14:46

Judging History

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

  • [2024-11-18 12:14:46]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-11-18 12:14:46]
  • 提交

answer

/*************************************
*    author: marvinthang             *
*    created: 18.11.2024 10:59:54    *
*************************************/

#include <bits/stdc++.h>

using namespace std;

#define             fi  first
#define             se  second
#define           left  ___left___
#define          right  ___right___
#define   scan_op(...)  istream & operator >> (istream &in, __VA_ARGS__ &u)
#define  print_op(...)  ostream & operator << (ostream &out, const __VA_ARGS__ &u)
#define     file(name)  if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
#ifdef LOCAL
    #include "debug.h"
#else
    #define DB(...)
    #define db(...) ""
    #define debug(...)
#endif

namespace std {
template <class U, class V> scan_op(pair <U, V>) { return in >> u.first >> u.second; }
template <class T> scan_op(vector <T>) { for (size_t i = 0; i < u.size(); ++i) in >> u[i]; return in; }
template <class U, class V> print_op(pair <U, V>) { return out << '(' << u.first << ", " << u.second << ')'; }
template <size_t i, class T> ostream &print_tuple_utils(ostream &out, const T &tup) { if constexpr(i == tuple_size<T>::value) return out << ")"; else return print_tuple_utils<i + 1, T>(out << (i ? ", " : "(") << get<i>(tup), tup); }
template <class...U> print_op(tuple <U...>) { return print_tuple_utils<0, tuple <U...>>(out, u); }
template <class Con, class = decltype(begin(declval<Con>()))>typename enable_if <!is_same<Con, string>::value, ostream &>::type operator << (ostream &out, const Con &con) { out << '{'; for (__typeof(con.begin()) it = con.begin(); it != con.end(); ++it) out << (it == con.begin() ? "" : ", ") << *it; return out << '}'; }
template <class T> print_op(stack <T>) { vector <T> v; stack <T> st = u; while (!st.empty()) v.push_back(st.top()), st.pop(); reverse(v.begin(), v.end()); return out << v; }
template <class T> print_op(queue <T>) { queue <T> q = u; out << '{'; while (!q.empty()) { out << q.front(); q.pop(); if (!q.empty()) out << ", "; } out << '}'; return out; }
template <class T, class X, class Y> print_op(priority_queue <T, X, Y>) { priority_queue <T, X, Y> pq = u; out << '{'; while (!pq.empty()) { out << pq.top(); pq.pop(); if (!pq.empty()) out << ", "; } out << '}'; return out; }
template <class Fun> class y_combinator_result { Fun fun_; public: template <class T> explicit y_combinator_result(T &&fun): fun_(forward<T>(fun)) {} template <class...Args> decltype(auto)operator()(Args &&...args) { return fun_(ref(*this), forward<Args>(args)...); } };
template <class Fun> decltype(auto)y_combinator(Fun &&fun) { return y_combinator_result<decay_t<Fun>>(forward<Fun>(fun)); }
template <typename T, int D> struct Vec: public vector <Vec<T, D - 1>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template <typename ...Args> Vec(int n = 0, Args ...args): vector <Vec<T, D - 1>>(n, Vec<T, D - 1>(args...)) {} };
template <typename T> struct Vec<T, 1>: public vector<T>{ Vec(int n = 0, const T &val = T()): vector<T>(n, val) {} };
#if __cplusplus < 202002L
    template <class T> int ssize(const T &a) { return a.size(); }
#endif
}

void process(void) {
    int n; cin >> n;

    vector<int> a(n + 1), s(n + 1), f(n + 1), g(n + 1);

    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }

    f[0] = 0;

    for (int i = 1; i <= n; i++) {
        g[i] = max(g[i], g[i - 1]);
        // for (int j = 0; j < i; j++) if (f[j] <= i) {
        //     last = j;
        // }
        int last = g[i];
        assert(last != -1);
        int k = lower_bound(s.begin(), s.end(), 2 * s[i] - s[last]) - s.begin();
        f[i] = k;
        g[f[i]] = max(g[f[i]], i);

        // cout << f[i] << " " << i << " " << last << endl;
    }

    int ans = 2e9;

    for (int i = 1; i <= n; i++) {
        int l = f[i], r = n + 1;

        auto eval = [&] (int x) {
            return max(s[n] - s[x], s[x] - s[i]);
        };  
        while (r - l > 1) {
            int mid = (l + r) >> 1;
            if (eval(mid) <= eval(mid + 1)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        ans = min(ans, eval(l));
    }

    cout << ans;
}

int main(void) {
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    file("test");
    // int t; cin >> t; while (t--)
    process();
    return (0^0);
}

详细

Test #1:

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

input:

4
3 2 2 3

output:

4

result:

ok single line: '4'

Test #2:

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

input:

5
1 1 1 1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

7
1 3 2 3 4 2 2

output:

6

result:

ok single line: '6'

Test #4:

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

input:

9
5 6 3 4 8 8 2 2 5

output:

6

result:

wrong answer 1st lines differ - expected: '9', found: '6'