제출 #1184982

#제출 시각아이디문제언어결과실행 시간메모리
1184982ThunnusArcade (NOI20_arcade)C++20
51 / 100
3 ms584 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define int i64 #define vi vector<int> #define vvi vector<vi> #define vb vector<bool> #define pii pair<int, int> #define fi first #define se second #define sz(x) (int)(x).size() inline void solve(){ int n, m; cin >> n >> m; vector<pii> a(m); // (x, y), x = a[i], y = t[i], each hand can be descriped by a line heading downwards and connecting points, such that no line exceeds an angle of 45 degrees from the vertical (in both directions). for(int i = 0; i < m; i++){ cin >> a[i].se; } for(int i = 0; i < m; i++){ cin >> a[i].fi; } for(int i = 0; i < m; i++){ // rotate the grid 45 degrees clockwise. Now all lines must connect points where one point is the bottom-left of another. This grid can be viewed as a DAG. a[i] = {a[i].fi - a[i].se, a[i].fi + a[i].se}; } // The question now becomes: How do we decompose this DAG into the minimum number of chains such that each chain follows the edges on that DAG? // By Dilworth's theorem the minimum partitioning of a DAG into chains is equal to the size of the maximum antichain. // Maximum antichain -> Finding a line connecting the maximum number of points such that the line can only head bottom-right. // Finding this line is the equivalent of sorting the points by their y (t) values and finding the longest increasing subsequence by their x (a) values sort(a.begin(), a.end(), [&](const pii &lhs, const pii &rhs){return lhs.se < rhs.se;} ); auto find_lis = [&]() -> int { vi lis; for(int i = 0; i < m; i++){ int pos = lower_bound(lis.begin(), lis.end(), a[i].fi) - lis.begin(); if(pos == sz(lis)){ lis.emplace_back(a[i].fi); } else{ lis[pos] = a[i].fi; } } return sz(lis); }; cout << find_lis() << "\n"; return; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } 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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...