結果
問題 | No.1268 Fruit Rush 2 |
ユーザー | polylogK |
提出日時 | 2020-10-23 23:12:49 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 1,175 bytes |
コンパイル時間 | 2,141 ms |
コンパイル使用メモリ | 201,352 KB |
最終ジャッジ日時 | 2025-01-15 13:58:32 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:19:35: warning: format ‘%lld’ expects argument of type ‘long long int*’, but argument 2 has type ‘long int*’ [-Wformat=] 19 | for(auto& v: a) scanf("%lld", &v); | ~~~^ ~~ | | | | | long int* | long long int* | %ld main.cpp:46:20: warning: format ‘%lld’ expects argument of type ‘long long int’, but argument 2 has type ‘i64’ {aka ‘long int’} [-Wformat=] 46 | printf("%lld\n", ans); | ~~~^ ~~~ | | | | | i64 {aka long int} | long long int | %ld main.cpp:18:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 18 | int n; scanf("%d", &n); std::vector<i64> a(n); | ~~~~~^~~~~~~~~~ main.cpp:19:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 19 | for(auto& v: a) scanf("%lld", &v); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std::literals::string_literals; using i64 = std::int_fast64_t; using std::cout; using std::cerr; using std::endl; using std::cin; template<typename T> std::vector<T> make_v(size_t a){return std::vector<T>(a);} template<typename T,typename... Ts> auto make_v(size_t a,Ts... ts){ return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); } int main() { int n; scanf("%d", &n); std::vector<i64> a(n); for(auto& v: a) scanf("%lld", &v); sort(begin(a), end(a)); std::vector<std::pair<i64, i64>> A, B; for(auto v: a) { if(v & 1) { if(A.empty() or A.back().second + 2 != v) A.push_back({v, v}); else A.back().second += 2; } else { if(B.empty() or B.back().second + 2 != v) B.push_back({v, v}); else B.back().second += 2; } } i64 ans = n; int x = 0, y = 0; for(int i = 0; i < n; i++) { if(i + 1 >= n or a[i] + 1 != a[i + 1]) continue; while(x < A.size() and A[x].second < a[i]) x++; while(y < B.size() and B[y].second < a[i]) y++; if(a[i] & 1) { ans += (B[y].second - a[i + 1]) / 2 + 1; } else { ans += (A[x].second - a[i + 1]) / 2 + 1; } } printf("%lld\n", ans); return 0; }