QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108448#3168. Letter Wheelsandrew018gu#WA 2ms3484kbC++143.9kb2023-05-25 02:38:342023-05-25 02:39:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-25 02:39:42]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3484kb
  • [2023-05-25 02:38:34]
  • 提交

answer

#include <string>
#include <iostream>

using namespace std;

string a1;
string a2;
string a3;
int p1, p2, p3;

int main(){
    cin >> a1 >> a2 >> a3;
    int len = a1.size();
    p1 = len;
    p2 = len;
    p3 = len;
    for(int i = 1; i < len; i++){
        if(len % i == 0){
            bool bad = false;
            for(int j = 0; j < len; j++){
                if(a1[j] != a1[(j + i) % len]){
                    bad = true;
                    break;
                }
            }
            if(!bad){
                p1 = i;
                break;
            }
        }
    }
    for(int i = 1; i < len; i++){
        if(len % i == 0){
            bool bad = false;
            for(int j = 0; j < len; j++){
                if(a2[j] != a2[(j + i) % len]){
                    bad = true;
                    break;
                }
            }
            if(!bad){
                p2 = i;
                break;
            }
        }
    }
    for(int i = 1; i < len; i++){
        if(len % i == 0){
            bool bad = false;
            for(int j = 0; j < len; j++){
                if(a3[j] != a3[(j + i) % len]){
                    bad = true;
                    break;
                }
            }
            if(!bad){
                p3 = i;
                break;
            }
        }
    }
    if(p1 != p2 || p2 != p3 || p3 != p1){
        cout << -1 << endl;
        return 0;
    }
    int pos2b = -1;
    int pos2c = -1;
    int pos3b = -1;
    int pos3c = -1;
    for(int i = 0; i < p1; i++){
        bool good = true;
        for(int j = 0; j < p1; j++){
            if((3 + a1[j] - a2[(i + j) % len]) % 3 != 2){
                good = false;
                break;
            }
        }
        if(good){
            pos2b = i;
            break;
        }
    }
    for(int i = 0; i < p1; i++){
        bool good = true;
        for(int j = 0; j < p1; j++){
            if((3 + a1[j] - a2[(i + j) % len]) % 3 != 1){
                good = false;
                break;
            }
        }
        if(good){
            pos2c = i;
            break;
        }
    }
    for(int i = 0; i < p1; i++){
        bool good = true;
        for(int j = 0; j < p1; j++){
            if((3 + a1[j] - a3[(i + j) % len]) % 3 != 2){
                good = false;
                break;
            }
        }
        if(good){
            pos3b = i;
            break;
        }
    }
    for(int i = 0; i < p1; i++){
        bool good = true;
        for(int j = 0; j < p1; j++){
            if((3 + a1[j] - a3[(i + j) % len]) % 3 != 1){
                good = false;
                break;
            }
        }
        if(good){
            pos3c = i;
            break;
        }
    }
    if((pos3c == -1 && pos3b == -1) || (pos2c == -1 && pos2b == -1)){
        cout << -1 << endl;
        return 0;
    }
    int ans1 = 1000000;
    if(pos3c >= 0 && pos2b >= 0){
        for(int i = 0; i < p1; i++){
            int dist1 = min(i, p1 - i);
            int dist2 = min(abs(i - pos2b), min(abs(i + p1 - pos2b), abs(i - p1 - pos2b)));
            int dist3 = min(abs(i - pos3c), min(abs(i + p1 - pos3c), abs(i - p1 - pos3c)));
            if(ans1 > dist1 + dist2 + dist3){
                ans1 = dist1 + dist2 + dist3;
            }
        }
    }
    int ans2 = 1000000;
    if(pos2c >= 0 && pos3b >= 0){
        for(int i = 0; i < p1; i++){
            int dist1 = min(i, p1 - i);
            int dist2 = min(abs(i - pos2c), min(abs(i + p1 - pos2c), abs(i - p1 - pos2c)));
            int dist3 = min(abs(i - pos3b), min(abs(i + p1 - pos3b), abs(i - p1 - pos3b)));
            if(ans2 > dist1 + dist2 + dist3){
                ans2 = dist1 + dist2 + dist3;
            }
        }
    }
    if(min(ans1, ans2) < 1000000){
        cout << min(ans1, ans2) << endl;
        return 0;
    }
    cout << -1 << endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3484kb

input:

ABC
ABC
ABC

output:

2

result:

ok single line: '2'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3336kb

input:

ABBBAAAA
BBBCCCBB
CCCCAAAC

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 2ms
memory: 3420kb

input:

AABB
BBCC
ACAC

output:

-1

result:

ok single line: '-1'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3388kb

input:

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA...

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 1ms
memory: 3452kb

input:

ABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABABAB...

output:

-1

result:

ok single line: '-1'

Test #6:

score: -100
Wrong Answer
time: 2ms
memory: 3392kb

input:

ABBBCCACACBCBACCBBCCBACBBBABAABBCAACCABBBACABAACABBCAAACACABACAACACCBCABBABBCBBCCABBCCABCCACBCCCBABABAACAAACCCCBACCABBAACCAABCABBABAAABACBAABABCABAAACABAAACABBCBCACABACBBBBBBCCABBACAAAACBAAACABCABABBBABBAABACABABCCBCCBAAAABBCACACABBCABCAAAABABAAACBCCAAABCABBBAACBABBBACBBBCBCAABCCCCBBACCBABABBAAACAAB...

output:

-1

result:

wrong answer 1st lines differ - expected: '911', found: '-1'