제출 #1203785

#제출 시각아이디문제언어결과실행 시간메모리
1203785Andrey상형문자열 (IOI24_hieroglyphs)C++20
14 / 100
990 ms2162688 KiB
#include "hieroglyphs.h" #include <vector> #include<bits/stdc++.h> using namespace std; vector<int> pos[200001]; int dude(int x, int a) { if(pos[x].size() == 0 || pos[x][pos[x].size()-1] < a) { return -1; } int l = 0,r = pos[x].size()-1; while(l < r) { int mid = (l+r)/2; if(pos[x][mid] >= a) { r = mid; } else { l = mid+1; } } return pos[x][l]; } std::vector<int> ucs(std::vector<int> a, std::vector<int> b) { int n = a.size(),m = b.size(); int dp[n+1][m+1]; for(int i = 0; i <= n; i++) { for(int j = 0; j <= m; j++) { dp[i][j] = 0; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { dp[i][j] = max(dp[i-1][j],dp[i][j-1]); if(a[i-1] == b[j-1]) { dp[i][j] = max(dp[i][j],dp[i-1][j-1]+1); } } } vector<int> ans(0); int x = n,y = m; while(x != 0 && y != 0) { if(a[x-1] == b[y-1]) { ans.push_back(a[x-1]); x--; y--; } else { if(dp[x-1][y] == dp[x][y]) { x--; } else { y--; } } } reverse(ans.begin(),ans.end()); for(int i = 0; i < ans.size(); i++) { pos[ans[i]].push_back(i+1); } int wow[n+1][m+1]; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { wow[i][j] = 0; } } for(int i = 1; i <= n; i++) { for(int j = 1; j <= m; j++) { wow[i][j] = max(wow[i-1][j],wow[i][j-1]); if(a[i-1] == b[j-1]) { int c = dude(a[i-1],wow[i-1][j-1]+1); if(c == -1) { return {-1}; } wow[i][j] = max(wow[i][j],c); } } } return ans; }
#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...