結果
| 問題 |
No.489 株に挑戦
|
| コンテスト | |
| ユーザー |
TangentDay
|
| 提出日時 | 2017-02-24 22:43:19 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,702 bytes |
| コンパイル時間 | 744 ms |
| コンパイル使用メモリ | 86,828 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2025-01-02 23:15:22 |
| 合計ジャッジ時間 | 3,180 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 31 RE * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:64:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
64 | scanf("%d", &x[i]);
| ~~~~~^~~~~~~~~~~~~
In file included from /usr/include/stdio.h:980,
from /usr/include/c++/13/cstdio:42,
from /usr/include/c++/13/ext/string_conversions.h:45,
from /usr/include/c++/13/bits/basic_string.h:4109,
from /usr/include/c++/13/string:54,
from /usr/include/c++/13/bits/locale_classes.h:40,
from /usr/include/c++/13/bits/ios_base.h:41,
from /usr/include/c++/13/ios:44,
from /usr/include/c++/13/ostream:40,
from /usr/include/c++/13/iostream:41,
from main.cpp:1:
In function ‘int printf(const char*, ...)’,
inlined from ‘int main()’ at main.cpp:90:11:
/usr/include/x86_64-linux-gnu/bits/stdio2.h:86:23: warning: ‘j’ may be used uninitialized [-Wmaybe-uninitialized]
86 | return __printf_chk (__USE_FORTIFY_LEVEL - 1, __fmt, __va_arg_pack ());
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp: In function ‘int main()’:
main.cpp:68:9: note: ‘j’ was declared here
68 | int j, k;
| ^
ソースコード
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1e9
const int MAX_N = 200010;
int n, width;
int dat[MAX_N*4];
void init(){
width = 1;
while(width<n) width*=2;
REP(i,2*width-1) dat[i] = INF;
}
void update(int i, int x){
i += width-1;
dat[i] = x;
while (i>0){
i = (i-1)/2;
dat[i] = min(dat[i*2+1],dat[i*2+2]);
}
}
int query(int a, int b, int k, int l, int r){
if (r<=a || b<=l) return INF;
if (a<=l && r<=b) return dat[k];
int vl = query(a,b,k*2+1,l,(l+r)/2);
int vr = query(a,b,k*2+2,(l+r)/2,r);
return min(vl,vr);
}
int main() {
int d;
ll kabu;
cin >> n >> d >> kabu;
init();
VI x(n);
REP(i,n){
scanf("%d", &x[i]);
update(i, x[i]);
}
ll ans = 0;
int j, k;
REP(i,n){
int mi = query(max(0, i-d), i+1, 0, 0, width);
if (x[i] - mi > ans){
ans = x[i] - mi;
k = i;
}
}
if (ans == 0){
cout << 0 << endl;
return 0;
}
FOR(i,k-d,k){
if (x[i] == x[k] - ans){
j = i;
break;
}
}
ans *= kabu;
printf("%lld\n%d %d\n", ans, j, k);
return 0;
}
TangentDay