結果
問題 |
No.112 ややこしい鶴亀算
|
ユーザー |
![]() |
提出日時 | 2015-09-05 21:25:09 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 686 bytes |
コンパイル時間 | 374 ms |
コンパイル使用メモリ | 44,160 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 04:13:01 |
合計ジャッジ時間 | 1,078 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 23 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d", &n); | ~~~~~^~~~~~~~~~ main.cpp:12:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 12 | scanf("%d", &animals[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~
ソースコード
#include <cstdio> #include <vector> #include <algorithm> using namespace std; int main(){ int n, a, b; scanf("%d", &n); vector<int> animals(n); for(int i = 0; i < n; i++){ scanf("%d", &animals[i]); } sort(animals.begin(), animals.end()); if(animals[0] == animals[n - 1]){ a = (animals[0] / (n - 1) == 2) * n; b = (animals[0] / (n - 1) == 4) * n; } else{ n--; a = upper_bound(animals.begin(), animals.end(), animals[n]) - lower_bound(animals.begin(), animals.end(), animals[n]); b = upper_bound(animals.begin(), animals.end(), animals[0]) - lower_bound(animals.begin(), animals.end(), animals[0]); } printf("%d %d\n", a, b); return 0; }