結果

問題 No.1006 Share an Integer
ユーザー mdstoymdstoy
提出日時 2020-03-06 22:56:54
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,247 bytes
コンパイル時間 2,751 ms
コンパイル使用メモリ 166,072 KB
実行使用メモリ 18,964 KB
最終ジャッジ日時 2024-04-22 10:08:02
合計ジャッジ時間 2,862 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vl a(n + 2, 0);
    REP1(i, n) cin >> a[i];

    if (a[k] == 0) {
        cout << 0 << endl;
    } else if (a[k] == 1) {
        ll l = 0;
        for (int i = k - 1; i >= 0; i--) {
            if (a[i] == 0) break;
            if (a[i] == 1) {l += a[i]; break;}
            l += a[i];
        }
        ll r = 0;
        FOR(i, k + 1, n + 1) {
            if (a[i] == 0) break;
            if (a[i] == 1) {r += a[i]; break;}
            r += a[i];
        }
        cout << max(l, r) << endl;
    } else {
        ll l = 0;
        for (int i = k - 1; i >= 0; i--) {
            if (a[i] == 0) break;
            if (a[i] == 1) {l += a[i]; break;}
            l += a[i];
        }
        ll r = 0;
        FOR(i, k + 1, n + 1) {
            if (a[i] == 0) break;
            if (a[i] == 1) {r += a[i]; break;}
            r += a[i];
        }
        cout << a[k] + l + r << endl;

    }
}
0