提出 #16755795
ソースコード 拡げる
#include <bits/stdc++.h>
#define INF 1e9
#define INFLL 1ull<<60u
using namespace std;
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a) (a).begin(),(a).end()
#define endl "\n"
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
typedef long long ll;
void solve() {
int N,K; cin >> N >> K;
vector<int> v(N);
REP(i,N) cin >> v[i];
REP(i,N) {
if (v[i] != 1) continue;
// cerr << i << endl;
auto left = i;
auto right = N - i - 1;
auto left_cost = (i+K-1-1)/(K-1);
if (left_cost && (left_cost * (K-1)) > left) right -= (left_cost * (K-1)) - left;
chmax(right,0);
auto right_cost = (right+K-2)/(K-1);
cout << left_cost+right_cost << endl;
}
assert("bugged");
}
int main() {
solve();
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | C - Minimization |
| ユーザ | reud |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 300 |
| コード長 | 1102 Byte |
| 結果 | AC |
| 実行時間 | 33 ms |
| メモリ | 3748 KiB |
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 300 / 300 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| 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 | 15 ms | 3376 KiB |
| 10.txt | AC | 28 ms | 3460 KiB |
| 2.txt | AC | 33 ms | 3748 KiB |
| 3.txt | AC | 18 ms | 3512 KiB |
| 4.txt | AC | 25 ms | 3516 KiB |
| 5.txt | AC | 30 ms | 3464 KiB |
| 6.txt | AC | 28 ms | 3568 KiB |
| 7.txt | AC | 6 ms | 3440 KiB |
| 8.txt | AC | 29 ms | 3512 KiB |
| 9.txt | AC | 2 ms | 3520 KiB |
| sample1.txt | AC | 2 ms | 3576 KiB |
| sample2.txt | AC | 2 ms | 3436 KiB |
| sample3.txt | AC | 2 ms | 3508 KiB |