提出 #2719372


ソースコード 拡げる

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

template<typename T, typename S>
istream& operator>> (istream& in, pair<S, T>& p) {
    in >> p.fs >> p.sn;
    return in;
}
template<typename T, typename S>
ostream& operator<< (ostream& out, pair<S, T>& p) {
    out << p.fs << ' ' << p.sn << ' ';
    return out;
}

template<typename T>
istream& operator>> (istream& in, vector<T>& v) {
    for (T& x : v) in >> x;
    return in;
}
template<typename T>
ostream& operator<< (ostream& out, vector<T>& v) {
    for (T& x : v) out << x << ' ';
    return out;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    cin >> a;
    int l = 0;
    while (a[l] != 1) ++l;
    int r = n - 1 - l;
    int ans = INF;
    forn(l1, 0, k) {
        int r1 = k - 1 - l1;
        if (l1 <= l && r1 <= r) {
            setmin(ans, 1 + (l - l1 + k - 2) / (k - 1) + (r - r1 + k - 2) / (k - 1));
        }
    }
    cout << ans << '\n';
}

提出情報

提出日時
問題 C - Minimization
ユーザ khadaev
言語 C++14 (GCC 5.4.1)
得点 300
コード長 2050 Byte
結果 AC
実行時間 10 ms
メモリ 640 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 300 / 300
結果
AC × 3
AC × 16
セット名 テストケース
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, 1.txt, 10.txt, 2.txt, 3.txt, 4.txt, 5.txt, 6.txt, 7.txt, 8.txt, 9.txt, sample1.txt, sample2.txt, sample3.txt
ケース名 結果 実行時間 メモリ
1.txt AC 5 ms 384 KiB
10.txt AC 8 ms 512 KiB
2.txt AC 10 ms 640 KiB
3.txt AC 6 ms 512 KiB
4.txt AC 9 ms 640 KiB
5.txt AC 10 ms 640 KiB
6.txt AC 10 ms 640 KiB
7.txt AC 2 ms 256 KiB
8.txt AC 9 ms 640 KiB
9.txt AC 1 ms 256 KiB
sample1.txt AC 1 ms 256 KiB
sample2.txt AC 1 ms 256 KiB
sample3.txt AC 1 ms 256 KiB