QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#106593 | #3168. Letter Wheels | skittles1412# | WA | 845ms | 3520kb | C++17 | 2.4kb | 2023-05-18 09:23:45 | 2023-05-18 09:23:46 |
Judging History
answer
#include "bits/extc++.h"
using namespace std;
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t;
((cerr << " | " << u), ...);
cerr << endl;
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]: "; \
dbgh(__VA_ARGS__)
#else
#define dbg(...)
#define cerr \
if (false) \
cerr
#endif
using u64 = uint64_t;
#define endl "\n"
#define long int64_t
#define sz(x) int(std::size(x))
struct chash {
u64 operator()(u64 x) const {
x ^= x << 17;
x ^= x >> 33;
x ^= x << 11;
x ^= x >> 23;
return x;
}
};
// template <int MOD>
// int shash(const string& s, int base) {
// long ans = 0;
// for (auto& a : s) {
// ans = (ans * base + a - 'A' + 1) % MOD;
// }
// return int(ans);
// }
// u64 shash(const string& s) {
// constexpr int m1 = 1e9 + 7, m2 = 1e9 + 9;
// return (u64(shash<m1>(s, 5)) << 32) | shash<m2>(s, 5);
// }
u64 shash(const string& s) {
u64 ans = 0;
for (auto& a : s) {
ans = (ans * 1412 + a + 330);
}
return ans;
}
int solve(string a, string b, string c) {
int n = sz(a);
__gnu_pbds::gp_hash_table<u64, int, chash> mp;
for (int i = 0; i < n; i++) {
auto it = mp.insert({shash(c), i}).first;
it->second = min(it->second, i);
rotate(c.begin(), c.begin() + 1, c.end());
}
int ans = 1e9;
for (int i = 0; i < n; i++) {
string nc;
for (int j = 0; j < n; j++) {
nc += 'A' ^ 'B' ^ 'C' ^ a[j] ^ b[j];
}
auto it = mp.find(shash(nc));
if (it != mp.end()) {
ans = min(ans, i + it->second);
}
rotate(b.begin(), b.begin() + n - 1, b.end());
}
return ans;
}
void solve() {
string arr[3];
for (auto& a : arr) {
cin >> a;
}
int ans = 1e9, perm[3] {0, 1, 2};
do {
ans = min(ans, solve(arr[perm[0]], arr[perm[1]], arr[perm[2]]));
} while (next_permutation(begin(perm), end(perm)));
if (ans == 1e9) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
}
int main() {
cin.tie(nullptr);
cin.exceptions(ios::failbit);
ios_base::sync_with_stdio(false);
solve();
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3448kb
input:
ABC ABC ABC
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 2ms
memory: 3452kb
input:
ABBBAAAA BBBCCCBB CCCCAAAC
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3432kb
input:
AABB BBCC ACAC
output:
-1
result:
ok single line: '-1'
Test #4:
score: 0
Accepted
time: 845ms
memory: 3448kb
input:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...
output:
0
result:
ok single line: '0'
Test #5:
score: -100
Wrong Answer
time: 842ms
memory: 3520kb
input:
ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...
output:
0
result:
wrong answer 1st lines differ - expected: '-1', found: '0'