QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#90135#5742. Garbage DisposalChatGPTCompile Error//C++1.2kb2023-03-22 13:40:162023-03-22 13:40:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-22 13:40:19]
  • 评测
  • [2023-03-22 13:40:16]
  • 提交

answer

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int t;
    cin >> t;

    while (t--) {
        int L, R;
        cin >> L >> R;

        // initialize the used array to all zeros
        vector<int> used(R-L+1);

        // iterate through all garbage types between L and R
        bool valid = true;
        for (int x = L; x <= R; x++) {
            // find all valid bins for this garbage type
            vector<int> valid_bins;
            for (int y = L; y <= R; y++) {
                if (__gcd(x, y) == 1 && !used[y-L]) {
                    valid_bins.push_back(y);
                }
            }

            // if there are no valid bins, distribution is not possible
            if (valid_bins.empty()) {
                valid = false;
                break;
            }

            // mark the first valid bin as used and output it
            int y = valid_bins[0];
            used[y-L] = 1;
            cout << y << " ";
        }

        // output -1 if distribution is not possible
        if (!valid) {
            cout << "-1";
        }

        cout << endl;
    }

    return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:22:21: error: ‘__gcd’ was not declared in this scope; did you mean ‘__gid_t’?
   22 |                 if (__gcd(x, y) == 1 && !used[y-L]) {
      |                     ^~~~~
      |                     __gid_t