QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213067#4803. Candiesucup-team1209#WA 0ms3676kbC++201.2kb2023-10-14 10:53:572023-10-14 10:53:57

Judging History

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

  • [2023-10-14 10:53:57]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3676kb
  • [2023-10-14 10:53:57]
  • 提交

answer

#include <bits/stdc++.h>
#define cs const
#define pb push_back
using namespace std;

cs int N = 1e5 + 5; 
int n, X, a[N], pre[N], suf[N];
queue <int> q; 
bool era[N];
void del(int x) {
    era[x] = 1; 
    pre[suf[x]] = pre[x];
    suf[pre[x]] = suf[x];
}
int main() {
    #ifdef zqj 
    freopen("1.in","r",stdin);
    #endif
    ios::sync_with_stdio(false),cin.tie(0);
    cin >> n >> X;
    vector <int> s; 
    
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    } a[n] = a[0];
    for(int i = 0; i < n; i++) {
        pre[i] = i - 1, suf[i] = i + 1; 
    }
    pre[0] = n - 1; 
    suf[n - 1] = 0;
    for(int i = 0; i < n; i++) {
        if(a[i] + a[i + 1] == X || a[i] == a[i + 1]) {
            q.push(i);
        }
    }
    int cnt = 0; 
    while(!q.empty()) {
        int x = q.front(); q.pop();
        if(era[x]) continue;
        int y = suf[x];
        if(a[x] == a[y] || a[x] + a[y] == X) {
            del(x), del(y), ++ cnt; 
            if(cnt == n / 2) break;
            x = pre[x];
            if(a[x] == a[suf[x]] || a[x] + a[suf[x]] == X) q.push(x);
        }
    } 
    cout << cnt << '\n';
    return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 5
1 1 4 5 1 4

output:

2

result:

ok 1 number(s): "2"

Test #2:

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

input:

10 5
1 2 5 2 1 2 3 4 8 4

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

1 963837006
731841442

output:

1

result:

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