結果

問題 No.45 回転寿司
ユーザー 777yuuki12323
提出日時 2017-06-27 17:14:10
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 878 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 71,356 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-27 16:31:41
合計ジャッジ時間 1,685 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   42 |                 scanf("%d", v+i);
      |                 ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <bitset>
#include <vector>
#include <queue>


typedef long long ll;
#define fi first
#define se second
const ll mod = 1000000007;
//              123456789

using namespace std;

///////////////////////////////////////////////
//
//
///////////////////////////////////////////////

////////////////////////////////////////////////
////////////////////////////////////////////////

int N;
int v[1123];
int cost[1123][2];

int main(){
	
	int i;
	int j;
	
	cin>>N;
	
	fill( cost[0], cost[N], 0 );
	
	for( i = 0; i < N; i++ ){
		scanf("%d", v+i);
	}
	
	cost[0][0] = 0;
	cost[0][1] = v[0];
	
	for( i = 1; i < N; i++ ){
		cost[i][0] = max( cost[i-1][0], cost[i-1][1] );
		cost[i][1] = cost[i-1][0] + v[i];
	}
	
	cout<<max(cost[N-1][0], cost[N-1][1]);

	
	return 0;
}
0