답안 #604017

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
604017 2022-07-24T15:22:26 Z inksamurai Savez (COCI15_savez) C++17
96 / 120
315 ms 65128 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rng(i,c,n) for(int i=(c);i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define vec(...) vector<__VA_ARGS__>
#define _3aFGabX ios::sync_with_stdio(0),cin.tie(0)
typedef long long ll;
using pii=pair<int,int>;
using vi=vector<int>;
void print(){cout<<'\n';}
template<class h,class...t>
void print(const h&v,const t&...u){cout<<v<<' ',print(u...);}
// e

// kactl : Z function
vi Z(string S) {
	vi z(sz(S));
	int l = -1, r = -1;
	rng(i,1,sz(S)) {
		z[i] = i >= r ? 0 : min(r - i, z[i - l]);
		while (i + z[i] < sz(S) && S[i + z[i]] == S[z[i]])
			z[i]++;
		if (i + z[i] > r)
			l = i, r = i + z[i];
	}
	return z;
}


signed main(){
_3aFGabX;
	int n;
	cin>>n;
	vec(string) a,tmp;
	rep(i,n){
		string s;
		cin>>s;
		a.pb(s);
		string rs=s;
		reverse(rs.begin(), rs.end());
		tmp.pb(rs);
	}
	sort(tmp.begin(), tmp.end());
	tmp.erase(unique(tmp.begin(), tmp.end()),tmp.end());
	const int m=sz(tmp);
	// sort(a.begin(), a.end(),[&](const string&l,const string&r){
	// 	return sz(l)<sz(r);
	// });
	vi dp(m,0);
	rep(i,n){
		vi z=Z(a[i]);
		// rep(j,sz(a[i])){
		// 	cout<<z[j]<<" ";
		// }
		// print("....");
		int id=(int)(lower_bound(tmp.begin(), tmp.end(),a[i])-tmp.begin());
		string now="";
		int res=dp[id];
		per(j,sz(a[i])){
			now+=a[i][j];
			if(!j or z[j]==sz(a[i])-j){
				int ni=(int)(lower_bound(tmp.begin(), tmp.end(),now)-tmp.begin());
				// if(i==2) print(ni);
				res=max(res,dp[ni]+1);
			}
		}
		dp[id]=res;
		// print(id,dp[id],a[i]);
	}
	print(*max_element(dp.begin(), dp.end()));
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Incorrect 2 ms 468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2292 KB Output is correct
2 Correct 77 ms 2260 KB Output is correct
3 Correct 276 ms 3496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 101 ms 3028 KB Output is correct
3 Correct 166 ms 2452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 3032 KB Output is correct
2 Correct 46 ms 4060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 48 ms 3900 KB Output is correct
2 Correct 44 ms 5000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 53 ms 5432 KB Output is correct
2 Correct 51 ms 6356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 8064 KB Output is correct
2 Correct 59 ms 8888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 15512 KB Output is correct
2 Correct 91 ms 16740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 159 ms 25584 KB Output is correct
2 Correct 141 ms 26980 KB Output is correct
3 Correct 315 ms 65128 KB Output is correct