답안 #380540

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380540 2021-03-22T08:35:03 Z SavicS Rima (COCI17_rima) C++14
28 / 140
103 ms 39580 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n;
string s[maxn];

int dp[maxn];

int idx = 0;
int kraj[20*maxn];
int lipa[20*maxn][26];
void add(string a, int id){
	int tr = 0;
	ff(i,0,sz(a) - 1){
		if(!lipa[tr][a[i] - 'a'])lipa[tr][a[i] - 'a'] = ++idx;
		tr = lipa[tr][a[i] - 'a'];
	}
	kraj[tr] = max(kraj[tr], dp[id]);
}

int kve(string a){
	int tr = 0;
	int pomtr = -1;
	int ide = 0;
	ff(i,0,sz(a) - 1){
		if(i == sz(a) - 1)pomtr = tr;
		if(!lipa[tr][a[i] - 'a'])break;
		ide = i;
		tr = lipa[tr][a[i] - 'a'];
	}
	// gledam za jednu ispred
	int ans = 0;
	if(pomtr != -1){
		ans = max(ans, kraj[pomtr]);
		ff(i,0,25){
			int ntr = lipa[pomtr][i];
			if(ntr){
				ans = max(ans, kraj[ntr]);
			}
		}	
	}
	// gledam za jednu ispod
	if(ide == sz(a) - 1){
		ff(i,0,25){
			int ntr = lipa[tr][i];
			if(ntr)ans = max(ans, kraj[ntr]);
		}	
	}
	return ans;
}

bool cmp(string s1, string s2){
	return sz(s1) < sz(s2);
}

int main()
{
   	ios::sync_with_stdio(false);
   	cout.tie(nullptr);
  	cin.tie(nullptr);
	cin >> n;
	ff(i,1,n)cin >> s[i];
	sort(s + 1, s + n + 1, cmp);
	int j = 0;
	while(j + 1 <= n && sz(s[j + 1]) == 1)j += 1;
	ff(i,1,j){
		string x = s[i];
		reverse(all(x));
		dp[i] = j;
		add(x, i);
	}
	ff(i,j + 1,n){
		string x = s[i];
		reverse(all(x));
		dp[i] = kve(x) + 1;	
		add(x, i);
	}
	int rez = 0;
	ff(i,1,n)rez = max(rez, dp[i]);
	cout << rez << endl;
   	return 0;
}
/**

3
v
v
lwt


5
og
g
keaag
v
wlc


// probati bojenje sahovski ili slicno

**/


# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 3564 KB Output isn't correct
2 Correct 3 ms 3584 KB Output is correct
3 Incorrect 2 ms 3564 KB Output isn't correct
4 Runtime error 27 ms 6764 KB Execution killed with signal 11
5 Correct 46 ms 6764 KB Output is correct
6 Incorrect 37 ms 35548 KB Output isn't correct
7 Incorrect 35 ms 35432 KB Output isn't correct
8 Incorrect 32 ms 35232 KB Output isn't correct
9 Incorrect 103 ms 39580 KB Output isn't correct
10 Incorrect 32 ms 35272 KB Output isn't correct