結果
問題 | No.45 回転寿司 |
ユーザー |
|
提出日時 | 2019-07-12 07:26:02 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 5,000 ms |
コード長 | 966 bytes |
コンパイル時間 | 2,343 ms |
コンパイル使用メモリ | 161,700 KB |
実行使用メモリ | 6,824 KB |
最終ジャッジ日時 | 2024-11-16 05:40:00 |
合計ジャッジ時間 | 2,549 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(void){ int n; cin >> n; vector<int> data(n); for(int i=0; i<n; i++) cin >> data[i]; vector<int> result(n, 0); result[0] = data[0]; result[1] = data[1]; if(n==1) { cout << data[0] << endl; } else if(n==2) { if(data[0]>data[1]) cout << data[0] << endl; else cout << data[1] << endl; } else { for(int i=2; i<n; i++) { int temp_max = 0; for(int j=0; j<i-1; j++) { if(result[j]>temp_max) temp_max = result[j]; } if(temp_max+data[i]>result[i-1]) { result[i] = temp_max+data[i]; } else { result[i] = result[i-1]; } } // for(int i=0; i<n; i++) { // cout << result[i] << endl; // } cout << result[n-1] << endl; } return 0; }