結果
問題 | No.78 クジ付きアイスバー |
ユーザー |
![]() |
提出日時 | 2022-01-13 01:29:34 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 476 bytes |
コンパイル時間 | 2,067 ms |
コンパイル使用メモリ | 191,808 KB |
最終ジャッジ日時 | 2025-01-27 10:43:14 |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d%d%s",&n,&k,box); | ~~~~~^~~~~~~~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; int n,k,stock,cost; char box[60]; void f(int rest){ for(int i=0;i<rest;i++){ if(stock>0)stock--;else cost++; stock+=box[i]-'0'; } } int main(){ scanf("%d%d%s",&n,&k,box); f(min(n,k)); if(k<n) printf("%d",cost); else if(cost<=stock) printf("%d",cost); else{ cost+=(cost-stock)*(k/n-1); f(k%n); printf("%d",cost); } return 0; }