AtCoder Beginner Contest 346

A题: Adjacent Product

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    int t; cin >> t;
    for (int i = 2; i <= n; i ++ ) {
        int x; cin >> x;
        cout << x * t << ' ';
        t = x;
    }
    return 0;
}

B题: Piano

#include <bits/stdc++.h>
using namespace std;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int w, b; cin >> w >> b;
    string s = "wbwbwwbwbwbw";
    for (int i = 0; i < s.size(); i ++ ) {
        int x = 0, y = 0;
        for (int j = i, cnt = 1; cnt <= w + b; cnt ++, j = (j + 1) % s.size()) {
            if (s[j] == 'w') x ++;
            else y ++;
        }
        if (x == w && y == b) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
    return 0;
}

C题: Σ

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, k; cin >> n >> k;
    ll sum = (1 + k) * k / 2;
    set<ll> s;
    for (int i = 1; i <= n; i ++ ) {
        ll x; cin >> x;
        if (!s.count(x) && x >= 1 && x <= k) {
            s.insert(x);
            sum -= x;
        }
    }
    cout << sum << endl;
    return 0;
}

D题: Gomamayo Sequence

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5 + 9;
ll pre[N][2], suf[N][2];
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n; cin >> n;
    string s; cin >> s; s = " " + s;
    vector<int> a(n + 1);
    for (int i = 1; i <= n; i ++ ) cin >> a[i];
    for (int i = 1; i <= n; i ++ ) {
        pre[i][0] += pre[i - 1][1] + (s[i] == '0' ? 0 : a[i]);
        pre[i][1] += pre[i - 1][0] + (s[i] == '1' ? 0 : a[i]);
    }
    for (int i = n; i >= 1; i -- ) {
        suf[i][0] += suf[i + 1][1] + (s[i] == '0' ? 0 : a[i]);
        suf[i][1] += suf[i + 1][0] + (s[i] == '1' ? 0 : a[i]); 
    }
    ll ans = 1e18;
    for (int i = 1; i < n; i ++ ) 
        ans = min({ans, pre[i][0] + suf[i + 1][0], pre[i][1] + suf[i + 1][1]});
    cout << ans << endl;
    return 0;
}

E题: Paint

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    ll n, m, k; cin >> n >> m >> k;
    vector<array<ll, 3>> a(k + 1);
    for (int i = k; i >= 1; i -- ) {
        ll op, l, x; cin >> op >> l >> x;
        a[i] = {op, l, x};
    }
    set<ll> h, w;
    map<ll, ll> p;
    p[0] = n * m;
    for (int i = 1; i <= k; i ++ ) {
        auto&[op, l, x] = a[i];
        if (op == 1) {
            if (h.count(l)) continue;
            h.insert(l);
            if (m - w.size() > 0) {
                p[x] += m - w.size();
                p[0] -= m - w.size();
            }
        }else {
            if (w.count(l)) continue;
            w.insert(l);
            if (n - h.size() > 0) {
                p[x] += n - h.size();
                p[0] -= n - h.size();
            }
        }
    }
    if (!p[0]) p.erase(0);
    cout << p.size() << endl;
    for (auto&[x, y] : p) cout << x << ' ' << y << endl;
    return 0;
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值