/ WOJ / 讨论 / 分享 /

AWC0133

A:

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

void Main() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> t(n + 1);
    for (int i = 1; i <= n; ++i) {
        cin >> t[i];
    }
    vector<bool> canceled(n + 1);
    for (int i = 1; i <= m; ++i) {
        int d;
        cin >> d;
        canceled[d] = true;
    }
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        if (!canceled[i]) {
            res += t[i] / k;
        }
    }
    cout << res << endl;
}

// #define CP_MULTI_TEST_CASES

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
#ifdef CP_MULTI_TEST_CASES
    cin >> t;
#endif
    while (t--) {
        Main();
    }
    return cout << flush, fflush(stdout), 0;
}

B:

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

void Main() {
    int n;
    int k;
    int t;
    cin >> n >> k >> t;
    vector<int> a(n + 1);
    vector<int> b;
    b.reserve(n);
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        if (i != t) {
            b.push_back(a[i]);
        }
    }
    sort(b.begin(), b.end(), greater<int>());
    int res = a[t];
    for (int i = 0; i < k - 1; ++i) {
        res += b[i];
    }
    cout << res << endl;
}

// #define CP_MULTI_TEST_CASES

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
#ifdef CP_MULTI_TEST_CASES
    cin >> t;
#endif
    while (t--) {
        Main();
    }
    return cout << flush, fflush(stdout), 0;
}

C:

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

void Main() {
    int n, k;
    cin >> n >> k;
    vector<vector<int>> adj(n + 1);
    for (int i = 2; i <= n; ++i) {
        int p;
        cin >> p;
        adj[p].push_back(i);
    }
    function<int(int)> get_sz = [&](int u) -> int {
        int sz = 1;
        for (const int &v : adj[u]) {
            sz += get_sz(v);
        }
        return sz;
    };
    const int res = n - get_sz(k);
    cout << res << endl;
}

// #define CP_MULTI_TEST_CASES

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
#ifdef CP_MULTI_TEST_CASES
    cin >> t;
#endif
    while (t--) {
        Main();
    }
    return cout << flush, fflush(stdout), 0;
}

D:

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

void Main() {
    int n, t;
    cin >> n >> t;
    vector<vector<pair<int, int>>> req(t + 1);
    for (int i = 1; i <= n; ++i) {
        int l, r, v;
        cin >> l >> r >> v;
        req[r].emplace_back(l, v);
    }
    vector<int> dp(t + 1);
    for (int i = 1; i <= t; ++i) {
        dp[i] = dp[i - 1];
        for (const auto &[l, v] : req[i]) {
            dp[i] = max(dp[i], dp[l - 1] + v);
        }
    }
    int res = dp[t];
    cout << res << endl;
}

// #define CP_MULTI_TEST_CASES

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
#ifdef CP_MULTI_TEST_CASES
    cin >> t;
#endif
    while (t--) {
        Main();
    }
    return cout << flush, fflush(stdout), 0;
}

E:

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

void Main() {
    int n, m, k, t;
    cin >> n >> m >> k >> t;
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        vector<int> s(m + 1);
        for (int j = 1; j <= m; ++j) {
            cin >> s[j];
        }
        deque<int> mxq, mnq;
        int mxdf = 0;
        for (int j = 1; j <= m; ++j) {
            while (!mxq.empty() && s[mxq.back()] <= s[j]) {
                mxq.pop_back();
            }
            mxq.push_back(j);
            while (!mnq.empty() && s[mnq.back()] >= s[j]) {
                mnq.pop_back();
            }
            mnq.push_back(j);
            while (mxq.front() <= j - k) {
                mxq.pop_front();
            }
            while (mnq.front() <= j - k) {
                mnq.pop_front();
            }
            if (j >= k) {
                const int cur = s[mxq.front()] - s[mnq.front()];
                mxdf = max(mxdf, cur);
            }
        }
        if (mxdf >= t) {
            ++res;
        }
    }
    cout << res << endl;
}

// #define CP_MULTI_TEST_CASES

signed main() {
    ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
    int t = 1;
#ifdef CP_MULTI_TEST_CASES
    cin >> t;
#endif
    while (t--) {
        Main();
    }
    return cout << flush, fflush(stdout), 0;
}

0 条评论

目前还没有评论...