mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:08:47 +00:00
#1728. 【2022.11.02 联考】字符串还原(friends)
https://sjzezoj.com/submission/63180
This commit is contained in:
parent
07e69976a1
commit
45b3499a20
83
S2OJ/1728/1728.cpp
Normal file
83
S2OJ/1728/1728.cpp
Normal file
@ -0,0 +1,83 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <unordered_set>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2e6 + 5;
|
||||
|
||||
class Hash {
|
||||
private:
|
||||
unsigned long long hash[N], p[N];
|
||||
|
||||
public:
|
||||
Hash(std::string s = "", int base = 131) {
|
||||
p[0] = 1;
|
||||
|
||||
for (int i = 1; i <= s.size(); i++) {
|
||||
hash[i] = hash[i - 1] * base + s[i - 1];
|
||||
p[i] = p[i - 1] * base;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned long long get(int l, int r) {
|
||||
return hash[r] - hash[l - 1] * p[r - l + 1];
|
||||
}
|
||||
|
||||
const unsigned long long &operator[](int i) const {
|
||||
return p[i];
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
std::string u;
|
||||
|
||||
cin >> n >> u;
|
||||
|
||||
if (n % 2 == 0) {
|
||||
cout << "NOT POSSIBLE" << endl;
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
Hash hash(u, 131);
|
||||
int mid = n >> 1;
|
||||
unsigned long long lst = 0;
|
||||
std::string ans;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
if (i - 1 <= mid) {
|
||||
if (hash.get(1, i - 1) * hash[mid - i + 1] + hash.get(i + 1, mid + 1) == hash.get(mid + 2, n)) {
|
||||
if (lst && lst != hash.get(mid + 2, n)) {
|
||||
cout << "NOT UNIQUE" << endl;
|
||||
|
||||
exit(0);
|
||||
} else if (!lst) {
|
||||
ans = u.substr(mid + 1, mid);
|
||||
lst = hash.get(mid + 2, n);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hash.get(1, mid) == hash.get(mid + 1, i - 1) * hash[n - i] + hash.get(i + 1, n)) {
|
||||
if (lst && lst != hash.get(1, mid)) {
|
||||
cout << "NOT UNIQUE" << endl;
|
||||
|
||||
exit(0);
|
||||
} else if (!lst) {
|
||||
ans = u.substr(0, mid);
|
||||
lst = hash.get(1, mid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << (ans.empty() ? "NOT POSSIBLE" : ans) << endl;
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/1728/data/friends1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends11.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends11.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends12.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends12.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends13.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends13.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends14.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends14.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends15.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends15.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends16.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends16.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends17.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends17.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends18.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends18.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends19.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends19.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends20.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends20.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/friends9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/friends9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1728/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1728/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user