QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#387966 | #3168. Letter Wheels | ohiostatescarlet# | TL | 0ms | 3656kb | C++17 | 1.3kb | 2024-04-13 08:08:02 | 2024-04-13 08:08:03 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define L long long
#ifdef LOCAL
#define dbg(x) cerr << '[' << #x << " = " << (x) << "]\n";
#else
#define dbg(x)
#endif
// g++ -std=c++17 -O2 -DLOCAL -o a a.cpp
int main() {
cin.tie(0)->sync_with_stdio(0);
vector<string> s(3);
for (auto &i : s) cin >> i;
int n = s[0].size();
int ans = 1e9;
for (int zz = 0; zz < 3; zz++) {
unordered_map<string, int> cyc;
for (int i = 0; i < n; i++) {
string c = s[2].substr(i) + s[2].substr(0, i);
int d = min(i, n - i);
cyc[c] = d;
}
for (int i = 0; i < n; i++) {
string newb = s[1].substr(i) + s[1].substr(0, i);
string c = string(n, 0);
for (int j = 0; j < n; j++) {
set<char> t = {'A', 'B', 'C'};
if (t.count(s[0][j])) t.erase(s[0][j]);
if (t.count(newb[j])) t.erase(newb[j]);
if (t.size() == 1) {
c[j] = *t.begin();
}
}
if (cyc.count(c)) {
int d = cyc[c];
ans = min(ans, min(i, n - i) + d);
}
}
swap(s[0], s[2]);
swap(s[1], s[2]);
}
if (ans > 1e8) cout << "-1\n";
else cout << ans << '\n';
}
// AAB
// BCC
// CCA
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3536kb
input:
ABC ABC ABC
output:
2
result:
ok single line: '2'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
ABBBAAAA BBBCCCBB CCCCAAAC
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
AABB BBCC ACAC
output:
-1
result:
ok single line: '-1'
Test #4:
score: -100
Time Limit Exceeded
input:
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...