ABC423のC問題のコード修正お願いしたいです。
問題のリンク:https://atcoder.jp/contests/abc423/tasks/abc423_c
31/36がACで残りの4つのテストケースのWAが解決できません。
どなたかコード修正をお願いします。
以下のコードが私の書いたコードです。
#include
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define pb(x) push_back(x)
#define popb pop_back()
#define fi first
#define se second
#define yn(x) do { if(x) cout << "Yes\n"; else cout << "No\n"; } while(0)
#define nall(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define For(x) for(auto a : x)cout << a << " ";
using ll = long long; using ld = long double;
using Graph = vector>;
/変数たち/
/変数たち/
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
ll N,R,l,r; cin >> N >> R;
vector L(N);
rep(i,0,N) cin >> L[i];
if(count(nall(L),0) == 0) {
cout << 0;
return 0;
}
if(count(nall(L),1) == 0) {
cout << N;
return 0;
}
ll zero = 0, one = 0;
l = 0;
r = N-1;
rep(i,0,N) {
if(L[i] == 0) {
l = i;
break;
}
}
rrep(i,N-1,0) {
if(L[i] == 0) {
r = i;
break;
}
}
if(l == r) {
cout << 1;
return 0;
}
l = min(l,R);
r = max(r,R);
one = count(L.begin()+l,L.begin()+r+1,1);
zero = count(L.begin(),L.end(),0);
cout << one*2+zero << endl;
// cout << l << " " << r << endl;
// cout << one << " " << zero << endl;
return 0;
}