QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#508926 | #4925. Adjacent Pairs | Wansur | 0 | 1ms | 5752kb | C++23 | 1.7kb | 2024-08-07 22:01:21 | 2024-08-07 22:01:21 |
answer
#include <bits/stdc++.h>
#define ent '\n'
#define f first
#define s second
#define int long long
#define sz(x) (int)(x).size()
#define rep(i, a, b) for(int i = a; i < (b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int maxn = 2e5 + 12;
const int mod = 1e9 + 7;
int a[maxn];
int b[maxn];
int n, m, k;
int solve(int a[], int x, int y){
int ans = 0;
for(int i=1;i<=n;i++){
if(a[i] == x){
swap(x, y);
continue;
}
ans++;
if(a[i] == y){
int j = i;
while(j < n && a[j+1] == x + y - a[j]){
j++;
}
ans += (j - i + 1) / 2;
for(int l=i;l<=j;l++){
a[l] = x + y - a[l];
swap(x, y);
}
continue;
}
if(a[i+1] == x){
int j = i+1;
while(j < n && a[j+1] == x + y - a[j]){
j++;
}
ans += (j - i) / 2;
for(int l=i+1;l<=j;l++){
a[l] = x + y - a[l];
}
}
a[i] = x;
swap(x, y);
}
return ans;
}
void solve(){
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i];
}
int ans = 2 * n;
for(int x=1;x<=n+2;x++){
for(int y=1;y<=n+2;y++){
if(x == y) continue;
for(int i=1;i<=n;i++){
b[i] = a[i];
}
ans = min(ans, solve(b, x, y));
}
}
cout << ans << ent;
}
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5752kb
input:
2 5 4 5 2 4 5 2 1 2
output:
2 0
result:
wrong answer 1st lines differ - expected: '3', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%