結果
| 問題 | No.5 数字のブロック |
| コンテスト | |
| ユーザー |
hamray
|
| 提出日時 | 2017-11-01 23:37:27 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 579 bytes |
| 記録 | |
| コンパイル時間 | 643 ms |
| コンパイル使用メモリ | 70,360 KB |
| 実行使用メモリ | 7,852 KB |
| 最終ジャッジ日時 | 2025-12-13 21:51:08 |
| 合計ジャッジ時間 | 2,061 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:20:13: warning: ‘sum’ may be used uninitialized [-Wmaybe-uninitialized]
20 | sum = v[j] + sum;
| ~~~~^~~~~~~~~~~~
main.cpp:9:9: note: ‘sum’ was declared here
9 | int sum;
| ^~~
main.cpp:31:14: warning: ‘ans’ may be used uninitialized [-Wmaybe-uninitialized]
31 | cout << ans << endl;
| ^~~
main.cpp:10:9: note: ‘ans’ was declared here
10 | int ans;
| ^~~
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
int L, N;
cin >> L >> N;
int sum;
int ans;
vector<int> v;
for(int i = 0; i < N; i++){
int a;
cin >> a;
v.push_back(a);
}
sort(v.begin(), v.end());
for(int j = 0; j < N; j++){
sum = v[j] + sum;
if(sum == L){
ans = j + 1;
break;
}
if(sum > L){
ans = j;
break;
}
ans = N;
}
cout << ans << endl;
return 0;
}
hamray