提出 #12162928
ソースコード 拡げる
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>
#include <bitset>
//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9+7;
const long long INF = 1e18;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> pdl;
typedef pair<LD, LD> pdd;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned long long ULL;
//typedef boost::multiprecision::cpp_int bigint;
LL N;
vector<PLL> A;
map<PLL, LL> DP;
LL dp(LL n,LL s,LL e) {
if (n == 0) {
DP.insert(pair<PLL, LL>(PLL(s, s), abs(A[0].second - s) * A[0].first));
return abs(A[0].second - s) * A[0].first;
}
//sに寄せた場合
LL ssc = abs(A[n].second - s) * A[n].first;
PLL tasks;
tasks.first = s + 1;
tasks.second = e;
if (DP.find(tasks) == DP.end()) {
dp(n - 1, s + 1, e);
}
ssc += DP.find(tasks)->second;
LL esc = abs(e - A[n].second) * A[n].first;
PLL taske;
taske.first = s;
taske.second = e - 1;
if (DP.find(taske) == DP.end()) {
dp(n - 1, s, e - 1);
}
esc += DP.find(taske)->second;
DP.insert(pair<PLL, LL>(PLL(s, e), max(ssc, esc)));
return max(ssc, esc);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
cin >> N;
A.resize(N);
for (LL n = 0; n < N; n++) {
cin >> A[n].first;
A[n].second = n;
}
sort(A.begin(), A.end(), [](PLL a, PLL b) {
return a.first < b.first;
});
cout << dp(N - 1, 0, N - 1) << "\n";
return 0;
}
提出情報
| 提出日時 |
|
| 問題 |
E - Active Infants |
| ユーザ |
ano3 |
| 言語 |
C++ (Clang 10.0.0) |
| 得点 |
500 |
| コード長 |
1922 Byte |
| 結果 |
AC |
| 実行時間 |
976 ms |
| メモリ |
128416 KiB |
コンパイルエラー
./Main.cpp:29:17: warning: unused variable 'MOD' [-Wunused-const-variable]
const long long MOD = 1e9+7;
^
./Main.cpp:30:17: warning: unused variable 'INF' [-Wunused-const-variable]
const long long INF = 1e18;
^
2 warnings generated.
ジャッジ結果
| セット名 |
Sample |
FULL |
| 得点 / 配点 |
0 / 0 |
500 / 500 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
Sample_01.txt, Sample_02.txt, Sample_03.txt |
| FULL |
Sample_01.txt, Sample_02.txt, Sample_03.txt, maxhand_01.txt, maxhand_02.txt, maxhand_03.txt, maxhand_04.txt, maxhand_05.txt, maxrand_01.txt, maxrand_02.txt, maxrand_03.txt, maxrand_04.txt, maxrand_05.txt, minhand_01.txt, minhand_02.txt, minhand_03.txt, minhand_04.txt, minrand_01.txt, minrand_02.txt, minrand_03.txt, minrand_04.txt, ni_01.txt, rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| Sample_01.txt |
AC |
2 ms |
3116 KiB |
| Sample_02.txt |
AC |
2 ms |
3116 KiB |
| Sample_03.txt |
AC |
2 ms |
3060 KiB |
| maxhand_01.txt |
AC |
971 ms |
128352 KiB |
| maxhand_02.txt |
AC |
971 ms |
128400 KiB |
| maxhand_03.txt |
AC |
969 ms |
128264 KiB |
| maxhand_04.txt |
AC |
969 ms |
128392 KiB |
| maxhand_05.txt |
AC |
976 ms |
128352 KiB |
| maxrand_01.txt |
AC |
972 ms |
128416 KiB |
| maxrand_02.txt |
AC |
968 ms |
128308 KiB |
| maxrand_03.txt |
AC |
974 ms |
128260 KiB |
| maxrand_04.txt |
AC |
969 ms |
128352 KiB |
| maxrand_05.txt |
AC |
971 ms |
128280 KiB |
| minhand_01.txt |
AC |
2 ms |
3068 KiB |
| minhand_02.txt |
AC |
2 ms |
3048 KiB |
| minhand_03.txt |
AC |
2 ms |
3008 KiB |
| minhand_04.txt |
AC |
2 ms |
3200 KiB |
| minrand_01.txt |
AC |
2 ms |
3016 KiB |
| minrand_02.txt |
AC |
2 ms |
3160 KiB |
| minrand_03.txt |
AC |
2 ms |
3124 KiB |
| minrand_04.txt |
AC |
2 ms |
3172 KiB |
| ni_01.txt |
AC |
2 ms |
3020 KiB |
| rand_01.txt |
AC |
223 ms |
33852 KiB |
| rand_02.txt |
AC |
849 ms |
113460 KiB |
| rand_03.txt |
AC |
542 ms |
74920 KiB |
| rand_04.txt |
AC |
39 ms |
8492 KiB |