Submission #37847639


Source Code Expand

Copy
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define SYNC std::ios_base::sync_with_stdio(0); cout.tie(nullptr);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)
void __print(int x) {cerr << x;}
void __print(int32_t x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#define _CRT_SECURE_NO_DEPRECATE
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define SYNC std::ios_base::sync_with_stdio(0); cout.tie(nullptr);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout)

void __print(int x) {cerr << x;}
void __print(int32_t x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...) 42
#endif

const int MOD = 1e9 + 7;
const int MOD1 = 998244353;
const int N = 2e6 + 5;
const int INF = 1000111000111000111LL;
const long double EPS = 1e-12;
const long double PI = 3.141592653589793116;

const int mod_hash = 1e9+207;
const int p = 31;
const int p1 = 29;
const int mod_hash1 = 1e9+7;

int modular_exp(int base,int exp,int mod)
{
    int ans =1;
    while(exp)
    {
        if(exp%2)   ans = ans%mod*base%mod;
        base = (base%mod*base%mod)%mod;
        exp/=2;
        ans%=mod;
    }
    return ans;
}
int inverse_modulo(int base,int mod)
{
    return modular_exp(base,mod-2,mod);
}
int p_inv[N];
int p_inv1[N];


struct str_hash
{
    string s;
    vector<int> pre;
    vector<int> pre1;
    str_hash(string s) {
        this->s = s;
        compute_hash();
    }
    void compute_hash()
    {
        int hash_val = 0, hash_val1 = 0;
        int p_pow = 1;
        vector<int> pre_compute, pre_compute1;
        for(auto c : s) {
            hash_val = (hash_val + (c-'a'+1)*p_pow) % mod_hash;
            p_pow = (p_pow * p) % mod_hash;
            pre_compute.push_back(hash_val);
        }
        p_pow = 1;
        for(auto c : s) {
            hash_val1 = (hash_val1 + (c-'a'+1)*p_pow) % mod_hash1;
            p_pow = (p_pow * p1) % mod_hash1;
            pre_compute1.push_back(hash_val1);
        }
        this->pre = pre_compute;
        this->pre1 = pre_compute1;
    }
    pair<int, int> get_hash(int l, int r)
    {
    	if (l > r)
    		return {0, 0};
        if(l==0)    return {pre[r], pre1[r]};
        int res = (pre[r] - pre[l-1]+mod_hash)%mod_hash;
        res *= p_inv[l];
        int res1 = (pre1[r] - pre1[l-1]+mod_hash1)%mod_hash1;
        res1 *= p_inv1[l];
        return {res % mod_hash, res1 % mod_hash1};
    }
};

string get_str(string a, int l, int r) {
	return a.substr(l, r - l + 1);
}

void pre_all() {
	int inv = inverse_modulo(p,mod_hash);
    p_inv[0] = 1;
    for(int i = 1; i < N; i++) p_inv[i] = (inv * p_inv[i-1])%mod_hash;

    int inv1 = inverse_modulo(p1,mod_hash1);
    p_inv1[0] = 1;
    for(int i = 1; i < N; i++) p_inv1[i] = (inv1 * p_inv1[i-1])%mod_hash1; 
}

int32_t main() {
	SYNC
	pre_all();
	int n; cin >> n;
	string t; cin >> t;
	string rev_t = t;
	reverse(rev_t.begin(), rev_t.end());

	str_hash f_hash(t);
	str_hash b_hash(rev_t);
	// debug(f_hash.get_hash(0, 2), b_hash.get_hash(1, 3));
	for (int i = 0; i < n; i++) {
		bool match = true;
		if (f_hash.get_hash(0, i) != b_hash.get_hash(n - i - 1, n - 1))
			match = false;
		if (i == 1) {
			debug(get_str(t, 0, i), get_str(rev_t, n - i - 1, n - 1), match);
		}
		if (f_hash.get_hash(i + n + 1, 2 * n - 1) !=  b_hash.get_hash(n, 2 * n - i - 2))
			match = false;
		// if (i == 1) {
		// 	debug(f_hash.get_hash(i + n + 1, 2 * n - 1));
		// 	debug(b_hash.get_hash(n, 2 * n - i - 2));
		// 	debug(get_str(t, i + n + 1, 2 * n - 1), get_str(rev_t, n, 2 * n - i - 2), match);
		// }
		if (match) {
			string res = t.substr(i + 1, n);
			reverse(res.begin(), res.end());
			cout << res << '\n' << i + 1;
			return 0;
		}
	}
	int all_match = 0;
	int rt = 2 * n - 1;
	for (int i = n - 1; i >= 0; i--) {
		if (t[i] == t[rt])
			all_match++;
		rt--;
	}
	if (all_match == n) {
		cout << t.substr(n, n) << '\n' << 0;
	}
    return 0;
}

Submission Info

Submission Time
Task F - ABCBAC
User darklight13
Language C++ (GCC 9.2.1)
Score 0
Code Size 4627 Byte
Status WA
Exec Time 209 ms
Memory 138732 KB

Compile Error

./Main.cpp: In function ‘int32_t main()’:
./Main.cpp:29:21: warning: statement has no effect [-Wunused-value]
   29 | #define debug(x...) 42
      |                     ^~
