Submission #83093

#TimeUsernameProblemLanguageResultExecution timeMemory
83093chunghan막대기 (KOI13_game)C++17
0 / 100
1067 ms2212 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int lld; typedef pair<int, int> pii; int N, L; vector<pii> S; lld D[100005]; lld solve(int p) { if(D[p] != -1) return D[p]; lld ret = 0; for(int i = 0; i < p; i++) { if(S[i].second == S[p].second) ret = max(ret, solve(i)); if(S[i].first == S[p].first && S[i].second < S[p].second) ret = max(ret, solve(i)); } return D[p] = ret + abs(S[p].first - S[p].second) + L; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); memset(D, -1, sizeof(D)); cin >> N >> L; for(int i = 0; i < N; i++) { int x, y; cin >> x >> y; S.push_back(pii(x, y)); } sort(S.begin(), S.end()); lld rst = 0; for(int i = 0; i < N; i++) rst = max(rst, solve(i)); cout << rst; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...