結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2017-07-04 18:39:45 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,015 bytes |
コンパイル時間 | 836 ms |
コンパイル使用メモリ | 66,724 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-27 16:32:41 |
合計ジャッジ時間 | 1,662 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:46:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 46 | scanf("%d", &v[i]); | ~~~~~^~~~~~~~~~~~~
ソースコード
#include <iostream> #include <cstdio> #include <algorithm> #include <cstdlib> #include <cstring> #include <cmath> #include <vector> #include <queue> using namespace std; #define FOR(i,a,b) for (ll i = (a); i < (b); i++) #define REP(i,n) FOR(i,0,n) long gcd(long a, long b){ if (a%b==0){ return b; } else{ return gcd(b,a%b); } } long lcm(long a, long b){ return (a*b) / gcd(a,b); } template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; } template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; } typedef long long ll; const ll INF = 1ll<<29; const ll MOD = 1000000007; const double EPS = 1e-10; int d[1000]; int v[1000]; int main(){ int n; cin >> n; REP(i,n){ scanf("%d", &v[i]); } d[0] = v[0]; d[1] = v[1]; d[2] = v[0] + v[2]; FOR(i,3,n){ d[i] = max(d[i-2], d[i-3]) + v[i]; } if (n > 1) cout << max(d[n-1], d[n-2]) << endl; else cout << d[n-1] << endl; return 0; }