提出 #34408251


ソースコード 拡げる

#include <iostream>
#include <sstream>
#include <vector>
#include <iterator>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cctype>
#include <cassert>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <string>
#include <ext/pb_ds/assoc_container.hpp>

// #define cerr if(false)cerr
#define see(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
  for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
    out << v[i] << " ";
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, set<T> &s) {
  for (auto e : s)
    out << e << " ";
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, multiset<T> &s) {
  for (auto e : s)
    out << e << " ";
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, queue<T> &s) {
  for (auto e : s)
    out << e << " ";
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, deque<T> &s) {
  for (auto e : s)
    out << e << " ";
  out << "\n";
  return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, pair<T, N> &p) {
  out << "(" << p.first << ", " << p.second << ") ";
  return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
  for (size_t i = 0; i < v.size(); ++i)
    cout << v[i];
  out << "\n";
  return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, set<pair<T, N> > &s) {
  for (auto p : s)
    out << p;
  out << "\n";
  return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    for (size_t j = 0; j < v[i].size(); ++j) {
      out << v[i][j] << " ";
    }
    out << "\n";
  }
  return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<set<T> > &v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
  }
  out << "\n";
  return out;
}

int n;
vector<vector<long long> > snukes;
vector<vector<long long> > memo;

long long memoization(int t, int p) {
  if (t == 1e5 + 1) return 0;
  if (memo[p][t] != LLONG_MIN) {
    return memo[p][t];
  }

  memo[p][t] = snukes[p][t];
  if (p > 0 && p < 4) {
    memo[p][t] = max(memo[p][t] + memoization(t + 1, p), max(memo[p][t] + memoization(t + 1, p - 1), memo[p][t] + memoization(t + 1, p + 1)));
  }
  else if (p > 0) {
    memo[p][t] = max(memo[p][t] + memoization(t + 1, p), memo[p][t] + memoization(t + 1, p - 1));
  }
  else if (p < 4) {
    memo[p][t] = max(memo[p][t] + memoization(t + 1, p), memo[p][t] + memoization(t + 1, p + 1));
  }

  return memo[p][t];
}

void solve() {
  cin >> n;

  snukes = vector<vector<long long> > (5, vector<long long> (1e5 + 1));
  int t, x, a;
  for (int i = 0; i < n; ++i) {
    cin >> t >> x >> a;
    snukes[x][t] += a;
  }

  memo = vector<vector<long long> > (5, vector<long long> (1e5 + 1, LLONG_MIN));
  memoization(0, 0);

  cout << memo[0][0] << "\n";

  return ;
}

int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);

  int t;
  t = 1;

  while (t--) {
    solve();
  }

  return 0;

}

提出情報

提出日時
問題 D - Snuke Panic (1D)
ユーザ SoumyadeepPal21
言語 C++ (GCC 9.2.1)
得点 400
コード長 3909 Byte
結果 AC
実行時間 48 ms
メモリ 22856 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 30
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All hand_01.txt, hand_02.txt, min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
hand_01.txt AC 28 ms 22768 KiB
hand_02.txt AC 23 ms 22728 KiB
min.txt AC 31 ms 22652 KiB
random_01.txt AC 45 ms 22856 KiB
random_02.txt AC 44 ms 22772 KiB
random_03.txt AC 44 ms 22856 KiB
random_04.txt AC 45 ms 22628 KiB
random_05.txt AC 39 ms 22784 KiB
random_06.txt AC 42 ms 22828 KiB
random_07.txt AC 36 ms 22816 KiB
random_08.txt AC 38 ms 22828 KiB
random_09.txt AC 31 ms 22660 KiB
random_10.txt AC 26 ms 22660 KiB
random_11.txt AC 24 ms 22852 KiB
random_12.txt AC 27 ms 22800 KiB
random_13.txt AC 48 ms 22664 KiB
random_14.txt AC 45 ms 22856 KiB
random_15.txt AC 45 ms 22856 KiB
random_16.txt AC 45 ms 22772 KiB
random_17.txt AC 44 ms 22856 KiB
random_18.txt AC 44 ms 22720 KiB
random_19.txt AC 33 ms 22660 KiB
random_20.txt AC 40 ms 22676 KiB
random_21.txt AC 30 ms 22792 KiB
random_22.txt AC 26 ms 22828 KiB
random_23.txt AC 28 ms 22676 KiB
random_24.txt AC 30 ms 22812 KiB
sample_01.txt AC 22 ms 22792 KiB
sample_02.txt AC 30 ms 22820 KiB
sample_03.txt AC 29 ms 22740 KiB