結果
| 問題 |
No.78 クジ付きアイスバー
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2014-12-09 22:18:18 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 5,000 ms |
| コード長 | 1,210 bytes |
| コンパイル時間 | 205 ms |
| コンパイル使用メモリ | 35,812 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-08 00:26:38 |
| 合計ジャッジ時間 | 1,147 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:55:14: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘ll’ {aka ‘long long int’} [-Wformat=]
55 | printf("%d\n", res);
| ~^ ~~~
| | |
| int ll {aka long long int}
| %lld
main.cpp:8:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d %d", &N, &K);
| ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:11:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%s", ice);
| ~~~~~^~~~~~~~~~~
ソースコード
#include <cstdio>
#include <algorithm>
typedef long long ll;
int main(){
int N, K;
scanf("%d %d", &N, &K);
char ice[100];
scanf("%s", ice);
for(int i=N;i<2*N;i++){ice[i] = ice[i-N];}
bool bought[100];
std::fill(bought, bought+2*N, false);
int cost[100], last = 0;
std::fill(cost, cost+2*N, 0);
for(int i=0;i<2*N;i++){
if(!bought[i]){
cost[i] = 1;
}
if(ice[i] == '1'){
if(last+1 < 2*N){bought[last+1] = true; last += 1;}
}else if(ice[i] == '2'){
if(last+1 < 2*N){bought[last+1] = true; last += 1;}
if(last+1 < 2*N){bought[last+1] = true; last += 1;}
}
last = std::max(i+1, last);
}
for(int i=1;i<N;i++){
cost[i] += cost[i-1];
cost[i+N] += cost[i-1+N];
}
// for(int i=0;i<2*N;i++){
// printf("%d: %d\n", i, cost[i]);
// }
ll res;
if(K <= N){
res = cost[K-1];
}else{
res = cost[N-1];
K -= N;
res += 1ll * cost[2*N-1] * (K/N);
K %= N;
res += K>0?cost[K-1+N]:0;
}
printf("%d\n", res);
}
tottoripaper