QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#213057 | #4803. Candies | ucup-team1209# | WA | 0ms | 3644kb | C++20 | 1.2kb | 2023-10-14 10:36:58 | 2023-10-14 10:36:59 |
Judging History
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;
++ cnt;
// cout << x <<' ' << suf[x] << endl;
if(cnt == n / 2) break;
int y = suf[x];
if(a[x] == a[y] || a[x] + a[y] == X) {
del(x), del(y);
}
x = pre[x];
if(a[x] == a[suf[x]] || a[x] + a[suf[x]] == X) q.push(x);
}
cout << cnt << '\n';
return 0;
}
詳細信息
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: 3616kb
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: 3612kb
input:
1 963837006 731841442
output:
1
result:
wrong answer 1st numbers differ - expected: '0', found: '1'