Submission #380405

# Submission time Handle Problem Language Result Execution time Memory
380405 2021-03-21T15:47:59 Z SavicS Three Friends (BOI14_friends) C++14
0 / 100
20 ms 16144 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 = 200005;
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;

// Hashing - O(n)
const int mod = 1e9 + 7;
ll add(ll a, ll b){
    return (a + b) % mod;
}
ll sub(ll a, ll b){
	return (a - b + mod) % mod;
}
ll mul(ll a, ll b){
    return (a * b) % mod;
}
ll power(ll a, ll b){
    if(!b)return 1;
    ll pola = power(a, b / 2);
    pola = mul(pola, pola);
    if(b % 2)pola = mul(pola, a);
    return pola;
}
ll inv(ll a){
    return power(a, mod - 2);
}

const int p = 31;
ll pw[maxn];
ll invz[maxn];
void init_hsh(){
	pw[0] = 1;
	ff(i,1,maxn - 1)pw[i] = mul(pw[i - 1], p);
	invz[maxn - 1] = inv(pw[maxn - 1]);
	fb(i,maxn - 2, 0)invz[i] = mul(invz[i + 1], p);
}

ll hsh[maxn];
ll get(int l, int r){
	if(l > r)return 0;
	return mul(sub(hsh[r], hsh[l - 1]), invz[l - 1]);
}

int main()
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
	cin >> n >> s;
	if(n % 2 == 0)return cout << "NOT POSSIBLE", 0;
	init_hsh();
	ff(i,0,n - 1)hsh[i + 1] = add(hsh[i], mul(pw[i], s[i] - 'A' + 1));
	int len = (n - 1) / 2;
	
	int rez = 0;
	int L = 0, R = -1;
	ff(i,1,len){
		ll a1 = hsh[i - 1];
		ll a2 = mul(pw[i - 1], get(i + 1, len + 1));
		ll a = a1 + a2;
		ll b = get(len + 2, n);
		if(a == b){
			rez += 1;
			L = len + 2;
			R = n;
		}
	}
	
	ff(i,len + 1,n){
		ll a1 = get(len + 1, i - 1);
		ll a2 = mul(pw[i - len - 1], get(i + 1, n));
		ll a = a1 + a2;
		ll b = hsh[len];
		if(a == b){
			rez += 1;
			L = 1;
			R = len;
		}
	}
	
	if(rez > 1){
		cout << "NOT UNIQUE" << endl;
		return 0;
	}
	ff(i,L - 1,R - 1)cout << s[i];
	cout << endl;
	
    return 0;
}
/**



// probati bojenje sahovski ili slicno

**/

# Verdict Execution time Memory Grader output
1 Correct 4 ms 3436 KB Output is correct
2 Correct 5 ms 3436 KB Output is correct
3 Correct 4 ms 3436 KB Output is correct
4 Correct 4 ms 3436 KB Output is correct
5 Correct 4 ms 3436 KB Output is correct
6 Correct 4 ms 3436 KB Output is correct
7 Correct 4 ms 3436 KB Output is correct
8 Correct 5 ms 3436 KB Output is correct
9 Correct 5 ms 3436 KB Output is correct
10 Correct 4 ms 3456 KB Output is correct
11 Correct 4 ms 3436 KB Output is correct
12 Correct 4 ms 3436 KB Output is correct
13 Correct 4 ms 3436 KB Output is correct
14 Correct 4 ms 3436 KB Output is correct
15 Correct 4 ms 3436 KB Output is correct
16 Correct 4 ms 3436 KB Output is correct
17 Correct 4 ms 3436 KB Output is correct
18 Correct 4 ms 3436 KB Output is correct
19 Correct 5 ms 3436 KB Output is correct
20 Correct 4 ms 3444 KB Output is correct
21 Correct 4 ms 3436 KB Output is correct
22 Correct 5 ms 3436 KB Output is correct
23 Incorrect 5 ms 3436 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 20 ms 16144 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -