結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-12 06:26:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 5,000 ms |
| コード長 | 425 bytes |
| コンパイル時間 | 557 ms |
| コンパイル使用メモリ | 64,256 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-27 04:49:39 |
| 合計ジャッジ時間 | 1,700 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
コンパイルメッセージ
main.cpp:18:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
18 | main()
| ^~~~
ソースコード
#include<iostream>
using namespace std;
int N;
long K;
string s;
int sum[55];
int rest(int k,int y)
{
int ret=0;
for(int i=0;i<k;i++)
{
if(y>0)y--;
else ret++;
y+=s[i]-'0';
}
return ret;
}
main()
{
cin>>N>>K>>s;
int x=0,y=0;
for(int i=0;i<N;i++)
{
if(y>0)y--;
else x++;
y+=s[i]-'0';
}
if(K<N)cout<<rest(K,0)<<endl;
else
{
if(x<=y)cout<<x<<endl;
else cout<<x+(x-y)*(K/N-1)+rest(K%N,y)<<endl;
}
}