QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#439315 | #4803. Candies | Ahmed57 | WA | 55ms | 13136kb | C++23 | 2.1kb | 2024-06-11 19:26:59 | 2024-06-11 19:26:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
int n,x;
cin>>n>>x;
int ans = 0;
set<pair<int,int>> s;
int arr[n];
for(int i = 0;i<n;i++){
int x;cin>>x;
arr[i] = x;
s.insert({i,x});
}
set<int> st;
for(int i = 0;i<n;i++){
if(arr[i]==arr[(i+1)%n]){
st.insert(i);
}
}
while(st.size()&&s.size()>1){
auto it = s.lower_bound(make_pair(*st.begin(),0));
s.erase(it);
it = s.lower_bound(make_pair(*st.begin(),0));
if(it==s.end())it=s.begin();
s.erase(it);
if(s.size()<=1){
st.erase(st.begin());
continue;
}
it = s.lower_bound(make_pair(*st.begin(),0));
if(it==s.begin()){
it = --s.end();
}else it--;
st.erase(st.begin());
if(st.find((*it).first)!=st.end())st.erase((*it).first);
auto it2 = it;it2++;
if(it2==s.end())it2 = s.begin();
if((*it).second==(*it2).second){
st.insert((*it).first);
}
ans++;
}
st.clear();
for(auto it =s.begin();it!=s.end();it++){
auto it2 = it;
it2++;
if(it2==s.end())it2 = s.begin();
if((*it).second+(*it2).second==x){
st.insert((*it).first);
}
}
while(st.size()&&s.size()>1){
auto it = s.lower_bound(make_pair(*st.begin(),0));
s.erase(it);
it = s.lower_bound(make_pair(*st.begin(),0));
if(it==s.end())it=s.begin();
s.erase(it);
if(s.size()<=1){
st.erase(st.begin());
continue;
}
it = s.lower_bound(make_pair(*st.begin(),0));
if(it==s.begin()){
it = --s.end();
}else it--;
if(st.find((*it).first)!=st.end())st.erase((*it).first);
st.erase(st.begin());
auto it2 = it;it2++;
if(it2==s.end())it2 = s.begin();
if((*it).second+(*it2).second==x){
st.insert((*it).first);
}
ans++;
}
cout<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
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: 3536kb
input:
10 5 1 2 5 2 1 2 3 4 8 4
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3464kb
input:
1 963837006 731841442
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3588kb
input:
2 948507270 461613425 139535653
output:
0
result:
ok 1 number(s): "0"
Test #5:
score: 0
Accepted
time: 49ms
memory: 10792kb
input:
100000 253614967 278270961 980235896 498158919 928430171 216003120 852570559 948400591 239257297 897053668 294741177 38297442 382677591 406314558 609468974 854148233 314532768 738191552 158215003 5865826 920471827 380037059 356271729 749175328 28319050 208101106 953758996 896570759 521930645 2413736...
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 55ms
memory: 13136kb
input:
100000 2 1 2 2 2 2 1 1 2 1 1 1 1 1 1 1 1 1 1 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 2 1 2 1 1 1 2 2 1 1 1 1 1 2 1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 1 2 1 1 2 2 2 2 1 2 2 2 1 1 2 1 2 1 2 2 2 1 1 1 2 1 1 1 1 1 1 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 2 2 2 1 1 2 1 1 2 2 2 2 2 2 2 1 2 1 1 2 2 1 1 2 1 1 1 1...
output:
49999
result:
ok 1 number(s): "49999"
Test #7:
score: -100
Wrong Answer
time: 55ms
memory: 12936kb
input:
99824 2 1 1 2 1 1 1 2 1 2 2 2 2 1 1 1 1 2 1 1 2 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 2 1 2 2 1 1 2 2 1 2 1 1 1 2 2 1 2 1 1 2 1 2 1 2 2 2 1 1 2 1 2 2 2 2 2 1 2 1 1 2 1 1 2 1 2 2 1 2 1 2 2 1 2 2 1 2 2 2 1 1 2 1 2 1 1 1 2 1 1 2 2 1 1 2 2 1 1 1 2 2 1 2 1 1 2 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 2 1 1 2 1 2 1 1 1 ...
output:
49911
result:
wrong answer 1st numbers differ - expected: '49904', found: '49911'