結果
問題 |
No.115 遠足のおやつ
|
ユーザー |
![]() |
提出日時 | 2018-11-15 21:20:51 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 1 ms / 5,000 ms |
コード長 | 415 bytes |
コンパイル時間 | 424 ms |
コンパイル使用メモリ | 25,856 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2025-01-03 01:30:59 |
合計ジャッジ時間 | 1,538 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:5:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 5 | scanf("%d%d%d",&n,&d,&k); | ^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> int main() { int n,d,k,min,max,i; scanf("%d%d%d",&n,&d,&k); int c[k]; min=k*(k+1)/2; // 1~kの和 max=k*(2*n-k+1)/2;// n-k+1~nの和 if (max<d||min>d) { puts("-1"); return 0; } else { for (i=0;i<k;i++) c[i]=i+1; for (i=k-1;i>=0;i--) { while (min<d&&c[i]<n) c[i]++,min++; if (min==d) break; n--; } } for (i=0;i<k;i++) printf("%d ",c[i]); return 0; }