Submission #102518

#TimeUsernameProblemLanguageResultExecution timeMemory
102518jhnah917조화행렬 (KOI18_matrix)C++14
29 / 100
307 ms7024 KiB
#include <bits/stdc++.h> #define x first #define y second using namespace std; typedef pair<int, int> p; typedef pair<int, p> pp; void f2(){ int n; cin >> n; vector<p> v(n); for(int i=0; i<n; i++) cin >> v[i].x; for(int i=0; i<n; i++) cin >> v[i].y; sort(v.begin(), v.end()); int ans = 0; vector<int> lis(1, -1); for(auto &i : v){ int now = i.y; if(now > lis.back()) lis.push_back(now), ans++; else{ auto it = lower_bound(lis.begin(), lis.end(), now); *it = now; } } cout << ans; } void f3(){ int n; cin >> n; vector<pp> v(n); for(int i=0; i<n; i++) cin >> v[i].x; for(int i=0; i<n; i++) cin >> v[i].y.x; for(int i=0; i<n; i++) cin >> v[i].y.y; sort(v.begin(), v.end()); vector<int> dp(n, 0); dp[0] = 1; int ans = 0; for(int i=2; i<n; i++){ int now = 0; for(int j=i-1; j>=0; j--){ if(v[j].y.x < v[i].y.x && v[j].y.y < v[i].y.y) now = max(now, dp[j]); } dp[i] = now+1; ans = max(ans, dp[i]); } cout << ans; } int main(){ int n; cin >> n; if(n == 2){ f2(); }else{ f3(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...