/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Wrong Answer 6ms 580.0 KiB
#3 Wrong Answer 6ms 576.0 KiB
#4 Wrong Answer 5ms 576.0 KiB
#5 Wrong Answer 5ms 580.0 KiB
#6 Accepted 4ms 532.0 KiB
#7 Accepted 4ms 584.0 KiB
#8 Accepted 4ms 580.0 KiB
#9 Wrong Answer 6ms 392.0 KiB
#10 Wrong Answer 6ms 580.0 KiB

Code

#include <bits/stdc++.h>
using namespace std;

int gcd(int x, int y) {
    while (y != 0) {
        int t = y;
        y = x % y;
        x = t;
    }
    return x;
}

void solution() {
    int A, B, C;
    cin >> A >> B >> C;
    int arr[3] = {A, B, C};
    sort(arr, arr + 3);  // Sort the array to easily find the minimum, middle, and maximum values

    if (arr[0] == arr[1] && arr[1] == arr[2]) {
        cout << 0 << "\n";
        return;
    } 

    if (arr[0] == arr[1] || arr[1] == arr[2]) {
        cout << 1 << "\n";
        return;
    }

    // Compute the GCD of the differences
    int diff1 = arr[2] - arr[0];
    int diff2 = arr[2] - arr[1];
    int diff3 = arr[1] - arr[0];
    
    int common_gcd = gcd(gcd(diff1, diff2), diff3);

    if (common_gcd == 1) {
        // If GCD is 1, at least two operations are needed
        cout << 2 << "\n";
    } else {
        // Otherwise, it can be done in 1 operation
        cout << 1 << "\n";
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while (T--) {
        solution();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1061 Bring equality
Contest
Brain Booster #4
Language
C++20 (G++ 13.2.0)
Submit At
2024-07-14 18:52:26
Judged At
2024-10-03 13:34:58
Judged By
Score
40
Total Time
6ms
Peak Memory
584.0 KiB