Submission #421094

# Submission time Handle Problem Language Result Execution time Memory
421094 2021-06-08T18:04:05 Z abdzag Necklace (Subtask 1-3) (BOI19_necklace1) C++17
0 / 85
5 ms 3464 KB
#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 1e15;
vector<ull> suffix(1e5);
vector<ull> suffix2(1e5);
vector<ull> suffix3(1e5);
vector<ull> powers(1e5);
ll n;
ull getS(vector<ull>& v, ll start, ll end) {
	if (start >= end)return 0;
	return v[start] - (v[end] * powers[end - start]);
}
int main() {
	cin.sync_with_stdio(false);
	vector<ull> primes = { 43,47,53,59,61,67,71,73,79,83,89,97,101,103,107 };
	string a, b;
	cin >> a >> b;
	n = a.size();
	ull c = 31;
	powers[0] = 1;
	rep(i, 1, 1e5)powers[i] = powers[i - 1] * c;
	rrep(i, a.size() - 1, -1)suffix[i] = a[i] + c * suffix[i + 1];
	rrep(i, b.size() - 1, -1)suffix2[i] = b[i] + c * suffix2[i + 1];
	reverse(all(a));
	rrep(i, a.size() - 1, -1)suffix3[i] = a[i] + c * suffix3[i + 1];
	ll ans = 0;
	ll pos1, pos2;
	rep(i, 0, b.size()) {
		rep(j, 0, a.size()) {
			int FuckMinAndMax = b.size() - i;
			ll l = 1, r = min(j, FuckMinAndMax);//maybe wrong
			ll val1 = 0;
			rep (mid,l,r+1) {
				if (getS(suffix2, i, i + mid) == getS(suffix, j - mid, j)) {
					val1 = mid;
				}
			}
			FuckMinAndMax = a.size() - j;
			l = 0, r = min(i, FuckMinAndMax);//maybe wrong
			ll val2 = 0;
			rep(mid,l,r+1) {
				if (getS(suffix2, i-mid, i) == getS(suffix, j, j+mid)) {
					val2 = mid;
				}
			}
			if (val1 + val2 > ans) {
				ans = val1 + val2;
				pos1 = j;
				pos2 = i;
			}
		}
		rep(j, 0, a.size()) {
			int FuckMinAndMax = b.size() - i;
			ll l = 1, r = min(j, FuckMinAndMax);//maybe wrong
			ll val1 = 0;
			rep(mid,l,r+1) {
				if (getS(suffix2, i, i + mid) == getS(suffix3, j - mid, j)) {
					val1 = mid;
				}
			}
			FuckMinAndMax = a.size() - j;
			l = 0, r = min(i, FuckMinAndMax);//maybe wrong
			ll val2 = 0;
			rep (mid,l,r+1) {
				if (getS(suffix2, i - mid, i) == getS(suffix3, j, j + mid)) {
					val2 = mid;
				}
			}
			if (val1 + val2 > ans) {
				ans = val1 + val2;
				pos1 = a.size()-j;
				pos2 = i;
			}
		}
	}
	cout << ans << endl;
	if (ans)cout << pos1  << " " << pos2 << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3464 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3464 KB Output isn't correct
2 Halted 0 ms 0 KB -