結果
問題 | No.45 回転寿司 |
ユーザー | gurualo |
提出日時 | 2019-04-07 17:31:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 6,076 bytes |
コンパイル時間 | 1,672 ms |
コンパイル使用メモリ | 203,152 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-08 12:46:12 |
合計ジャッジ時間 | 2,689 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,816 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,944 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,944 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,944 KB |
testcase_09 | AC | 2 ms
6,944 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 2 ms
6,944 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 2 ms
6,944 KB |
testcase_25 | AC | 2 ms
6,940 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,944 KB |
testcase_30 | AC | 2 ms
6,940 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | AC | 2 ms
6,940 KB |
testcase_33 | AC | 2 ms
6,944 KB |
ソースコード
#include <vector> #include <list> #include <map> #include <set>//2分探索木 #include <deque> #include <stack> #include <bitset> #include <algorithm> #include <functional> #include <numeric> #include <utility> #include <sstream> #include <iostream> #include <iomanip> #include <cstdio> #include <cmath> #include <cstdlib> #include <cctype> #include <string> #include <cstring> #include <ctime> #include <queue>// キュー 優先度付きキュー #include <stack> #include <complex> #include <assert.h> #ifdef LOCAL #include "UnionFind.h"//同じグループに属するか #include "Prime.h"//素数判定 #include "RMQ.h"//区間最小値 #include "BIT.h"//累積和 #endif using namespace std; //conversion //------------------------------------------ inline long long toInt(string s) { long long v; istringstream sin(s); sin >> v; return v; } template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } //math //------------------------------------------- template<class T> inline T sqr(T x) { return x * x; } //typedef //------------------------------------------ typedef vector<int> VI; typedef vector<VI> VVI; typedef vector<string> VS; typedef pair<int, int> PII; typedef long long LL; typedef vector<LL> VLL; typedef vector<PII> VPII; //container util //------------------------------------------ #define ALL(a) (a).begin(),(a).end() #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define MP make_pair #define SZ(a) int((a).size()) #define EACH(t,c) for(typeof((c).begin()) t=(c).begin(); t!=(c).end(); ++t) #define EXIST(s,e) ((s).find(e)!=(s).end()) #define SORT(c) sort((c).begin(),(c).end()) //repetition //------------------------------------------ #define FOR(t,a,b) for(int t=(a);t<(b);++t) #define REP(t,n) FOR(t,0,n) //constant //------------------------------------------ const double EPS = 1e-10; const double PI = acos(-1.0); //clear memory //------------------------------------------ #define CLR(a) memset((a), 0 ,sizeof(a)) //debug //------------------------------------------ #if defined(__GNUC__) #include <assert.h> #define ASSERT_(x) assert(x) #else #include <assert.h> #define ASSERT_(x) assert(x) #endif #ifdef _DEBUG #define dump(x) cerr << #x << '=' << (x) << endl; #define debug(x) cerr << #x << '=' << (x) << '('<<'L' << __LINE__ << ')' << ' ' << __FILE__ << endl; #define ASSERT(x) {if (!(x)){std::cerr << "\nError!!\n" << "info string file:" << __FILE__ << " line:" << __LINE__ <<" "<< #x<< std::endl;ASSERT_(x);}} #else #define ASSERT(x) ((void)0) #define debug(x) ((void)0) #define dump(x) ((void)0) #endif // _DEBUG template<class T> void showVector(vector<T>& v) { for (int i = 0; i < v.size(); ++i) cerr << v[i] << " "; cerr << endl; } //mod //------------------------------------------- const LL mod = 1000000007; LL mod_pow(LL x, LL n, LL mod) { if (n == 0) { return 1; } LL res = mod_pow(x * x % mod, n / 2, mod); if (n & 1) { res = res * x % mod; } return res; } //bitop //------------------------------------------- #if defined(__GNUC__) #include <immintrin.h> int popcount(int a) { return __builtin_popcount(a); } #elif defined(_MSC_VER) #include <intrin.h> int popcount(int a) { return __popcnt(a); } #endif //gcd lcm //------------------------------------------- LL gcd(LL a, LL b) { if (a%b == 0) { return b; } else return gcd(b, a%b); } LL lcm(LL a, LL b) { return a / gcd(a, b)*b; } //YES_NO //------------------------------------------ #define Yes_ cout<<"Yes"<<endl; return 0; #define No_ cout<<"No"<<endl; return 0; #define YES_ cout<<"YES"<<endl; return 0; #define NO_ cout<<"NO"<<endl; return 0; #define POSSIBLE cout<<"POSSIBLE"<<endl; return 0; #define IMPOSSIBLE cout<<"IMPOSSIBLE"<<endl; return 0; //matrix //------------------------------------------ template <class T> class matrix : public vector< vector<T> > { private: int tate_, yoko_; public: matrix(const int tate__, const int yoko__) { ASSERT(tate__ > 0); ASSERT(yoko__ > 0); this->resize(tate__); for (size_t i = 0; i < this->size(); i++) { (*this)[i].resize(yoko__); } tate_ = tate__; yoko_ = yoko__; } matrix() {}; int tate()const { return tate_; } int yoko()const { return yoko_; } void resizematrix(const int tate__, const int yoko__) { ASSERT(tate__ > 0); ASSERT(yoko__ > 0); this->resize(tate__); for (size_t i = 0; i < this->size(); i++) { (*this)[i].resize(yoko__); } tate_ = tate__; yoko_ = yoko__; } void setone() {for (int i = 0; i < tate(); i++) for (int j = 0; j < yoko(); j++) { (*this)[i][j] = 1; }} void setzero() {for (int i = 0; i < tate(); i++) for (int j = 0; j < yoko(); j++) { (*this)[i][j] = 0; }} void setAll(T a) {for (int i = 0; i < tate(); i++) for (int j = 0; j < yoko(); j++) { (*this)[i][j] = a; }} }; template<class T> std::ostream& operator<<(std::ostream& os, const matrix<T>& m) { for (int j = 0; j < m.tate(); j++) { for (int i = 0; i < m.yoko(); i++) { os << (int)m[j][i]; } os << endl; } return os; } //time //------------------------------------------ #if defined(__GNUC__) #include <sys/time.h> #include <immintrin.h> #include <string.h> LL starttime; inline LL now() { struct timeval tv; gettimeofday(&tv, NULL); LL t = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL; return t; } inline LL elapsed() { return now() - starttime; } #else #include <chrono> #include <intrin.h> typedef std::chrono::milliseconds::rep TimePoint; inline TimePoint now() { return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now().time_since_epoch()).count(); } TimePoint starttime; inline TimePoint elapsed() { return now() - starttime; } #endif //===================================================== //i番目の皿までしかない場合の最大値 //DP[i]=max(DP[i-1],DP[i-2]+W[i]) int DP[1234]; int main() { int N; cin >> N; VI W(N); REP(i, N) { cin >> W[i]; } DP[0] = W[0]; if (N == 1) { cout << DP[0] << endl; exit(0); } DP[1] = max(W[0], W[1]); FOR(i, 2, N) { DP[i] = max(DP[i - 1], DP[i - 2] + W[i]); } cout << DP[N-1] << endl; }