QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#90141#5662. Distance CalculatorChatGPTWA 2ms3436kbC++779b2023-03-22 13:42:552023-03-22 13:42:56

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:42:56]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3436kb
  • [2023-03-22 13:42:55]
  • 提交

answer

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

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

    while (m--) {
        int n;
        cin >> n;

        // read the encoding of the given city
        vector<int> city(n);
        for (int i = 0; i < n; i++) {
            cin >> city[i];
        }

        // calculate the distance to the castle
        int dist = 0;
        for (int i = 0; i < n-1; i++) {
            if (city[i] != i+1) {
                int j = find(city.begin()+i, city.end(), i+1) - city.begin();
                reverse(city.begin()+i, city.begin()+j+1);
                dist += j-i+1;
            }
        }

        // output the result
        cout << dist << endl;
    }

    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 3436kb

input:

5
3
3 1 2
4
4 3 2 1
5
4 1 2 3 5
7
2 6 1 5 4 3 7
10
3 2 1 5 7 6 4 10 8 9

output:

4
4
6
9
16

result:

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