QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#140797#6310. Dining ProfessorssupepapupuWA 4ms3628kbC++171.5kb2023-08-16 20:30:482023-08-16 20:30:50

Judging History

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

  • [2023-08-16 20:30:50]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:3628kb
  • [2023-08-16 20:30:48]
  • 提交

answer

#include <bits/stdc++.h>

#define x first
#define y second
#define el '\n'
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 3e5 + 10, INF = 0x3f3f3f3f, mod = 998244353;

inline int read() {
    int f = 1, k = 0;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        k = k * 10 + c - '0';
        c = getchar();
    }
    return f * k;
}

int main() {
    int n = read(), k = read();
    vector<int> a(n + 2);
    vector<bool> st(n + 1);
    for (int i = 1; i <= n; ++i) a[i] = read();
    a[0] = a[n], a[n + 1] = a[1];
    for (int i = 1; i <= n; ++i) {
        if (k && a[i - 1] + a[i] + a[i + 1] == 3) {
            --k;
            st[i] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (!st[i] && k && a[i - 1] + a[i] + a[i + 1] == 2) {
            --k;
            st[i] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (!st[i] && k && a[i - 1] + a[i] + a[i + 1] == 1) {
            --k;
            st[i] = 1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        if (k) {
            --k;
            st[i] = 1;
        }
    }
    ll ans = 0;
    st[0] = st[n], st[n + 1] = st[1];
    for (int i = 1; i <= n; ++i) {
        if (a[i]) ans += 3;
        else ans += !st[i - 1] + !st[i] + !st[i + 1];
    }
    cout << ans;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 2
1 0 1 0 1

output:

13

result:

ok 1 number(s): "13"

Test #2:

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

input:

100000 33292
1 1 1 1 0 1 1 0 0 1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 0 0 0 0 0 1 1 1 1 0 1 1 1 0 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 1 0 1 1 1 1 0 1 1 0 1 1 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 0 1 0 0 1 0 1 0 1 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 0 0...

output:

279236

result:

ok 1 number(s): "279236"

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 3628kb

input:

100000 91906
1 1 1 1 1 0 1 0 0 0 1 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1 0 0 1 0 1 0 0 0 1 0 0 1 0 1 0 0 1 1 1 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 1 0 1 0 0 1 1 0 1 0 1 0 1 1 0 0 0 1 0 0 1 0 1 0 1 1 1 0 1 0 1 1 1 0 1 1 0 0 0 0 1 1 1 1 1 1 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 1 0 1 0 1 1 0 0 1 0...

output:

185874

result:

wrong answer 1st numbers differ - expected: '174297', found: '185874'