結果

問題 No.1007 コイン集め
ユーザー i_am_nicolen_22i_am_nicolen_22
提出日時 2020-03-07 00:35:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,426 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 165,008 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 11:35:26
合計ジャッジ時間 3,104 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 RE -
testcase_09 WA -
testcase_10 AC 2 ms
6,940 KB
testcase_11 RE -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 18 ms
6,944 KB
testcase_16 AC 18 ms
6,940 KB
testcase_17 AC 18 ms
6,944 KB
testcase_18 AC 47 ms
6,940 KB
testcase_19 AC 49 ms
6,940 KB
testcase_20 AC 47 ms
6,944 KB
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n,k;
    cin>>n>>k;
    k--;
    vector<int>a(n);
    REP(i,n) cin>>a[i];
    int index1=0;
    for (size_t i = k-1; i>=0; i--)
    {
        if(a[i]==0){
            index1=i+1;
            break;
        }
        if(a[i]==1){
            index1=i;
            break;
        }
    }
    int index2=n-1;
    for (size_t i = k + 1; i < n; i++)
    {
        if (a[i] == 0)
        {
            index2 = i - 1;
            break;
        }
        if (a[i] == 1)
        {
            index2 = i;
            break;
        }
    }
    if(a[k]==0){
        cout<<0<<endl;
    }
    else{
    int cnt1=0,cnt2=0;
    if(k-1>=0){
    for (size_t i = k-1; i >=index1; i--)
    {
        cnt1+=a[i];
     //   cerr<<a[i]<<endl;
    }
    }
    if(k+1<n){
    for (int i = k+1; i <=index2 ; i++)
    {
        cnt2+=a[i];
    }
    }
    if(a[k]==1){
        cout<<a[k]+max(cnt1,cnt2)<<endl;
    }
    else{
        cout<<a[k]+cnt1+cnt2<<endl;
    }
   // cerr<<cnt1<<" "<<cnt2<<endl;
    }
    return 0;
}
0