./Main.cpp:135:4: note: in expansion of macro ‘debug’
  135 |    debug(get_str(t, 0, i), get_str(rev_t, n - i - 1, n - 1), match);
      |    ^~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 500
Status
AC × 3
WA × 1
AC × 41
WA × 19
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_small_00.txt, 01_small_01.txt, 01_small_02.txt, 01_small_03.txt, 01_small_04.txt, 01_small_05.txt, 01_small_06.txt, 01_small_07.txt, 02_large_00.txt, 02_large_01.txt, 02_large_02.txt, 02_large_03.txt, 02_large_04.txt, 02_large_05.txt, 02_large_06.txt, 02_large_07.txt, 02_large_08.txt, 02_large_09.txt, 02_large_10.txt, 02_large_11.txt, 02_large_12.txt, 02_large_13.txt, 02_large_14.txt, 02_large_15.txt, 03_max_00.txt, 03_max_01.txt, 03_max_02.txt, 03_max_03.txt, 03_max_04.txt, 03_max_05.txt, 03_max_06.txt, 03_max_07.txt, 04_min_00.txt, 04_min_01.txt, 05_two_types_00.txt, 05_two_types_01.txt, 05_two_types_02.txt, 05_two_types_03.txt, 06_repeat_00.txt, 06_repeat_01.txt, 06_repeat_02.txt, 06_repeat_03.txt, 06_repeat_04.txt, 07_killer_00.txt, 07_killer_01.txt, 07_killer_02.txt, 07_killer_03.txt, 07_killer_04.txt, 08_killer2_00.txt, 08_killer2_01.txt, 08_killer2_02.txt, 09_killer3_00.txt, 09_killer3_01.txt, 09_killer3_02.txt, 09_killer3_03.txt, 09_killer3_04.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 45 ms 34768 KB
00_sample_01.txt AC 43 ms 34928 KB
00_sample_02.txt AC 41 ms 34924 KB
00_sample_03.txt WA 39 ms 34828 KB
01_small_00.txt AC 44 ms 35012 KB
01_small_01.txt AC 39 ms 34868 KB
01_small_02.txt AC 41 ms 34928 KB
01_small_03.txt AC 41 ms 35000 KB
01_small_04.txt AC 39 ms 34796 KB
01_small_05.txt AC 40 ms 34884 KB
01_small_06.txt WA 41 ms 34856 KB
01_small_07.txt WA 41 ms 34908 KB
02_large_00.txt AC 201 ms 138676 KB
02_large_01.txt AC 189 ms 138660 KB
02_large_02.txt AC 208 ms 138560 KB
02_large_03.txt AC 192 ms 138656 KB
02_large_04.txt AC 198 ms 138652 KB
02_large_05.txt AC 193 ms 138612 KB
02_large_06.txt WA 204 ms 138672 KB
02_large_07.txt WA 205 ms 138552 KB
02_large_08.txt AC 207 ms 138572 KB
02_large_09.txt AC 192 ms 138648 KB
02_large_10.txt AC 203 ms 138628 KB
02_large_11.txt AC 195 ms 138548 KB
02_large_12.txt AC 204 ms 138544 KB
02_large_13.txt AC 192 ms 138604 KB
02_large_14.txt WA 205 ms 138552 KB
02_large_15.txt WA 204 ms 138612 KB
03_max_00.txt AC 194 ms 138648 KB
03_max_01.txt AC 205 ms 138556 KB
03_max_02.txt AC 194 ms 138608 KB
03_max_03.txt AC 208 ms 138656 KB
03_max_04.txt AC 204 ms 138628 KB
03_max_05.txt AC 209 ms 138728 KB
03_max_06.txt WA 207 ms 138556 KB
03_max_07.txt WA 205 ms 138664 KB
04_min_00.txt AC 44 ms 34828 KB
04_min_01.txt WA 41 ms 34700 KB
05_two_types_00.txt AC 196 ms 138728 KB
05_two_types_01.txt AC 207 ms 138560 KB
05_two_types_02.txt AC 191 ms 138608 KB
05_two_types_03.txt WA 206 ms 138732 KB
06_repeat_00.txt AC 189 ms 138616 KB
06_repeat_01.txt AC 189 ms 138552 KB
06_repeat_02.txt AC 189 ms 138648 KB
06_repeat_03.txt AC 188 ms 138660 KB
06_repeat_04.txt AC 192 ms 138652 KB
07_killer_00.txt WA 203 ms 138652 KB
07_killer_01.txt WA 203 ms 138732 KB
07_killer_02.txt WA 205 ms 138612 KB
07_killer_03.txt WA 203 ms 138556 KB
07_killer_04.txt WA 204 ms 138624 KB
08_killer2_00.txt WA 204 ms 138660 KB
08_killer2_01.txt WA 202 ms 138608 KB
08_killer2_02.txt WA 202 ms 138732 KB
09_killer3_00.txt AC 205 ms 138588 KB
09_killer3_01.txt AC 205 ms 138572 KB
09_killer3_02.txt AC 194 ms 138668 KB
09_killer3_03.txt AC 190 ms 138496 KB
09_killer3_04.txt AC 199 ms 138656 KB


2025-03-15 (Sat)
21:06:25 +00:00