結果
| 問題 |
No.994 ばらばらコイン
|
| コンテスト | |
| ユーザー |
courange_cou
|
| 提出日時 | 2020-02-21 21:53:45 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 578 bytes |
| コンパイル時間 | 389 ms |
| コンパイル使用メモリ | 31,488 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-08 21:37:59 |
| 合計ジャッジ時間 | 4,706 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | RE * 23 |
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:5:59: warning: 'b' may be used uninitialized [-Wmaybe-uninitialized]
5 | int a[100000],b[100000];for(int i = 0;i < n-1;i++)scanf("%d %d",&a[i],b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
main.cpp:5:18: note: 'b' declared here
5 | int a[100000],b[100000];for(int i = 0;i < n-1;i++)scanf("%d %d",&a[i],b[i]);
| ^
main.cpp:27:10: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
27 | printf("%d",ans);
| ~~~~~~^~~~~~~~~~
main.cpp:10:8: note: 'ans' was declared here
10 | int ans;
| ^~~
ソースコード
#include <stdio.h>
int main(){
int n,coin;scanf("%d %d",&n,&coin);
int a[100000],b[100000];for(int i = 0;i < n-1;i++)scanf("%d %d",&a[i],b[i]);
if(coin > n){
printf("%d",-1);
return 0;
}
int ans;
int count[100000];
for(int i = 0;i < n;i++){
for(int j = i;j < n;j++){
if(a[j] == i+1)count[i]++;
}
}
coin--;
for(int i = 0;i < n;i++){
if(coin <= 0)break;
if(coin > count[i]){
ans += coin-count[i];
coin -= count[i];
}else {
ans += coin;
}
}
printf("%d",ans);
}
courange_cou