QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#90042#5490. Smallest Calculated ValueChatGPTWA 2ms3472kbC++231.6kb2023-03-22 02:56:472023-03-22 02:56:51

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 02:56:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3472kb
  • [2023-03-22 02:56:47]
  • 提交

answer

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

int main() {
    // read in the three integers
    int a, b, c;
    cin >> a >> b >> c;

    // generate all possible orderings of the operators
    vector<char> operators {'+', '-', '*', '/'};
    vector<vector<char>> orders;
    for (char op1 : operators) {
        for (char op2 : operators) {
            for (char op3 : operators) {
                orders.push_back({op1, op2, op3});
            }
        }
    }

    // iterate through all possible orderings of the operators
    int min_result = 1000;
    for (auto order : orders) {
        // apply the operators to the three integers
        int result = a;
        for (int i = 0; i < 3; i++) {
            char op = order[i];
            int operand = (i == 1) ? b : c;
            if (op == '+') {
                result += operand;
            } else if (op == '-') {
                result -= operand;
            } else if (op == '*') {
                result *= operand;
            } else if (op == '/') {
                if (result % operand == 0) {
                    result /= operand;
                } else {
                    // skip this order if integer division is not possible
                    break;
                }
            }
        }

        // update the minimum non-negative result
        if (result >= 0 && result < min_result) {
            min_result = result;
        }
    }

    // output the minimum non-negative result
    cout << min_result << endl;

    return 0;
}

詳細信息

Test #1:

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

input:

2 3 5

output:

0

result:

ok single line: '0'

Test #2:

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

input:

9 9 9

output:

0

result:

ok single line: '0'

Test #3:

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

input:

5 7 3

output:

1

result:

ok single line: '1'

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3320kb

input:

406 21 18

output:

330

result:

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