QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#183872 | #5662. Distance Calculator | Beevo# | WA | 1ms | 3676kb | C++20 | 970b | 2023-09-19 22:42:12 | 2023-09-19 22:42:13 |
Judging History
answer
#include <bits/stdc++.h>
#define el '\n'
#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
bool valid(vector<int> &v) {
int l = n, r = 0;
for (int i = 0; i < n; i++) {
if (v[i] != i + 1)
l = min(l, i), r = max(r, i);
}
return l == n || r - l == 1;
}
void testCase() {
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
cin >> v[i];
int cnt = 0;
while (!valid(v)) {
for (int i = 1; i < n; i++) {
if (v[i] < v[i - 1]) {
swap(v[i], v[i - 1]);
break;
}
}
cnt++;
}
cout << cnt + 1 << el;
}
signed main() {
Beevo
int t = 1;
cin >> t;
while (t--)
testCase();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3608kb
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:
2 6 3 8 9
result:
ok 5 lines
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 3676kb
input:
4 5 1 3 5 4 2 5 3 1 2 5 4 3 1 2 3 6 5 3 1 6 2 4
output:
4 3 1 8
result:
wrong answer 3rd lines differ - expected: '0', found: '1'