結果
| 問題 |
No.952 危険な火薬庫
|
| コンテスト | |
| ユーザー |
tarattata1
|
| 提出日時 | 2019-12-15 22:10:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,699 bytes |
| コンパイル時間 | 743 ms |
| コンパイル使用メモリ | 78,432 KB |
| 実行使用メモリ | 49,408 KB |
| 最終ジャッジ日時 | 2024-07-02 18:22:51 |
| 合計ジャッジ時間 | 3,705 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 22 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:31:14: warning: spurious trailing ‘%’ in format [-Wformat=]
31 | scanf("%d%", &n);
| ^
main.cpp:31:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | scanf("%d%", &n);
| ~~~~~^~~~~~~~~~~
main.cpp:35:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
35 | scanf("%lld", &A[i]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996)
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;
ll dp[3005][3005]; // dp[i][j] i番目(0,1,..i-1)まで見て、j個閉じている場合の危険度の最小値
int main(int argc, char* argv[])
{
int n;
scanf("%d%", &n);
vector<ll> A(n),S(n+1);
int i,j;
for(i=0; i<n; i++) {
scanf("%lld", &A[i]);
S[i+1]=S[i]+A[i];
}
vector<ll> a(n+1),b(n+1);
const double eps=1e-6;
for(j=0; j<=n; j++) {
if(j==0) {
for(i=0; i<=n; i++) {
dp[i][j]=S[i]*S[i];
}
}
else {
vector<pair<double,int> > z; // xの値, xより少し大きいところの直線のindex
for(i=j; i<=n; i++) {
if(i>j) {
ll tmp=0;
if(!z.empty()) {
int k=lower_bound(z.begin(), z.end(), make_pair((double)S[i]+eps,-INF))-z.begin();
if(k>0) {
k--;
int id=z[k].second;
tmp=a[id]*S[i]+b[id];
}
}
dp[i][j]=tmp+S[i]*S[i];
}
if(i<n) {
// for CHT
a[i]=-2*S[i+1];
b[i]=dp[i][j-1]+S[i+1]*S[i+1];
while( 1 ) {
if(z.empty()) {
z.push_back(make_pair(-LINF,i));
break;
}
else {
double x0=z.back().first;
int id0=z.back().second;
double tmp=-(double)(b[i]-b[id0])/(a[i]-a[id0]);
if(tmp<x0) {
z.pop_back();
}
else {
z.push_back(make_pair(tmp,i));
break;
}
}
}
}
}
}
}
for(i=0; i<n; i++) {
printf("%lld\n", dp[n][n-1-i]);
}
return 0;
}
tarattata1