結果
問題 | No.489 株に挑戦 |
ユーザー | ふっぴー |
提出日時 | 2017-12-16 14:31:17 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 93 ms / 1,000 ms |
コード長 | 2,662 bytes |
コンパイル時間 | 1,929 ms |
コンパイル使用メモリ | 176,944 KB |
実行使用メモリ | 87,380 KB |
最終ジャッジ日時 | 2024-07-20 00:02:46 |
合計ジャッジ時間 | 4,884 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
87,372 KB |
testcase_01 | AC | 55 ms
86,348 KB |
testcase_02 | AC | 23 ms
85,076 KB |
testcase_03 | AC | 24 ms
85,180 KB |
testcase_04 | AC | 24 ms
85,276 KB |
testcase_05 | AC | 24 ms
85,148 KB |
testcase_06 | AC | 24 ms
85,276 KB |
testcase_07 | AC | 24 ms
85,096 KB |
testcase_08 | AC | 24 ms
85,220 KB |
testcase_09 | AC | 24 ms
85,100 KB |
testcase_10 | AC | 23 ms
85,204 KB |
testcase_11 | AC | 24 ms
85,140 KB |
testcase_12 | AC | 24 ms
85,136 KB |
testcase_13 | AC | 23 ms
85,116 KB |
testcase_14 | AC | 23 ms
85,220 KB |
testcase_15 | AC | 26 ms
85,296 KB |
testcase_16 | AC | 79 ms
87,376 KB |
testcase_17 | AC | 30 ms
85,460 KB |
testcase_18 | AC | 55 ms
86,352 KB |
testcase_19 | AC | 47 ms
86,352 KB |
testcase_20 | AC | 81 ms
87,380 KB |
testcase_21 | AC | 38 ms
85,756 KB |
testcase_22 | AC | 28 ms
85,332 KB |
testcase_23 | AC | 59 ms
86,480 KB |
testcase_24 | AC | 93 ms
87,376 KB |
testcase_25 | AC | 24 ms
85,156 KB |
testcase_26 | AC | 73 ms
87,376 KB |
testcase_27 | AC | 89 ms
87,372 KB |
testcase_28 | AC | 24 ms
85,284 KB |
testcase_29 | AC | 23 ms
85,080 KB |
testcase_30 | AC | 82 ms
87,372 KB |
testcase_31 | AC | 71 ms
87,376 KB |
testcase_32 | AC | 61 ms
86,352 KB |
testcase_33 | AC | 89 ms
87,376 KB |
testcase_34 | AC | 84 ms
87,376 KB |
testcase_35 | AC | 47 ms
86,352 KB |
testcase_36 | AC | 31 ms
85,504 KB |
testcase_37 | AC | 56 ms
86,356 KB |
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/istream:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/sstream:38, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/complex:45, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ccomplex:39, from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/x86_64-pc-linux-gnu/bits/stdc++.h:54, from main.cpp:1: In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]', inlined from 'int main()' at main.cpp:123:26: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'selld' may be used uninitialized [-Wmaybe-uninitialized] 202 | { return _M_insert(__n); } | ~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:111:18: note: 'selld' was declared here 111 | ll buyd, selld; | ^~~~~ In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(long long int) [with _CharT = char; _Traits = std::char_traits<char>]', inlined from 'int main()' at main.cpp:123:11: /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/ostream:202:25: warning: 'buyd' may be used uninitialized [-Wmaybe-uninitialized] 202 | { return _M_insert(__n); } | ~~~~~~~~~^~~~~ main.cpp: In function 'int main()': main.cpp:111:12: note: 'buyd' was declared here 111 | ll buyd, selld; | ^~~~
ソースコード
#include "bits/stdc++.h" using namespace std; #define DEBUG(x) cout<<#x<<": "<<x<<endl; #define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl typedef long long ll; #define vi vector<int> #define vl vector<ll> #define vii vector< vector<int> > #define vll vector< vector<ll> > #define vs vector<string> #define pii pair<int,int> #define pis pair<int,string> #define psi pair<string,int> #define pll pair<ll,ll> const int inf = 1000000001; const ll INF = 1e18 * 2; #define MOD 1000000007 #define mod 1000000009 #define pi 3.14159265358979323846 #define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl; int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 }; //rmq に使用 const ll MAX_N = 1 << 21; int n; vector<pll> dat(2 * MAX_N - 1); vl a(MAX_N); //rmqに使用 void init(int k, int l, int r) { if (r - l == 1) { dat[k].first = a[l]; dat[k].second = l; } else { int lch = 2 * k + 1, rch = 2 * k + 2; init(lch, l, (l + r) / 2); init(rch, (l + r) / 2, r); if (dat[lch].first >= dat[rch].first) { dat[k] = dat[lch]; } else { dat[k] = dat[rch]; } } } //k番目の値をaに変更 //rmqに使用 void update(int k, int a, int v, int l, int r) { if (r - l == 1) { dat[v].first = a; } else { if (k < (l + r) / 2) update(k, a, 2 * v + 1, l, (l + r) / 2); else { update(k, a, 2 * v + 2, (l + r) / 2, r); } if (dat[2*v+1].first >= dat[2*v+2].first) { dat[k] = dat[2*v+1]; } else { dat[k] = dat[2*v+2]; } } } //rmqに使用 //[a,b)の最小値を求める //後ろのほうの引数は計算の簡単のための引数 //kは接点の番号,l,rはその接点が[l,r)に対応していることを表す //従って、外からはquery(a,b,0,0,n)としてよぶ pll query(int a, int b, int k, int l, int r) { if (r <= a || b <= l) { return pll(-1, inf); } if (a <= l && r <= b) { return dat[k]; } else { pll ul = query(a, b, k * 2 + 1, l, (l + r) / 2); pll ur = query(a, b, k * 2 + 2, (l + r) / 2, r); if (ul.first >= ur.first) { return ul; } else { return ur; } } } int main() { int d, k, i, j; cin >> n >> d >> k; vector<pll> vp; for (i = 0; i < n; i++) { cin >> a[i]; vp.push_back(pll(a[i], i)); } sort(vp.begin(), vp.end()); init(0, 0, n); ll ans = -INF; ll buyd, selld; for (i = 0; i < n; i++) { ll buy = a[i]; pll sell = query(i, min(i + d + 1, n), 0, 0, n); if (ans < (sell.first - buy) * k) { buyd = i; selld = sell.second; ans = (sell.first - buy)*k; } } cout << ans << endl; if (ans) { cout << buyd << " " << selld << endl; } }