QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#387966#3168. Letter Wheelsohiostatescarlet#TL 0ms3656kbC++171.3kb2024-04-13 08:08:022024-04-13 08:08:03

Judging History

你现在查看的是最新测评结果

  • [2024-04-13 08:08:03]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3656kb
  • [2024-04-13 08:08:02]
  • 提交

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...

output:


result: