답안 #380533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380533 2021-03-22T08:15:28 Z SavicS Rima (COCI17_rima) C++14
14 / 140
74 ms 39068 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;
}

int main()
{
   	ios::sync_with_stdio(false);
   	cout.tie(nullptr);
  	cin.tie(nullptr);
	cin >> n;
	ff(i,1,n)cin >> s[i];
	ff(i,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;
}
/**

4 
honi 
toni 
oni 
ovi 

3
odi
hodi
bodi

// probati bojenje sahovski ili slicno

**/


# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3564 KB Output isn't correct
2 Correct 3 ms 3564 KB Output is correct
3 Incorrect 3 ms 3564 KB Output isn't correct
4 Runtime error 25 ms 6764 KB Execution killed with signal 11
5 Incorrect 41 ms 6764 KB Output isn't correct
6 Incorrect 37 ms 35416 KB Output isn't correct
7 Incorrect 35 ms 35176 KB Output isn't correct
8 Incorrect 32 ms 35232 KB Output isn't correct
9 Incorrect 74 ms 39068 KB Output isn't correct
10 Incorrect 32 ms 35272 KB Output isn't correct