QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#90141 | #5662. Distance Calculator | ChatGPT | WA | 2ms | 3436kb | C++ | 779b | 2023-03-22 13:42:55 | 2023-03-22 13:42:56 |
Judging History
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;
}
Details
Tip: Click on the bar to expand more detailed information
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'