QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#753158 | #5119. Perfect Word | HaijieTan | WA | 1ms | 3820kb | C++23 | 2.2kb | 2024-11-16 11:35:07 | 2024-11-16 11:35:07 |
Judging History
answer
#include<iostream>
#include<vector>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<string>
#include<queue>
#include<numeric>//iota -- iota(all(a), x) a从头到尾从x开始递增
#include<cstring>
#include<ctime>
#include<array>
#include<list>
#include<random>
#include<tuple>
#include<deque>
#include<map>
#include<stack>
#include<set>
using namespace std;
#define IOS ios::sync_with_stdio(false);cin.tie(0), cout.tie(0)
#define int long long
#define all(x) x.begin(), x.end()
#define pb push_back
#define pf push_front
#define lowbit(x) (x & (-x))
const int xy[][2] = { 0,1, 0, -1, 1, 0, -1, 0 };
#define mem(a, x) memset(a, x, sizeof a)
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<char, char> PCC;
typedef pair<int, char> PIC;
typedef pair<char, int> PCI;
#define x first
#define y second
#define NO cout << "NO\n"
#define YES cout << "YES\n"
inline int read();
const int INF = 1e9, N = 1e4 + 10, MOD = 998244353, M = 1e4 + 10, K = 1331;
const double PI = acos(-1.0);
void solve() {
int n; cin >> n;
vector<string>a(n + 2);
for (int i = 1; i <= n; i++)cin >> a[i];
sort(a.begin() + 1, a.begin() + 1 + n, [&](string a, string b) {return a.size() < b.size(); });
int ret = 0;
set<int>s;
for (int i = 1; i <= n; i++) {
bool flag = 0;
int len = a[i].size(), h(0), h1(0), h2(0);
if (len == 1)flag = 1;
else {
for (int j = 0; j < len - 1; j++)h1 = h1 * K + a[i][j] % MOD;
for (int j = 1; j < len; j++)h2 = h2 * K + a[i][j] % MOD;
flag = s.count(h1) && s.count(h2);
}
h = K * h + a[i][len - 1] % MOD;
if (flag)ret = max(ret, len), s.insert(h);
}
cout << ret << endl;
}
signed main() {
IOS;
int _ = 1;
//cin >> _;
while (_--)solve();
return 0;
}
inline int read()
{
int x = 0, f = 1; char ch = getchar();
while (ch < '0' || ch>'9') { if (ch == '-') f = -1; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = x * 10 + ch - 48; ch = getchar(); }
return x * f;
}
/* /\_/\
* (= ._.)
* / > \>
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3820kb
input:
4 a t b ab
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3572kb
input:
310 a aa aaa aaaa aaaaa aaaaaa aaaaaaa aaaaaaaa aaaaaaaaa aaaaaaaaaa aaaaaaaaaaa aaaaaaaaaaaa aaaaaaaaaaaaa aaaaaaaaaaaaaa aaaaaaaaaaaaaaa aaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaa...
output:
2
result:
wrong answer 1st numbers differ - expected: '300', found: '2'