Submission #930850

# Submission time Handle Problem Language Result Execution time Memory
930850 2024-02-20T13:49:05 Z WH8 Three Friends (BOI14_friends) C++14
0 / 100
500 ms 8196 KB
#include <bits/stdc++.h>
using namespace std;
#define iloop(x, n) for (long long i = x; i < n; ++i)
#define jloop(x, n) for (long long j = x; j < n; ++j)
#define kloop(x, n) for (long long k = x; k < n; ++k)
#define dloop(x, n) for (long long d = x; d >= n; --d)
#define ll long long
#define pll pair<long long, long long>
#define pii pair<int, int>
#define iii tuple<int, int, int>
#define vi vector<int>
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define int long long
#define endl '\n'
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define dg(x) cout << #x << ": " << x << endl
#define all(x) x.begin(), x.end()
#define FASTIO               \
    ios::sync_with_stdio(false); \
	cin.tie(0);              \
    cout.tie(0);


int32_t main(){
	FASTIO
	int l; cin >> l;
	string s;
	cin >> s;
	if ((l - 1) % 2 != 0) {
		cout << "NOT POSSIBLE";
		return 0;
	}
	int n = l / 2;
	string lf, lb, rf, rb;
	iloop(0, n){
		lf += s[i];
	}
	iloop(n+1, l){
		rf += s[i];
	}
	int cnt = 0;
	string ans;
	for (int j = n; j >= 0; j--){
		if (j != n){
			lf.pop_back();
			lb += s[j + 1];

			rf.pop_back();
			rb += s[l + j - n];
		}
		if (lf == rf and lb == rb){
			string temp = rb;
			reverse(all(temp));
			if (ans.length() == 0) ans = rf + temp;
			cnt++;
		}
	}
	lf = lb = rf = rb = "" ;
	iloop(n, l - 1){
		lf += s[i];
	}
	iloop(0, n){
		rf += s[i];
	}
	for (int j = l - 1 ; j >= n; j--){
		if (j != l - 1){
			lf.pop_back();
			lb += s[j + 1];

			rf.pop_back();
			rb += s[l + j - n];
		}
		if (lf == rf and lb == rb){
			string temp = rb;
			reverse(all(temp));
			if (ans.length() == 0) ans = rf + temp;
			cnt++;
		}
	}
	if (cnt == 0){
		cout << "NOT POSSIBLE";

	}
	else if (cnt == 1){
		cout << ans;
	}
	else cout << "NOT UNIQUE";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 452 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 456 KB Output is correct
5 Incorrect 1 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1052 ms 8196 KB Time limit exceeded
2 Halted 0 ms 0 KB -