제출 #1241249

#제출 시각아이디문제언어결과실행 시간메모리
1241249rxlfd314상형문자열 (IOI24_hieroglyphs)C++20
3 / 100
30 ms2632 KiB
#include "hieroglyphs.h" #include <bits/stdc++.h> using namespace std; using ll = long long; using ari2 = array<int, 2>; using ari3 = array<int, 3>; using arl2 = array<ll, 2>; using arl3 = array<ll, 3>; template <class T> using vt = vector<T>; #define all(x) begin(x), end(x) #define size(x) (int((x).size())) #define REP(a,b,c,d) for(int a=(b);(d)>0?a<=(c):a>=(c);a+=(d)) #define FOR(a,b,c) REP(a,b,c,1) #define ROF(a,b,c) REP(a,b,c,-1) vt<int> ucs(vt<int> A, vt<int> B) { const int N = size(A), M = size(B); bool sub1 = N == M; vt<int> temp = A; sort(all(temp)); FOR(i, 0, N-1) sub1 &= temp[i] == i; temp = B; sort(all(temp)); FOR(i, 0, M-1) sub1 &= temp[i] == i; if (sub1) return A == B ? A : vt<int>{-1}; if (max(N, M) <= 3000) { A.insert(A.begin(), 0); B.insert(B.begin(), 0); vt<vt<int>> dp(N+1, vt<int>(M+1)); vt<vt<pair<int, int>>> par(N+1, vt<pair<int, int>>(M+1)); FOR(i, 1, N) FOR(j, 1, M) { dp[i][j] = max({dp[i-1][j-1] + (A[i] == B[j]), dp[i-1][j], dp[i][j-1]}); if (A[i] == B[j] && dp[i-1][j-1] + 1 == dp[i][j]) par[i][j] = {i-1, j-1}; else if (dp[i-1][j] == dp[i][j]) par[i][j] = {i-1, j}; else par[i][j] = {i, j-1}; } vt<int> ans; for (int i = N, j = M; i && j; ) { const auto &[x, y] = par[i][j]; if (x < i && y < j) { #ifdef DEBUG cout << "added: " << i << ' ' << j << '\n'; #endif ans.push_back(A[i]); } i = x, j = y; } reverse(all(ans)); constexpr int MAX = 200005; vt<int> cnt_A(MAX), cnt_B(MAX); FOR(i, 1, N) cnt_A[A[i]]++; FOR(i, 1, M) cnt_B[B[i]]++; int must = 0; FOR(i, 0, MAX-1) must += min(cnt_A[i], cnt_B[i]); #ifdef DEBUG cout << "must: " << must << '\n'; #endif return size(ans) < must ? vt<int>{-1} : ans; } }

컴파일 시 표준 에러 (stderr) 메시지

hieroglyphs.cpp: In function 'vt<int> ucs(vt<int>, vt<int>)':
hieroglyphs.cpp:70:1: warning: control reaches end of non-void function [-Wreturn-type]
   70 | }
      | ^
#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...