結果
問題 |
No.777 再帰的ケーキ
|
ユーザー |
![]() |
提出日時 | 2018-12-25 01:59:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,416 bytes |
コンパイル時間 | 1,990 ms |
コンパイル使用メモリ | 135,024 KB |
最終ジャッジ日時 | 2025-01-06 20:02:12 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 WA * 15 TLE * 2 |
ソースコード
#include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<string> #include<cstring> #include<algorithm> #include<sstream> #include<complex> #include<functional> #include<vector> #include<map> #include<queue> #include<deque> #include<stack> #include<set> using namespace std; #define endl '\n' #define pb push_back #define fst first #define scd second #define EPS (1e-7) #define INF (1e9) #define PI (acos(-1)) #define ALL(x) (x).begin(), (x).end() #define RALL(x) (x).rbegin(), (x).rend() #define REP(i,n) for(int i = 0;i < (n);i++) #define FOR(i,a,b) for(int i = (a);i <= (b);i++) #define YES(n) cout << ((n) ? "YES" : "NO" ) << endl #define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl constexpr int MOD = 1000000007; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> P; typedef vector<int> vi; typedef vector<vector<int>> vii; typedef vector<ll> vl; template <class T = int> T in() { T x; cin >> x; return (x); } template <class T = int> void out(T x) { cout << (x) << endl; } ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; } // value ll N; vector<vector<ll>> cake; vector<pair<vector<ll>, ll>> m_cake; void solve() { cin >> N; cake.resize(N, vector<ll>(3)); for (ll i = 0; i < N; i++) { ll tmp1, tmp2, tmp3; cin >> tmp1 >> tmp2 >> tmp3; cake[i][0] = tmp1; cake[i][1] = tmp2; cake[i][2] = tmp3; } sort(ALL(cake), [](vector<ll> v1, vector<ll> v2) { if (v1[0] != v2[0]) { return v1[0] < v2[0]; } else { return v1[1] < v2[1]; } }); m_cake.pb(make_pair(vector<ll>(1, 0), 0)); for (int i = 0; i < N;) { ll tmp = cake[i][0]; ll tmp3 = i; for (int j = i; i < N && cake[j][0] == tmp; j++, i++) { pair<vector<ll>,ll> tmp2 = make_pair(vector<ll>(1,i), cake[i][2]); for (int k = 0; k < tmp3; k++) { if (cake[k][1] > cake[j][1]) break; vector<ll> tmp_cake = m_cake[k+1].fst; ll tmp_cal = m_cake[k+1].scd; if (cake[i][0] > cake[tmp_cake.back()][0] && cake[i][1] > cake[tmp_cake.back()][1]) { if (tmp2.scd < tmp_cal + cake[i][2]) { tmp_cake.pb(i); tmp2.fst = tmp_cake; tmp2.scd = tmp_cal + cake[i][2]; } } } m_cake.pb(tmp2); } } sort(ALL(m_cake), [](pair<vector<ll>, ll> p1, pair<vector<ll>, ll> p2) { return p1.scd > p2.scd; }); cout << m_cake[0].scd << endl; return; } int main() { cin.tie(0); ios::sync_with_stdio(false); solve(); return 0; }