提出 #29682023
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
ll n, k;
cin >> n >> k;
vi a(n);
rep(i,0,n) cin >> a[i];
ll x = 0;
ll len = 0;
int nxt = x % n;
vi vis(n);
vi rho;
while (!vis[nxt]) {
vis[nxt] = sz(rho);
rho.pb(nxt);
x += a[nxt];
nxt = x % n;
}
int cstart = vis[nxt];
ll csum = 0;
int clen = 0;
rep(i,cstart,sz(rho)) {
csum += a[rho[i]];
++clen;
}
int early = sz(rho) - clen;
ll rm = min((ll)early, k);
k -= rm;
ll ans = 0;
rep(i,0,rm) ans += a[rho[i]];
ll cycs = k / clen;
k -= cycs * clen;
ans += csum * cycs;
rep(i,cstart,cstart+k) ans += a[rho[i]];
cout << ans << '\n';
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | E - Putting Candies |
| ユーザ | hoke_t |
| 言語 | C++ (GCC 9.2.1) |
| 得点 | 500 |
| コード長 | 1502 Byte |
| 結果 | AC |
| 実行時間 | 34 ms |
| メモリ | 5864 KiB |
コンパイルエラー
./Main.cpp: In function ‘int main()’:
./Main.cpp:39:6: warning: unused variable ‘len’ [-Wunused-variable]
39 | ll len = 0;
| ^~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 500 / 500 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | example_00.txt, example_01.txt |
| All | example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| example_00.txt | AC | 8 ms | 3468 KiB |
| example_01.txt | AC | 2 ms | 3560 KiB |
| hand_00.txt | AC | 3 ms | 3528 KiB |
| hand_01.txt | AC | 3 ms | 3572 KiB |
| hand_02.txt | AC | 25 ms | 5852 KiB |
| hand_03.txt | AC | 26 ms | 5764 KiB |
| hand_04.txt | AC | 2 ms | 3504 KiB |
| hand_05.txt | AC | 29 ms | 5864 KiB |
| hand_06.txt | AC | 30 ms | 5804 KiB |
| hand_07.txt | AC | 22 ms | 4696 KiB |
| random_00.txt | AC | 25 ms | 4696 KiB |
| random_01.txt | AC | 32 ms | 5808 KiB |
| random_02.txt | AC | 26 ms | 4752 KiB |
| random_03.txt | AC | 31 ms | 5808 KiB |
| random_04.txt | AC | 29 ms | 5372 KiB |
| random_05.txt | AC | 32 ms | 5808 KiB |
| random_06.txt | AC | 21 ms | 5024 KiB |
| random_07.txt | AC | 20 ms | 4740 KiB |
| random_08.txt | AC | 34 ms | 5848 KiB |
| random_09.txt | AC | 29 ms | 5420 KiB |
| random_10.txt | AC | 23 ms | 4792 KiB |
| random_11.txt | AC | 28 ms | 5736 KiB |
| random_12.txt | AC | 22 ms | 5212 KiB |
| random_13.txt | AC | 27 ms | 5788 KiB |
| random_14.txt | AC | 24 ms | 5372 KiB |
| random_15.txt | AC | 33 ms | 5808 KiB |
| random_16.txt | AC | 27 ms | 5224 KiB |
| random_17.txt | AC | 26 ms | 5088 KiB |
| random_18.txt | AC | 27 ms | 5220 KiB |